-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathbuild_release.ps1
More file actions
61 lines (55 loc) · 1.93 KB
/
build_release.ps1
File metadata and controls
61 lines (55 loc) · 1.93 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# Build release version with environment variables from .env file
# Usage: .\build_release.ps1 [apk|appbundle|ios|windows|linux|macos|web]
param(
[string]$Target = "apk"
)
# Read .env file
$envFile = ".env"
if (Test-Path $envFile) {
Get-Content $envFile | ForEach-Object {
if ($_ -match '^(.+?)=(.+)$') {
$name = $matches[1].Trim()
$value = $matches[2].Trim()
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-Error ".env file not found!"
exit 1
}
# Build dart-define arguments
$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`""
}
# Build based on target
$cmd = ""
switch ($Target.ToLower()) {
"apk" { $cmd = "flutter build apk --release" }
"appbundle" { $cmd = "flutter build appbundle --release" }
"ios" { $cmd = "flutter build ios --release" }
"windows" { $cmd = "flutter build windows --release" }
"linux" { $cmd = "flutter build linux --release" }
"macos" { $cmd = "flutter build macos --release" }
"web" { $cmd = "flutter build web --release" }
default {
Write-Error "Unknown target: $Target"
Write-Host "Valid targets: apk, appbundle, ios, windows, linux, macos, web"
exit 1
}
}
Write-Host "Building: $cmd with dart-defines" -ForegroundColor Cyan
& flutter build $Target --release @defines
if ($LASTEXITCODE -eq 0) {
Write-Host "Build completed successfully!" -ForegroundColor Green
} else {
Write-Error "Build failed!"
}