Skip to content

Commit

Permalink
Add installer script
Browse files Browse the repository at this point in the history
It works via `script/install.sh PLUGIN_TYPE` command.
Supported plugin types are  `Debug`, `Beta` and `Test`.
Type argument can be omitted to replace original plugin.
  • Loading branch information
kardeslik committed Jul 12, 2019
1 parent 6e8b597 commit fad75af
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions script/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash
set -e

main ()
{
SKETCH_APP_PATH="/Applications/Sketch.app"
SKETCH_PLUGIN_DIR="$HOME/Library/Application Support/com.bohemiancoding.sketch3/Plugins"
SCRIPT_DIR=$(cd "$(dirname "$0")"; pwd)
PLUGIN_PATH="$SCRIPT_DIR/../Zeplin.sketchplugin"

TYPES=('Debug' 'Beta' 'Test')

if [[ " ${TYPES[*]} " == *"$1"* ]]; then
if [ -z "$1" ]; then
IDENTIFIER_SUFFIX=""
NAME_SUFFIX=""
else
IDENTIFIER_SUFFIX=".$(echo "$1" | tr '[:upper:]' '[:lower:]')"
NAME_SUFFIX=" $(tr '[:lower:]' '[:upper:]' <<< ${1:0:1})$(tr '[:upper:]' '[:lower:]' <<< ${1:1})"
fi
else
echo "Argument must be one of the followings: ${TYPES[@]}"

exit 0
fi

TEMP_PLUGIN_PATH="$TMPDIR/Zeplin$NAME_SUFFIX.sketchplugin"
SKETCH_PLUGIN_PATH="$SKETCH_PLUGIN_DIR/Zeplin$NAME_SUFFIX.sketchplugin"

rm -rf "$TEMP_PLUGIN_PATH"
cp -r "$PLUGIN_PATH" "$TEMP_PLUGIN_PATH"

sed -i '' -e '/"name": "/s/Zeplin/Zeplin'"$NAME_SUFFIX"'/' "$TEMP_PLUGIN_PATH/Contents/Sketch/manifest.json"
sed -i '' -e '/"identifier": "/s/io.zeplin.sketch-plugin/io.zeplin.sketch-plugin'"$IDENTIFIER_SUFFIX"'/' "$TEMP_PLUGIN_PATH/Contents/Sketch/manifest.json"
sed -i '' -e 's/io.zeplin.osx/io.zeplin.osx'"$IDENTIFIER_SUFFIX"'/' "$TEMP_PLUGIN_PATH/Contents/Sketch/helpers.cocoascript"

if [ -d "$SKETCH_PLUGIN_PATH" ]; then
rm -rf "$SKETCH_PLUGIN_PATH"
cp -r "$TEMP_PLUGIN_PATH" "$SKETCH_PLUGIN_PATH"

open "$SKETCH_APP_PATH"
else
open "$TEMP_PLUGIN_PATH"
fi

exit 0
}

main "$1"

0 comments on commit fad75af

Please sign in to comment.