1234567891011121314151617181920212223242526272829 |
- #!/bin/bash
- # Recreate config file
- rm -rf ./build/env-config.js
- touch ./build/env-config.js
- # Add assignment
- echo "window._env_ = {" >> ./build/env-config.js
- # Read each line in .env file
- # Each line represents key=value pairs
- while read -r line || [[ -n "$line" ]];
- do
- # Split env variables by character `=`
- if printf '%s\n' "$line" | grep -q -e '='; then
- varname=$(printf '%s\n' "$line" | sed -e 's/=.*//')
- varvalue=$(printf '%s\n' "$line" | sed -e 's/^[^=]*=//')
- fi
- # Read value of current variable if exists as Environment variable
- value=$(printf '%s\n' "${!varname}")
- # Otherwise use value from .env file
- [[ -z $value ]] && value=${varvalue}
-
- # Append configuration property to JS file
- echo " $varname: \"$value\"," >> ./build/env-config.js
- done < ./build/.env
- echo "}" >> ./build/env-config.js
|