Last active
April 4, 2022 01:59
-
-
Save AmirhBeigi/711cac718a655ebb44c404d12205b925 to your computer and use it in GitHub Desktop.
env.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
rm -rf ./env-config.js | |
touch ./env-config.js | |
echo "window._env_ = {" >> ./env-config.js | |
while read -r line || [[ -n "$line" ]]; | |
do | |
if printf '%s\n' "$line" | grep -q -e '=' && printf '%s\n' "$line" | grep -q -e '^PUBLIC'; then | |
name=$(printf '%s\n' "$line" | sed -e 's/=.*//') | |
value=$(printf '%s\n' "$line" | sed -e 's/^[^=]*=//') | |
if [[ -f ".env.local" ]]; then | |
if grep -q -e "^$name=" ".env.local"; then | |
value=$(grep -e "^$name=" ".env.local" | sed -e 's/^[^=]*=//') | |
fi | |
fi | |
if printf '%s\n' "$value" | grep -q -e 'true' ||printf '%s\n' "$value" | grep -q -e 'false' ; then | |
echo " $name: $value," >> ./env-config.js | |
else | |
echo " $name: \`$value\`," >> ./env-config.js | |
fi | |
fi | |
done < .env | |
echo "};" >> ./env-config.js |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment