BUILD=$1
VERSION=`npm version`.$BUILD

# Configure node and npm
echo -------------
echo Node version:
node -v
echo -------------
echo npm version:
npm -v
echo ------------

# Install all dependencies
npm install
bower cache clean
# rm -rf src/bower_components
bower update

# Add build version number to public/index.html
sed -i -e 's/##BUILDVERSION##/'${VERSION}'/g' ./public/index.html

npm run dist
cd dist
if [ "$?" = "0" ]; then
  echo "The /dist folder was created successfully. Build finished."

else
  echo "The /dist folder could not be created. Build failed."
  exit 1
fi

# Create zip file for artifactory (and Jenkins)
zip -r ../admin-ui-microapp-$VERSION.zip *
cd ..
