From 8c4dbc73a29ad4f2b22ee9bc1129b19d9742a5f7 Mon Sep 17 00:00:00 2001 From: Gubolin Date: Mon, 8 Sep 2014 11:34:23 +0200 Subject: rewrite scripts --- binary.sh | 34 ++++++++++++++++++++++++++-------- desktop.sh | 17 ++++++++++++----- mobile.sh | 24 +++++++++++++++++------- 3 files changed, 55 insertions(+), 20 deletions(-) diff --git a/binary.sh b/binary.sh index b7c02ef..489e6ed 100755 --- a/binary.sh +++ b/binary.sh @@ -16,6 +16,8 @@ then exit 0 fi +scriptdir=$(readlink -e ".") + # Requirements: # git # UglifyJS2 (https://github.com/mishoo/UglifyJS2) @@ -23,6 +25,7 @@ fi ide=true platform=$2 +# presentation mode if [[ "$3" != "" ]] then ide=false @@ -32,40 +35,55 @@ if [ $ide == false ] then if [ -f "$3" ] then - content=$(cat "$3") + content=$(cat $3) else ide=true fi fi -git clone "https://github.com/Gubolin/snap.git" -cd "snap" +buildsource=$(mktemp -d) +git clone "https://github.com/Gubolin/snap.git" $buildsource +cd "$buildsource" git checkout mobileapp rm -rf .git/ if [ $ide == false ] then + # minimize everything 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 + # load custom project from file + sed -i '/sha512\.js"/a\ + ' 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