#!/usr/bin/env bash

set -eu

baseDir=`dirname $0`
baseDir="$baseDir/../pkg"
baseDir=`node -r fs -p "fs.realpathSync(process.argv[1]);" "$baseDir"`

abort() {
	message="$@"

	echo "$message" >&2
	exit 1
}

which ncu || abort "ERROR: npm-check-updates missing"

echo "==== updating faucet-pipeline-js ====" >&2
(cd "$baseDir/.."; ncu -u)

for dir in `find "$baseDir" -type d -d 1`; do
	echo "==== updating `basename $dir` ====" >&2
	(cd "$dir"; ncu -u)
done

echo
cat << EOF
NB: in order to ensure compatibility across faucet plugins, please only \
increase the version number of faucet-pipeline-core when necessary
EOF
echo
read -n1 -p "press any key to confirm" confirmation
