#!/bin/bash
set -euo pipefail

function color {
  tput bold
  tput setaf "$1"
  shift
  echo "$@"
  tput sgr0
}
function green {
  color 2 "$@"
}
function blue {
  color 4 "$@"
}

blue "Packaging Laser Array assets for Nintendo Switch..."
echo

SCRIPTS_DIR=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )

LASERARRAY_DIR=$SCRIPTS_DIR/../../laser-array
NINTENDO_SWITCH_ASSETS_DIR=$SCRIPTS_DIR/../app/html_document/laserarray.htdocs
rm -rf $NINTENDO_SWITCH_ASSETS_DIR
mkdir -p $NINTENDO_SWITCH_ASSETS_DIR

pushd $LASERARRAY_DIR
BUILD_COMMIT=$(git rev-parse HEAD)
REACT_APP_STARSHOT_PLATFORM="switch_web_tv" REACT_APP_GIT_COMMIT="$BUILD_COMMIT" yarn build
cp -R build/* "$NINTENDO_SWITCH_ASSETS_DIR"
popd

# TODO: We might need to programmatically update the Nintendo Switch project file with all the files that were added

green "Done packaging Laser Array assets for Nintendo Switch"
