From b0640ead441b1522e7e07cbdc87061c0462f00e0 Mon Sep 17 00:00:00 2001 From: Ethan Neff Date: Fri, 10 Feb 2017 14:51:31 -0800 Subject: [PATCH] refactor: organized script into functions --- testbed/init.sh | 91 ++++++++++++++++++++++++++----------------------- 1 file changed, 49 insertions(+), 42 deletions(-) diff --git a/testbed/init.sh b/testbed/init.sh index cea2c524..db06af62 100755 --- a/testbed/init.sh +++ b/testbed/init.sh @@ -19,52 +19,59 @@ usage() { exit 1 } -if [[ "$#" -lt 1 ]]; then usage; fi +options() { + if [[ "$#" -lt 1 ]]; then usage; fi -for arg in "$@"; do - if ! [[ "$arg" =~ ^-. ]]; then usage; fi -done + for arg in "$@"; do + if ! [[ "$arg" =~ ^-. ]]; then usage; fi + done -while getopts ":hiadc" opt; do - case $opt in - h) - usage - ;; - i) - run_ios=true - ;; - a) - run_and=true - ;; - d) - run_dep=true - ;; - c) - run_cor=true - ;; - *) - usage - ;; - esac -done + while getopts ":hiadc" opt; do + case $opt in + h) + usage + ;; + i) + run_ios=true + ;; + a) + run_and=true + ;; + d) + run_dep=true + ;; + c) + run_cor=true + ;; + *) + usage + ;; + esac + done +} + +main() { + # validate + gulp prod -# validate -gulp prod + # clean + if [[ "$run_cor" == "true" ]]; then npm install -g cordova; fi + if [[ "$run_dep" == "true" ]]; then npm uninstall mkpath node-version-compare plist xml2js; fi + rm -rf ../.installed + rm -rf ./plugins + rm -rf ./platforms -# clean -if [[ "$run_cor" == "true" ]]; then npm install -g cordova; fi -if [[ "$run_dep" == "true" ]]; then npm uninstall mkpath node-version-compare plist xml2js; fi -rm -rf ../.installed -rm -rf ./plugins -rm -rf ./platforms + # build (platforms added before plugin because before_plugin_install does not work on file reference) + if [[ "$run_ios" == "true" ]]; then cordova platform add ios; fi + if [[ "$run_and" == "true" ]]; then cordova platform add android; fi -# build (platforms added before plugin because before_plugin_install does not work on file reference) -if [[ "$run_ios" == "true" ]]; then cordova platform add ios; fi -if [[ "$run_and" == "true" ]]; then cordova platform add android; fi + # plugin + cordova plugin add ../ -# plugin -cordova plugin add ../ + # run + if [[ "$run_ios" == "true" ]]; then cordova build ios && open -a Xcode platforms/ios/Branch\ Testing.xcworkspace; fi + if [[ "$run_and" == "true" ]]; then cordova run android; fi +} -# run -if [[ "$run_ios" == "true" ]]; then cordova build ios && open -a Xcode platforms/ios/Branch\ Testing.xcworkspace; fi -if [[ "$run_and" == "true" ]]; then cordova run android; fi +options "$@" +main