Confirmation for publish.sh

This commit is contained in:
baldo 2016-06-11 20:13:38 +02:00
parent 211943091d
commit 8e42a60f68

View file

@ -2,24 +2,53 @@
set -e set -e
function confirm() {
msg="$1 [y/n] "
echo -n $msg
while read -n1 c; do
echo
if [ "$c" == "y" ]; then
return 0
fi
if [ "$c" == "n" ]; then
return 1
fi
echo -n $msg
done
}
cd $(dirname $0) cd $(dirname $0)
version=$(grep '^ *"version": *"[^"]*" *, *$' package.json | cut -d '"' -f4) version=$(grep '^ *"version": *"[^"]*" *, *$' package.json | cut -d '"' -f4)
npm_tag=$1
if [ -z "$version" ]; then if [ -z "$version" ]; then
echo "Could not determine current version." echo "Could not determine current version."
exit 1 exit 1
fi fi
echo "Current version: $version" if [ -z "$npm_tag" ]; then
npm_tag=latest
fi
echo "Current version: $version#$npm_tag"
if [[ $version =~ 'SNAPSHOT' ]]; then if [[ $version =~ 'SNAPSHOT' ]]; then
echo "Will not publish SNAPSHOT version." echo "Will not publish SNAPSHOT version."
exit 1 exit 1
fi fi
echo
if confirm "Continue publishing?"; then
./node_modules/.bin/grunt clean build ./node_modules/.bin/grunt clean build
cd dist cd dist
npm publish npm publish -t $npm_tag
fi