From c82cf0fa106ef9ea589962f59c784cda7a7a17f8 Mon Sep 17 00:00:00 2001 From: Code WvS Date: Wed, 4 Mar 2015 17:25:47 +0100 Subject: add mobile version --- binary.sh | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ config.xml | 16 +++++++++++ desktop.sh | 33 ++++++++++++++++++++++ mobile.sh | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 8 ++++++ 5 files changed, 229 insertions(+) create mode 100755 binary.sh create mode 100644 config.xml create mode 100755 desktop.sh create mode 100755 mobile.sh create mode 100644 package.json diff --git a/binary.sh b/binary.sh new file mode 100755 index 0000000..1d23507 --- /dev/null +++ b/binary.sh @@ -0,0 +1,83 @@ +#!/bin/bash + +if [[ "$snapsource" == "" ]] +then + export snapsource="https://github.com/Gubolin/snap.git" +fi + +if [[ $# < 2 ]] +then + echo "Usage: binary.sh OPTION PLATFORM [FILE/URL]" + 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 win32 win64 osx linux32 linux64" + echo "" + echo "If FILE/URL is given, it will be #open-ed inside Snap! immediately. URL will be loaded at runtime." + echo "" + echo "" + echo "The following environment variables will be used, if available:" + echo " snapsource Path or URL to the Snap! git repository. This repository must contain the branch" + echo " mobileapp with the configuration files! Default: https://github.com/Gubolin/snap.git" + echo " crosswalk Path to a crosswalk-cordova directory. Download \"Cordova Android\" here:" + echo " https://crosswalk-project.org/documentation/downloads.html" + echo " If omitted, standard cordova will be used." + exit 0 +fi + +scriptdir=$(readlink -e ".") + +# Requirements: +# git +# UglifyJS2 (https://github.com/mishoo/UglifyJS2) + +ide=true +platform=$2 + +# presentation mode +if [[ "$3" != "" ]] +then + ide=false +fi + +buildsource=$(mktemp -d) +git clone $snapsource $buildsource +cd "$buildsource" + +if [ $ide == false ] +then + # if a file was given, move it to "project.xml" + # it will be loaded like an URL then + if [ -f "$3" ] + then + cp "$3" "project.xml" + url="project.xml" + else + url=$3 + fi + + # load custom project from url + sed -i "/ide\.openIn/a\ + ide.droppedText(ide.getURL('$url'));" snap.html + # ... in presentation mode + sed -i "s/this.isAppMode = false/this.isAppMode = true/g" gui.js +fi + +# compress all js files +find . -name '*.js' | xargs -I {} uglifyjs {} -o {} -c 2> /dev/null + +# return to the directory where the script was called from +cd "$scriptdir" + +# run helper scripts for building + +if [[ $1 == "-m" ]] +then + ./mobile.sh "$2" "$buildsource" +else + ./desktop.sh "$2" "$buildsource" +fi diff --git a/config.xml b/config.xml new file mode 100644 index 0000000..e043129 --- /dev/null +++ b/config.xml @@ -0,0 +1,16 @@ + + + Snap! + + Snap! Build Your Own Blocks + A visual, blocks based programming language inspired by Scratch + + + Jens Mönig and Brian Harvey + + + + + + + diff --git a/desktop.sh b/desktop.sh new file mode 100755 index 0000000..f2ecb09 --- /dev/null +++ b/desktop.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +if [[ "$snapsource" == "" ]] +then + export snapsource="https://github.com/Gubolin/snap.git" +fi + +if [[ $1 = "" ]] +then + echo "Usage: desktop.sh PLATFORM [BUILDSOURCE]" + 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) + +builddir=$(mktemp -d) + +if [[ $2 == "" ]] +then + git clone "$snapsource" $builddir + cd $builddir/ +else + mv "$2" $builddir + cd $builddir/ +fi + +nwbuild -p "$1" . + +mv build/* $scriptdir/ diff --git a/mobile.sh b/mobile.sh new file mode 100755 index 0000000..bd003a1 --- /dev/null +++ b/mobile.sh @@ -0,0 +1,89 @@ +#!/bin/bash + +if [[ "$snapsource" == "" ]] +then + export snapsource="https://github.com/Gubolin/snap.git" +fi + +if [[ $1 = "" ]] +then + echo "Usage: mobile.sh PLATFORM [BUILDSOURCE]" + exit 0 +fi + +scriptdir=$(readlink -e ".") + +# Requirements: +# git, nodejs, android SDK / other platform(s) +# cordova (https://cordova.apache.org/) +# optional: crosswalk-cordova (https://github.com/crosswalk-project/crosswalk-cordova-android) + +if [[ $2 != "" ]] +then + buildsource=$(readlink -e "$2") +fi + +builddir=$(mktemp -d) + +cordova create $builddir edu.berkeley.snap "Snap\!" +cd $builddir +rm -rf www config.xml + +if [[ $2 == "" ]] +then + git clone "$snapsource" www + cd www/ +else + mv "$buildsource" www + cd www +fi + +# add mobile-specific library; it's made available at runtime +sed -i '/link rel="shortcut icon"/a\ + ' snap.html + +echo "Adding cordova plugins" +# add everything needed and build for $device +cordova platform add "$1" > /dev/null +cordova plugin add org.apache.cordova.plugin.softkeyboard \ + org.apache.cordova.vibration \ + org.apache.cordova.device-motion \ + org.apache.cordova.device-orientation \ + org.apache.cordova.geolocation \ + de.appplant.cordova.plugin.local-notification 2> /dev/null + +if [[ $1 == "android" ]] +then + # Remove default icons + cd "$builddir/platforms/android" + find -name '*.png' | xargs rm + + if [[ $crosswalk != "" ]] + then + # adapted from https://crosswalk-project.org/documentation/cordova/migrate_an_application.html#migrate + echo "Preparing crosswalk" + rm -Rf "$builddir/platforms/android/CordovaLib/*" + cp -a $crosswalk/framework/* "$builddir/platforms/android/CordovaLib/" + cp -a "$crosswalk/VERSION" "$builddir/platforms/android/" + export ANDROID_HOME=$(dirname $(dirname $(which android))) + cd "$builddir/platforms/android/CordovaLib/" + android update project --subprojects --target android-21 --path . > /dev/null + ant debug > /dev/null + cd "$builddir" + # prepend permissions to end of manifest + sed -i "s,,\ + \ + \ + \ + ,g" \ + "$builddir/platforms/android/AndroidManifest.xml" + fi +fi + +echo "Building application" +cordova build "$1" > /dev/null + +cd $builddir +# TODO other platforms +find -name '*.apk' | xargs -I {} mv {} $scriptdir +echo "Finished." diff --git a/package.json b/package.json new file mode 100644 index 0000000..678a69c --- /dev/null +++ b/package.json @@ -0,0 +1,8 @@ +{ + "name": "Snap!", + "version": "4.0", + "main": "snap.html", + "window": { + "toolbar": false + } +} -- cgit v1.3.1