#!/usr/bin/env bash

if [ ! -d www ]; then
    echo Symlinking the escalator-web directory
    ln -s `realpath ../escalator-web/www` `realpath www`
fi

mkdir -p platforms

if [ ! -d platforms/android ]; then
    echo "Installing android platform for cordova"
    cordova platform add android
fi

build() {
    echo "Building android app"
    cordova build android
    cd ./platforms/android/app/
    gradle build
}

deploy() {
    build

    cd build/outputs/apk/debug/

    echo "Removing the previous version if any"
    adb uninstall com.escalator.escalator

    echo "Installing app"
    adb -d install app-debug.apk
}

if [ $# -gt 0 ]; then
    "$@"
else
    deploy
fi

