#!/bin/bash -e
# deployBinary.sh
#
# Execute commands related to deploying the application binary

bundlePath="bundle"
if [ ! -z "$BUNDLE_PATH" ]
then
    bundlePath=$BUNDLE_PATH
fi

export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8

NODE_MODULES_BIN="$(pwd)/node_modules/.bin"
export PATH=$NODE_MODULES_BIN:$PATH

export BUNDLE_VERSION_NAME=$(./scripts/bundleVersion.sh)

platform=""
target=""
if [[ $PLATFORM == "android" ]]; then
    platform="android"
    target=""
elif [[ $PLATFORM == "ios" ]]; then
    platform="ios"
    target="device"
elif [[ $PLATFORM == "iosSimulator" ]]; then
    platform="ios"
    target="simulator"
else
    echo "Unknown argument $PLATFORM"
    exit 1
fi

yarn clean
yarn reset
yarn setup
yarn install
./scripts/yarnInstallSharp.sh
eval "cd $platform"
eval "$bundlePath exec fastlane deploy_binary target:$target"
