From 468fb94a5fb17218da16033e27e86c1219c2b3ec Mon Sep 17 00:00:00 2001 From: Gubolin Date: Sun, 7 Sep 2014 16:47:36 +0200 Subject: add script for compressing Snap\! --- binary.sh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100755 binary.sh (limited to 'binary.sh') diff --git a/binary.sh b/binary.sh new file mode 100755 index 0000000..fbeeeae --- /dev/null +++ b/binary.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +# Requirements: +# git +# UglifyJS2 (https://github.com/mishoo/UglifyJS2) + +git clone https://github.com/Gubolin/snap.git +cd "snap" +git checkout mobileapp + +rm -rf .git/ +rm lang* ypr.js paint.js cloud.js gui.js + +find . -name '*.js' | xargs -I {} uglifyjs {} -o {} -c + +sed -i '/paint\.js"/d' snap.html +sed -i '/cloud\.js"/d' snap.html +sed -i 's/gui\.js"/binary\.js"/' snap.html + +find . \( \! -name '*.js' \! -name 'snap.html' \! -name 'mobile.sh' \! -name 'desktop.sh' \! -name 'snap_logo_sm.png' \! -name 'config.xml' \! -name 'package.json' -type f \) -print0 | xargs -0 rm +find . -type d -empty -print0 | xargs -0 rm -r -- cgit v1.3.1 From 6f09aff97549fb9d2a3687781edf5d31dd766195 Mon Sep 17 00:00:00 2001 From: Gubolin Date: Sun, 7 Sep 2014 18:22:33 +0200 Subject: rewrite scripts --- binary.sh | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++------ desktop.sh | 21 +++++++++++++++++---- mobile.sh | 33 ++++++++++++++++++++++++++++----- snap.html | 6 ++---- 4 files changed, 103 insertions(+), 19 deletions(-) (limited to 'binary.sh') diff --git a/binary.sh b/binary.sh index fbeeeae..b7c02ef 100755 --- a/binary.sh +++ b/binary.sh @@ -1,21 +1,71 @@ #!/bin/bash +if [[ $# < 2 ]] +then + echo "Usage: binary.sh OPTION PLATFORM [FILE]" + echo "" + echo "OPTIONS:" + echo " -m Mobile" + echo " -d Desktop" + echo "" + echo "PLATFORMS:" + echo " Mobile amazon-fireos android blackberry10 firefoxos ios ubuntu wp8 win8 tizen" + echo " Desktop win osx linux32 linux64" + echo "" + echo "If FILE is given, it will be #open-ed inside Snap\! immediately" + exit 0 +fi + # Requirements: # git # UglifyJS2 (https://github.com/mishoo/UglifyJS2) -git clone https://github.com/Gubolin/snap.git +ide=true +platform=$2 + +if [[ "$3" != "" ]] +then + ide=false +fi + +if [ $ide == false ] +then + if [ -f "$3" ] + then + content=$(cat "$3") + else + ide=true + fi +fi + +git clone "https://github.com/Gubolin/snap.git" cd "snap" git checkout mobileapp rm -rf .git/ -rm lang* ypr.js paint.js cloud.js gui.js -find . -name '*.js' | xargs -I {} uglifyjs {} -o {} -c +if [ $ide == false ] +then + rm lang* ypr.js paint.js cloud.js gui.js -sed -i '/paint\.js"/d' snap.html -sed -i '/cloud\.js"/d' snap.html -sed -i 's/gui\.js"/binary\.js"/' snap.html + sed -i '/paint\.js"/d' snap.html + sed -i '/cloud\.js"/d' snap.html + sed -i 's/gui\.js"/binary\.js"/' snap.html + + sed -i "/ide\.openIn/a\ + ide.droppedText(\'$content\'); " snap.html +fi + +find . -name '*.js' | xargs -I {} uglifyjs {} -o {} -c find . \( \! -name '*.js' \! -name 'snap.html' \! -name 'mobile.sh' \! -name 'desktop.sh' \! -name 'snap_logo_sm.png' \! -name 'config.xml' \! -name 'package.json' -type f \) -print0 | xargs -0 rm find . -type d -empty -print0 | xargs -0 rm -r + +cd .. + +if [[ $1 == "-m" ]] +then + ./mobile.sh "$2" "snap" +else + ./desktop.sh "$2" "snap" +fi diff --git a/desktop.sh b/desktop.sh index 46a7594..a572b4f 100755 --- a/desktop.sh +++ b/desktop.sh @@ -1,12 +1,25 @@ #!/bin/bash +if [[ $1 = "" ]] +then + echo "Usage: desktop.sh PLATFORM [BUILDSOURCE]" + exit 0 +fi + # Requirements: # git, zip, nodejs # node-webkit (https://github.com/rogerwang/node-webkit), node-webkit-builder (https://github.com/mllrsohn/node-webkit-builder) # binaries are in snap/build/Snap! -git clone https://github.com/Gubolin/snap.git -cd "snap" -git checkout mobileapp -nwbuild -p win,osx,linux32,linux64 . +if [[ $2 == "" ]] +then + git clone https://github.com/Gubolin/snap.git www + cd www/ + git checkout mobileapp +else + cp -R "$2" www + cd www/ +fi + +nwbuild -p "$1" . diff --git a/mobile.sh b/mobile.sh index 656b7dc..789925a 100755 --- a/mobile.sh +++ b/mobile.sh @@ -1,21 +1,44 @@ #!/bin/bash +if [[ $1 = "" ]] +then + echo "Usage: mobile.sh PLATFORM [BUILDSOURCE]" + exit 0 +fi + # Requirements: # git, nodejs, android SDK / other platform(s) # cordova (https://cordova.apache.org/) # binaries are in platform/android/ant-build/Snap-debug.apk +if [[ $2 != "" ]] +then + copyfrom=$(readlink -e "$2") +fi + cordova create Snap-Mobile edu.berkeley.snap "Snap\!" cd Snap-Mobile rm -rf www config.xml -git clone https://github.com/Gubolin/snap.git www -cd www -git checkout mobileapp -cordova platform add android + +if [[ $2 == "" ]] +then + git clone https://github.com/Gubolin/snap.git www + cd www/ + git checkout mobileapp +else + cp -R "$copyfrom/" . + mv "$copyfrom" www + cd www +fi + +sed -i '/link rel="shortcut icon"/a\ + ' snap.html + +cordova platform add "$1" cordova plugin add org.apache.cordova.plugin.softkeyboard cordova plugin add org.apache.cordova.vibration cordova plugin add org.apache.cordova.device-motion cordova plugin add org.apache.cordova.device-orientation cordova plugin add org.apache.cordova.geolocation -cordova build android +cordova build "$1" diff --git a/snap.html b/snap.html index 8e8e919..d197b08 100755 --- a/snap.html +++ b/snap.html @@ -19,15 +19,13 @@ - - - ' snap.html + + echo "var code =" > code.js + echo "'$content'" >> code.js + echo ";" >> code.js + sed -i "/ide\.openIn/a\ - ide.droppedText(\'$content\'); " snap.html + ide.droppedText(code); " snap.html fi +# compress all js files find . -name '*.js' | xargs -I {} uglifyjs {} -o {} -c -find . \( \! -name '*.js' \! -name 'snap.html' \! -name 'mobile.sh' \! -name 'desktop.sh' \! -name 'snap_logo_sm.png' \! -name 'config.xml' \! -name 'package.json' -type f \) -print0 | xargs -0 rm +# delete everything that is not html/js/logo/config +find . \( \! -name '*.js' \! -name 'snap.html' \! -name 'snap_logo_sm.png' \! -name 'config.xml' \! -name 'package.json' -type f \) -print0 | xargs -0 rm find . -type d -empty -print0 | xargs -0 rm -r -cd .. +# return to the directory where the script was called from +cd "$scriptdir" + +# run helper scripts for building if [[ $1 == "-m" ]] then - ./mobile.sh "$2" "snap" + ./mobile.sh "$2" "$buildsource" else - ./desktop.sh "$2" "snap" + ./desktop.sh "$2" "$buildsource" fi diff --git a/desktop.sh b/desktop.sh index a572b4f..8b0e21c 100755 --- a/desktop.sh +++ b/desktop.sh @@ -6,20 +6,27 @@ then exit 0 fi +scriptdir=$(readlink -e ".") + # Requirements: # git, zip, nodejs # node-webkit (https://github.com/rogerwang/node-webkit), node-webkit-builder (https://github.com/mllrsohn/node-webkit-builder) -# binaries are in snap/build/Snap! +builddir=$(mktemp -d) if [[ $2 == "" ]] then - git clone https://github.com/Gubolin/snap.git www - cd www/ + git clone https://github.com/Gubolin/snap.git $builddir + cd $builddir/ git checkout mobileapp else - cp -R "$2" www - cd www/ + mv "$2" $builddir + cd $builddir/ fi +# remove mobile config +rm config.xml + nwbuild -p "$1" . + +mv build/* $scriptdir/ diff --git a/mobile.sh b/mobile.sh index 789925a..15b1c9c 100755 --- a/mobile.sh +++ b/mobile.sh @@ -6,19 +6,21 @@ then exit 0 fi +scriptdir=$(readlink -e ".") + # Requirements: # git, nodejs, android SDK / other platform(s) # cordova (https://cordova.apache.org/) -# binaries are in platform/android/ant-build/Snap-debug.apk - if [[ $2 != "" ]] then - copyfrom=$(readlink -e "$2") + buildsource=$(readlink -e "$2") fi -cordova create Snap-Mobile edu.berkeley.snap "Snap\!" -cd Snap-Mobile +builddir=$(mktemp -d) + +cordova create $builddir edu.berkeley.snap "Snap\!" +cd $builddir rm -rf www config.xml if [[ $2 == "" ]] @@ -27,14 +29,18 @@ then cd www/ git checkout mobileapp else - cp -R "$copyfrom/" . - mv "$copyfrom" www + mv "$buildsource" www cd www fi +# remove configs for desktop, it is not needed +rm package.json + +# add mobile-specific library; it's made available at runtime sed -i '/link rel="shortcut icon"/a\ ' snap.html +# add everything needed and build for $device cordova platform add "$1" cordova plugin add org.apache.cordova.plugin.softkeyboard cordova plugin add org.apache.cordova.vibration @@ -42,3 +48,7 @@ cordova plugin add org.apache.cordova.device-motion cordova plugin add org.apache.cordova.device-orientation cordova plugin add org.apache.cordova.geolocation cordova build "$1" + +cd $builddir +# TODO other platforms +find -name '*.apk' | xargs -I {} mv {} $scriptdir -- cgit v1.3.1 From 8433b79d9363dea79e139cbdc3a9811495694753 Mon Sep 17 00:00:00 2001 From: Gubolin Date: Mon, 8 Sep 2014 11:44:59 +0200 Subject: use the Snap-icon instead of the default one --- binary.sh | 2 ++ mobile.sh | 8 ++++++++ 2 files changed, 10 insertions(+) (limited to 'binary.sh') diff --git a/binary.sh b/binary.sh index 489e6ed..6f267d0 100755 --- a/binary.sh +++ b/binary.sh @@ -67,6 +67,8 @@ then sed -i "/ide\.openIn/a\ ide.droppedText(code); " snap.html +else + rm binary.js fi # compress all js files diff --git a/mobile.sh b/mobile.sh index 15b1c9c..81fa6f3 100755 --- a/mobile.sh +++ b/mobile.sh @@ -47,6 +47,14 @@ cordova plugin add org.apache.cordova.vibration cordova plugin add org.apache.cordova.device-motion cordova plugin add org.apache.cordova.device-orientation cordova plugin add org.apache.cordova.geolocation + +if [[ $1 == "android" ]] +then + # Remove default icons + cd "$builddir/platforms/android" + find -name '*.png' | xargs rm +fi + cordova build "$1" cd $builddir -- cgit v1.3.1 From 45033e2101a5d5d0929dd28205f3177059ad865d Mon Sep 17 00:00:00 2001 From: Gubolin Date: Sat, 3 Jan 2015 10:59:47 +0100 Subject: allow setting the Snap! source in a variable --- binary.sh | 7 ++++++- desktop.sh | 7 ++++++- mobile.sh | 7 ++++++- 3 files changed, 18 insertions(+), 3 deletions(-) (limited to 'binary.sh') diff --git a/binary.sh b/binary.sh index 6f267d0..c1a481e 100755 --- a/binary.sh +++ b/binary.sh @@ -1,5 +1,10 @@ #!/bin/bash +if [[ "$snapsource" == "" ]] +then + export snapsource="https://github.com/Gubolin/snap.git" +fi + if [[ $# < 2 ]] then echo "Usage: binary.sh OPTION PLATFORM [FILE]" @@ -42,7 +47,7 @@ then fi buildsource=$(mktemp -d) -git clone "https://github.com/Gubolin/snap.git" $buildsource +git clone $snapsource $buildsource cd "$buildsource" git checkout mobileapp diff --git a/desktop.sh b/desktop.sh index 8b0e21c..53ec24b 100755 --- a/desktop.sh +++ b/desktop.sh @@ -1,5 +1,10 @@ #!/bin/bash +if [[ "$snapsource" == "" ]] +then + export snapsource="https://github.com/Gubolin/snap.git" +fi + if [[ $1 = "" ]] then echo "Usage: desktop.sh PLATFORM [BUILDSOURCE]" @@ -16,7 +21,7 @@ builddir=$(mktemp -d) if [[ $2 == "" ]] then - git clone https://github.com/Gubolin/snap.git $builddir + git clone "$snapsource" $builddir cd $builddir/ git checkout mobileapp else diff --git a/mobile.sh b/mobile.sh index b0bcc5d..59e5da8 100755 --- a/mobile.sh +++ b/mobile.sh @@ -1,5 +1,10 @@ #!/bin/bash +if [[ "$snapsource" == "" ]] +then + export snapsource="https://github.com/Gubolin/snap.git" +fi + if [[ $1 = "" ]] then echo "Usage: mobile.sh PLATFORM [BUILDSOURCE]" @@ -25,7 +30,7 @@ rm -rf www config.xml if [[ $2 == "" ]] then - git clone https://github.com/Gubolin/snap.git www + git clone "$snapsource" www cd www/ git checkout mobileapp else -- cgit v1.3.1 From d7def3bb24465d028dbeb91539f0c98d756da492 Mon Sep 17 00:00:00 2001 From: Gubolin Date: Sat, 10 Jan 2015 11:26:05 +0100 Subject: don't delete files from binary.sh --- binary.sh | 4 ---- 1 file changed, 4 deletions(-) (limited to 'binary.sh') diff --git a/binary.sh b/binary.sh index c1a481e..212e7cb 100755 --- a/binary.sh +++ b/binary.sh @@ -79,10 +79,6 @@ fi # compress all js files find . -name '*.js' | xargs -I {} uglifyjs {} -o {} -c -# delete everything that is not html/js/logo/config -find . \( \! -name '*.js' \! -name 'snap.html' \! -name 'snap_logo_sm.png' \! -name 'config.xml' \! -name 'package.json' -type f \) -print0 | xargs -0 rm -find . -type d -empty -print0 | xargs -0 rm -r - # return to the directory where the script was called from cd "$scriptdir" -- cgit v1.3.1