#!/bin/bash

set -e

BRANCH_NAME='production'

set +e
git branch -D ${BRANCH_NAME}
set -e

rm -rf lib
rm -rf node_modules

npm version patch
git branch ${BRANCH_NAME}
git checkout ${BRANCH_NAME}

npm install
grunt build
rm -rf node_modules
npm install --production
git add -f lib/
git add -f node_modules/
git commit -m "Add generated code and runtime dependencies for elastic.io environment."
git push --force origin ${BRANCH_NAME}

git checkout master

VERSION=$(cat package.json | jq --raw-output .version)
git push origin "v${VERSION}"
npm version patch
npm install

#!/bin/bash

set -e

VERSION=$(cat package.json | jq --raw-output .version)
PKG_NAME=$(cat package.json | jq --raw-output .name)
BRANCH_NAME='production'

echo "About to release ${PKG_NAME} - v${VERSION} to ${BRANCH_NAME} branch!"

cleanup() {
  set +e
  echo "Cleaning up"
  rm -rf package
  rm "${PKG_NAME}"-*
  set -e
}

# cleanup
cleanup

set +e
git branch -D ${BRANCH_NAME}
set -e

# install all deps
echo "Installing all deps"
npm install &>/dev/null
echo "Building sources"
grunt build &>/dev/null

# package npm and extract it
echo "Packaging locally"
npm pack
tar -xzf "${PKG_NAME}-${VERSION}.tgz"

cd package
# install production deps (no devDeps)
echo "Installing only production deps"
npm install --production &>/dev/null
# push everything inside package to selected branch
git init
git remote add origin git@github.com:sphereio/${PKG_NAME}.git
git add -A &>/dev/null
git commit -m "Release packaged version ${VERSION} to ${BRANCH_NAME} branch" &>/dev/null
echo "About to push to ${BRANCH_NAME} branch"
git push --force origin master:${BRANCH_NAME}
cd -

# cleanup
cleanup

echo "Congratulations, the package has been successfully released to branch ${BRANCH_NAME}"

Update release script for elastic
Update release script for elastic
