#!/usr/bin/env bash
set -e
read -p "You're pushing out a public build. Continue (y/n)?" CONT
if [ "$CONT" != "y" ]; then
  echo "Cancelled"
  exit
fi
VERSION=$(node -p "require('./package.json').version")

echo "Pushing out @$VERSION build..."
npm run clean
npm run build

npm publish

URL="http://10.47.2.22/linchpin-web/fk-games-sdk/fkext-browser-min@$VERSION.js"

if curl --output /dev/null --silent --head --fail "$URL"; then
  echo "ERROR: $URL already exists"
  exit
fi

s3cmd put --acl-public --access_key="XQOJ2F5ZK315XXLVB059" --secret_key="jUe34R0Dhf9sD9btxMR+HBBnTNkShCRWEUB0IiAv" --host=10.47.2.22 --host-bucket=10.47.2.22 --no-ssl --recursive --exclude="*.*" --rinclude=".*\-min@(.*).js" --guess-mime-type --add-header="Cache-Control:max-age=630720000,public" --add-header="Content-Encoding:gzip" ./dist/build/ s3://linchpin-web/fk-platform-sdk/
echo "PUSH SUCCESS"