Created
May 12, 2019 14:45
-
-
Save mathieudutour/8a262a0252a9f2453496e5430faf7714 to your computer and use it in GitHub Desktop.
Sync a folder to Sketch Cloud
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 | |
SEC=`security find-generic-password -s sketch_cloud_authorization_token -g 2>&1` | |
TOKEN=`echo "$SEC" | grep -a "password" | cut -d \" -f 2` | |
if [ "$TOKEN" == "" ]; then | |
read -s -p "Enter Sketch Cloud authorization token: " TOKEN | |
security add-generic-password -s sketch_cloud_authorization_token -a sketch_cloud_authorization_token -w $TOKEN | |
echo "" | |
echo "Token stored in the keychain so you don't have to input it next time" | |
fi | |
for entry in ./*.sketch | |
do | |
data=`unzip -p "$entry" user.json | jq '.document.cloudShare | {id: .id, updatedAt: .updatedAt}'` | |
id=`echo "$data" | jq '.id'` | |
if [ "$id" != "null" ]; then | |
id=`echo "$data" | jq '.id'` | |
updatedAt=`echo "$data" | jq '.updatedAt' | cut -c2-20` | |
json=$(curl 'https://graphql.sketch.cloud/api' \ | |
--silent \ | |
-H "authorization: token $TOKEN" \ | |
-H 'Content-Type: application/json' \ | |
-H 'Accept: application/json' \ | |
--data-binary "{\"query\":\"query(\$documentId: UUID!) { share(id: \$documentId) { updatedAt version { document { url } } } }\",\"variables\":{\"documentId\":$id}}" | |
) | |
remoteUpdatedAt=$(echo "$json" | jq --raw-output '.data.share.updatedAt' | cut -c1-19) | |
if [ "$remoteUpdatedAt" != "null" ]; then | |
if [ "$updatedAt" != "$remoteUpdatedAt" ]; then | |
url=$(echo "$json" | jq --raw-output '.data.share.version.document.url') | |
echo "Updating $entry..." | |
curl --silent -L "$url" -o "$entry" | |
else | |
echo "Skipping $entry because the local version is based on the latest from Cloud" | |
fi | |
else | |
echo "Skipping $entry because we couldn't join Cloud" | |
fi | |
else | |
echo "Skipping $entry because it's not published on Cloud" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment