-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathrun_with_env.ps1
More file actions
46 lines (41 loc) · 1.5 KB
/
run_with_env.ps1
File metadata and controls
46 lines (41 loc) · 1.5 KB
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
40
41
42
43
44
45
46
# Run Flutter with environment variables from .env file
# Usage: .\run_with_env.ps1 [flutter_run_args]
param(
[string[]]$FlutterArgs = @()
)
# Read .env file
$envFile = ".env"
if (Test-Path $envFile) {
Get-Content $envFile | ForEach-Object {
if ($_ -match '^(.+?)=(.+)$') {
$name = $matches[1].Trim()
$value = $matches[2].Trim()
# Remove quotes if present
if ($value.StartsWith('"') -and $value.EndsWith('"')) {
$value = $value.Substring(1, $value.Length - 2)
}
[Environment]::SetEnvironmentVariable($name, $value, "Process")
Write-Host "Loaded: $name = ***" -ForegroundColor DarkGray
}
}
Write-Host "Environment variables loaded from .env" -ForegroundColor Green
} else {
Write-Warning ".env file not found. Creating from .env.example..."
if (Test-Path ".env.example") {
Copy-Item ".env.example" ".env"
Write-Host "Created .env from .env.example - please edit it with your values!" -ForegroundColor Yellow
}
exit 1
}
# Build flutter run command with dart-define
$defines = @()
if ($env:COUNTLY_SERVER_URL) {
$defines += "--dart-define=COUNTLY_SERVER_URL=`"$env:COUNTLY_SERVER_URL`""
}
if ($env:COUNTLY_APP_KEY) {
$defines += "--dart-define=COUNTLY_APP_KEY=`"$env:COUNTLY_APP_KEY`""
}
$cmd = "flutter run $($defines -join ' ') $($FlutterArgs -join ' ')"
Write-Host "Running: $cmd" -ForegroundColor Cyan
# Execute flutter run
& flutter run @defines @FlutterArgs