forked from OKEAMAH/frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake_envs_script.sh
More file actions
executable file
·39 lines (28 loc) · 970 Bytes
/
make_envs_script.sh
File metadata and controls
executable file
·39 lines (28 loc) · 970 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/bash
echo "🌀 Creating client script with ENV values..."
# Define the output file name
output_file="${1:-./public/assets/envs.js}"
touch $output_file;
truncate -s 0 $output_file;
# Check if the .env file exists and load ENVs from it
if [ -f .env ]; then
source .env
export $(cut -d= -f1 .env)
fi
echo "window.__envs = {" >> $output_file;
# Iterate through all environment variables
for var in $(env | grep '^NEXT_PUBLIC_' | cut -d= -f1); do
# Skip variables that start with NEXT_PUBLIC_VERCEL. Vercel injects these
# and they can cause runtime errors, particularly when commit messages wrap lines.
if [[ $var == NEXT_PUBLIC_VERCEL* ]]; then
continue
fi
# Get the value of the variable
value="${!var}"
# Replace double quotes with single quotes
value="${value//\"/\'}"
# Write the variable name and value to the output file
echo "${var}: \"${value}\"," >> "$output_file"
done
echo "}" >> $output_file;
echo "✅ Done."