Files
explore/deploy/scripts/make_envs_script.sh
T
omnusandGitHub d7a264b6ee Next.js compliant command for production builds (#2219)
* feat: Vercel compliant command for prod builds

* feat: simplify to a single command, rename command

Also included the script to download assets.

* fix: exclude vercel injected env vars

Vercel injects a number of environment variables, that in some cases can result in run time errors when the app is reading from envs.js. Exclude these.
2024-09-11 12:20:27 +02:00

40 lines
970 B
Bash
Executable File

#!/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."