forked from codinit-dev/codinit-dev
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbindings.sh
More file actions
executable file
·33 lines (28 loc) · 913 Bytes
/
bindings.sh
File metadata and controls
executable file
·33 lines (28 loc) · 913 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
#!/bin/bash
bindings=""
# Function to extract variable names from the TypeScript interface
extract_env_vars() {
grep -o '[A-Z_]\+:' worker-configuration.d.ts | sed 's/://'
}
# First try to read from .env.local if it exists
if [ -f ".env.local" ]; then
while IFS= read -r line || [ -n "$line" ]; do
if [[ ! "$line" =~ ^# ]] && [[ -n "$line" ]]; then
name=$(echo "$line" | cut -d '=' -f 1)
value=$(echo "$line" | cut -d '=' -f 2-)
value="${value//\"/}"
bindings+="--binding ${name}=${value} "
fi
done < .env.local
else
# If .env.local doesn't exist, use environment variables defined in .d.ts
mapfile -t env_vars < <(extract_env_vars)
# Generate bindings for each environment variable if it exists
for var in "${env_vars[@]}"; do
if [ -n "${!var}" ]; then
bindings+="--binding ${var}=${!var} "
fi
done
fi
bindings="${bindings%% }"
echo "$bindings"