Skip to content

Instantly share code, notes, and snippets.

@AmirhBeigi
Last active April 4, 2022 01:59
Show Gist options
  • Save AmirhBeigi/711cac718a655ebb44c404d12205b925 to your computer and use it in GitHub Desktop.
Save AmirhBeigi/711cac718a655ebb44c404d12205b925 to your computer and use it in GitHub Desktop.
env.sh
#!/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