Repository navigation
Expand file tree
/
Copy pathbuild-merged.ps1
More file actions
118 lines (97 loc) · 3.12 KB
/
Copy pathbuild-merged.ps1
File metadata and controls
118 lines (97 loc) · 3.12 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
param(
[ValidateSet(
"sunton-8048s043-dccex",
"sunton-8048s043-z21"
)]
[string]$Environment = "sunton-8048s043-dccex",
[switch]$SkipWeb
)
$ErrorActionPreference = "Stop"
Set-Location $PSScriptRoot
function Get-PlatformIO {
$cmd = Get-Command pio -ErrorAction SilentlyContinue
if ($cmd) {
return $cmd.Source
}
$candidates = @(
(Join-Path $env:USERPROFILE ".platformio\penv\Scripts\pio.exe"),
(Join-Path $env:USERPROFILE ".platformio\penv\Scripts\platformio.exe")
)
foreach ($candidate in $candidates) {
if (Test-Path $candidate) {
return $candidate
}
}
throw @"
PlatformIO CLI not found.
Tried:
- pio from PATH
- $env:USERPROFILE\.platformio\penv\Scripts\pio.exe
- $env:USERPROFILE\.platformio\penv\Scripts\platformio.exe
"@
}
function Get-FirmwareTarget {
param(
[Parameter(Mandatory = $true)]
[string]$Environment
)
switch ($Environment) {
"sunton-8048s043-dccex" {
return @{
DisplayName = "Sunton ESP32-8048S043 / DCC-EX"
FileTag = "Sunton-ESP32-8048S043-DCCEX"
}
}
"sunton-8048s043-z21" {
return @{
DisplayName = "Sunton ESP32-8048S043 / Z21 + YaMoRC"
FileTag = "Sunton-ESP32-8048S043-Z21"
}
}
default {
throw "Unsupported PlatformIO environment: $Environment"
}
}
}
$pio = Get-PlatformIO
$target = Get-FirmwareTarget -Environment $Environment
$packageJson = Get-Content ".\web-ui\package.json" -Raw | ConvertFrom-Json
$version = [string]$packageJson.version
if ([string]::IsNullOrWhiteSpace($version)) {
throw "web-ui\package.json does not contain a firmware version."
}
$outputName = "DCCExpressHub-{0}-v{1}-merged.bin" -f $target.FileTag, $version
$outputPath = Join-Path ".\dist\firmware" $outputName
Write-Host "== DCCExpressHub merged firmware ==" -ForegroundColor Cyan
Write-Host "Target: $($target.DisplayName)" -ForegroundColor DarkGray
Write-Host "Environment: $Environment" -ForegroundColor DarkGray
Write-Host "Version: $version" -ForegroundColor DarkGray
Write-Host "PlatformIO: $pio" -ForegroundColor DarkGray
Write-Host ""
if (-not $SkipWeb) {
& ".\build-web.ps1"
if ($LASTEXITCODE -ne 0) {
throw "Web build failed."
}
}
Write-Host "== Building firmware [$Environment] ==" -ForegroundColor Cyan
& $pio run -e $Environment
if ($LASTEXITCODE -ne 0) {
throw "PlatformIO firmware build failed."
}
Write-Host "== Building LittleFS [$Environment] ==" -ForegroundColor Cyan
& $pio run -e $Environment -t buildfs
if ($LASTEXITCODE -ne 0) {
throw "PlatformIO LittleFS build failed."
}
Write-Host "== Merging factory image ==" -ForegroundColor Cyan
node ".\tools\firmware\merge-firmware.mjs" --env $Environment
if ($LASTEXITCODE -ne 0) {
throw "Merged firmware generation failed."
}
if (-not (Test-Path $outputPath)) {
throw "Expected merged firmware was not created: $outputPath"
}
Write-Host ""
Write-Host "Done." -ForegroundColor Green
Write-Host "Firmware: $outputPath" -ForegroundColor Green