#!/bin/bash
DIR=`dirname $0`; 
pushd $DIR/..
SCRIPT=`basename $0 | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`

git pull

echo "$SCRIPT: building examples-json.js"
$DIR/js/examples-json.js; RC=$? || exit $RC

echo "$SCRIPT: building esd3 example graphs"
$DIR/ebt-es

git status | grep 'nothing to commit' > /dev/null; RC=$?
if [ "$RC" == "0" ]; then
  echo "$SCRIPT: Nothing to commit"
elif [ "$1" == "PUSH" ]; then
  echo "$SCRIPT: committing..."
  git commit -am "$SCRIPT updating examples"
  npm version patch
  VERSION=`$DIR/version`
  git reset --soft HEAD~1
  git commit --amend -m "$SCRIPT: v$VERSION"
  git push
  $DIR/publish-npm
else 
  echo $SCRIPT: PUSH not requested, changes not committed
fi
