#!/bin/sh
export NODE_ENV='production'
export TARGET=$1
# ADDING GTAG as per environment to client/index.html
filepath='index.html'
GTAG_PPP=''
GTAG_PROD=''
if [ "$1" = 'ppp' ]; then
GTAG=$GTAG_PPP
fi
if [ "$1" = 'prod' ]; then
GTAG=$GTAG_PROD
fi
sed -i "s/measurementId = null/measurementId = '$GTAG'/g" "$filepath"
echo "Updated $filepath with GTAG for $1 as $GTAG"
# START DEPLOYMENT
npm run build && firebase deploy --only hosting:$1
# Revert change to index.html
mv index.html index.html_bkup
git checkout index.html
echo "Reverting changes made to index.html"
echo "Changes saved to index.html_bkup file. Delete if not required."