Last active
September 10, 2021 10:51
-
-
Save chadlavi/ce628bc046c9aec8f23ea0bc8504bef4 to your computer and use it in GitHub Desktop.
shell script to work as middleware between Sketch and and git repo. syntax: 'upload.sh [filename] "optional commit message"'
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# some parts of this forked from https://github.com/blended/sketch-collaboration | |
# cf. https://github.com/chadlavi/sketch-collaboration | |
if [ ! `command -v jq` ]; then | |
echo "you need to install jq. If you use Homebrew, try 'brew install jq'" | |
exit 1 | |
fi | |
if [ -z "$1 ]; then | |
echo "syntax:" | |
echo "upload.sh [filename] \"optional commit message\"" | |
exit 1 | |
fi | |
sketch_file=$1 | |
sketch_file_base="$(basename $sketch_file)" | |
sketch_dir="${sketch_file_base%.*}" | |
return=`pwd` | |
cd "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | |
# Pull the latest changes from the repo | |
git pull | |
# Unzip the file | |
unzip -o "$sketch_file" -d "$sketch_dir" | |
# prettify JSON | |
for file in ./$sketch_dir/*.json; do | |
jq . $file | sed 's:/:\\/:g' > "$file.bak" | |
mv "$file.bak" "$file" | |
done | |
# Remove the preview file | |
rm -Rf ./$sketch_dir/previews/ | |
git add . | |
if [ -z "$2" ]; then | |
git commit -m "Update (`date`)" | |
else | |
git commit -m "$2 (`date`)" | |
fi | |
git push | |
cd "$return" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment