diff --git a/script/install.sh b/script/install.sh new file mode 100755 index 0000000..286b562 --- /dev/null +++ b/script/install.sh @@ -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"