-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathenv.ps1
More file actions
31 lines (25 loc) · 963 Bytes
/
env.ps1
File metadata and controls
31 lines (25 loc) · 963 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
$envFileName = ".env.production.local"
$envOutputFile = "./public/env-config.js"
# Recreate config file
Remove-Item -Path $envOutputFile -Force
New-Item -Path $envOutputFile -ItemType File
# Add assignment
Add-Content -Path $envOutputFile -Value "window.env = {"
# Read each line in env file
foreach ($line in Get-Content -Path $envFileName) {
if ($line -match '=') {
$parts = $line -split '=', 2
$varname = $parts[0]
$varvalue = $parts[1]
# Read value of current variable if exists as Environment variable
$value = [System.Environment]::GetEnvironmentVariable($varname)
# Otherwise, use value from env file
if (-not $value) {
$value = $varvalue
}
# Append configuration property to JS file
$lineToAdd = " {0}: `"{1}`"," -f $varname, $value
Add-Content -Path $envOutputFile -Value $lineToAdd
}
}
Add-Content -Path $envOutputFile -Value "}"