export const CURRENT_VERSION = '1.0.61 (2018.07.13.22.32) - UAT1'
export const CURRENT_ENVIRONMENT = ENVIRONMENT.TEST1
export const environmentVariable = getEnvironmentFile(CURRENT_ENVIRONMENT)
app.js file content is as above.
I am trying to replace the content of the file, during the build time as below
sh "./envScript 'app.js' 2 \"$VERSION_NUMBER ($BUILD_NUMBER) - PROD\""
and my envScript.sh is as below
#!/bin/bash
if [ $# == 3 ]; then
sed -i '' '/export const CURRENT_VERSION =/d' $1
sed -i '' '/export const CURRENT_ENVIRONMENT =/d' $1
sed -i '' '$a\
export var CURRENT_VERSION = '"'$3'" $1
case $2 in
0)
sed -i '' '$a\
export var CURRENT_ENVIRONMENT = ENVIRONMENT.UAT1' $1
;;
1)
sed -i '' '$a\
export var CURRENT_ENVIRONMENT = ENVIRONMENT.UAT2' $1
;;
2)
sed -i '' '$a\
export var CURRENT_ENVIRONMENT = ENVIRONMENT.PROD' $1
;;
esac
else
echo "You need to pass AppConfig.js path as a parameter"
fi
problem, this works partially, but always, updates the CURRENT_VERSION and CURRENT_ENVIRONMENT , towards the end of the file, due to which getEnvironmentFile(CURRENT_ENVIRONMENT)
defaults to CURRENT_ENVIRONMENT=undefined
option , since
export const CURRENT_VERSION = '1.0.61 (2018.07.13.22.32) - UAT1'
goes at the end of the file.
requested help : how can we use sed to do inplace edits at the same line in the file, basically find and replace in this situation , so that getEnvironmentFile(CURRENT_ENVIRONMENT)
would always find CURRENT_ENVIRONMENT
before calling, and won't default to undefined. Any help is really appreciated.
Original app.js before running the script
export const CURRENT_VERSION = '1.0.61 (2018.07.13.22.32) - UAT1'
export const CURRENT_ENVIRONMENT = ENVIRONMENT.TEST1
export const environmentVariable = getEnvironmentFile(CURRENT_ENVIRONMENT)
currently modified app.js
after running the command
sh "./envScript '../../App/Config/AppConfig.js' 2 \"$VERSION_NUMBER ($BUILD_NUMBER) - PROD\""
updated file
export const environmentVariable = getEnvironmentFile(CURRENT_ENVIRONMENT)
export const CURRENT_VERSION = '1.0.61 (2018.07.13.22.32) - PROD'
export const CURRENT_ENVIRONMENT = ENVIRONMENT.PROD
expected result
export const CURRENT_VERSION = '1.0.61 (2018.07.13.22.32) - PROD'
export const CURRENT_ENVIRONMENT = ENVIRONMENT.PROD
export const environmentVariable = getEnvironmentFile(CURRENT_ENVIRONMENT)