Skip to content

Instantly share code, notes, and snippets.

@mertenvg
Created January 30, 2019 13:07
Show Gist options
  • Save mertenvg/f4b7695466ebccf1af3255a5bbd33e31 to your computer and use it in GitHub Desktop.
Save mertenvg/f4b7695466ebccf1af3255a5bbd33e31 to your computer and use it in GitHub Desktop.
Replace all {{VAR_NAME}} tokens with their corresponding environment variable values into an `env.json` file
#!/usr/bin/env bash
APP_ROOT="${0%/*}/.."
APP_DIST="$APP_ROOT/build"
mkdir -p "$APP_DIST"
cp "$APP_ROOT/src/env.json.tpl" "$APP_DIST/env.json"
# replace all {{VAR_NAME}} tokens with their corresponding environment variable value
for key in `egrep -io '{{[A-Z_0-9]+}}' src/env.json.tpl | egrep -io '[A-Z_0-9]+'`; do
sed -i '' -e "s|{{${key}}}|${!key}|g" "$APP_DIST/env.json"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment