#!/usr/bin/env bash
#
# Utility script to update all versions in project

#   V=1.15.1 make set_version
#
if [ -z "$V" ]
then
  echo "V is required variable with new version. example: V=1.15.1 make set_version"
  exit 1
fi

current_version=$(grep \"version\" package.json | sed s/[^0-9\.]//g)
echo "Current Version: $current_version New Version: $V"

# newVersion file
# Use newVersion somefile.json
function newVersion() {
  orig=$1
  tmp=$orig.tmp
  jq ".version = env.V" $orig >  $tmp  && mv $tmp $orig
}

# version the main package
newVersion package.json
newVersion package-lock.json

# version client
newVersion nodejs-client/package.json
newVersion nodejs-client/package-lock.json

sed -i  '' -e "s/appVersion.*/appVersion: $V/" deploy/helm/service-dal/Chart.yaml;

