#!/bin/bash
DIR=`dirname $0`; 
APPDIR="$DIR/.."
pushd $APPDIR
SCRIPT=`basename $0 | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
echo -e "${SCRIPT}: BEGIN `date`"

set -e

git pull
echo -e "${SCRIPT}: updating dependencies..."
npm install --save \
  scv-esm@latest \
  log-instance@latest \
  merkle-json@latest 

npm install --save-dev \
  memo-again@latest 

$DIR/i18n-langs.cjs > $APPDIR/src/languages.mjs
$DIR/get-voices.sh
npm run build:messages

CMD="git status | grep 'nothing to commit' > /dev/null"
if bash -c "$CMD"; then
  echo "$SCRIPT: Nothing to commit (OK)"
  exit 0
fi

echo -e "$SCRIPT: updated package dependencies"
git commit -am "$SCRIPT: updated package dependencies"
VERSION=`npm version patch`
echo -e "$SCRIPT: committing package version ${VERSION}"
git push

# NOTE: The following line publishes software changes to
# all EBT-Sites.
#
# IMPORTANT:  Comment out this line during a development 
# cycle with dangerous changes,
# Uncomment the following line only when you need to update
# all EBT-sites.
#
npm publish

echo -e "${SCRIPT}: END `date`"
