Repository navigation
Expand file tree
/
Copy pathbuild-desktop.ps1
More file actions
322 lines (262 loc) · 10 KB
/
Copy pathbuild-desktop.ps1
File metadata and controls
322 lines (262 loc) · 10 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
[CmdletBinding()]
param(
[ValidateSet("Debug", "Release")]
[string]$Configuration = "Debug",
[switch]$Clean,
[switch]$RestoreNode,
[switch]$Publish
)
$ErrorActionPreference = "Stop"
Set-StrictMode -Version Latest
# Publish without an explicit configuration is a release build.
if ($Publish -and -not $PSBoundParameters.ContainsKey("Configuration")) {
$Configuration = "Release"
}
# DCCExpressHub ACTUAL repository layout:
#
# platformio.ini
# web-ui/
# desktop/
# DCCExpressHub.Desktop.slnx
# DCCExpressHub.Net/
# DCCExpressHub.Net.csproj
# wwwroot/
# DCCExpressHub.Desktop/
# DCCExpressHub.Desktop.csproj
#
$Root = $PSScriptRoot
$VersionFile = Join-Path $Root "VERSION"
$WebUi = Join-Path $Root "web-ui"
$Dist = Join-Path $WebUi "dist"
$DesktopRoot = Join-Path $Root "desktop"
$Solution = Join-Path $DesktopRoot "DCCExpressHub.Desktop.slnx"
$ServerRoot = Join-Path $DesktopRoot "DCCExpressHub.Net"
$ServerProject = Join-Path $ServerRoot "DCCExpressHub.Net.csproj"
$WwwRoot = Join-Path $ServerRoot "wwwroot"
$DesktopProjectRoot = Join-Path $DesktopRoot "DCCExpressHub.Desktop"
$DesktopProject = Join-Path $DesktopProjectRoot "DCCExpressHub.Desktop.csproj"
function Step([string]$Text) {
Write-Host ""
Write-Host "==> $Text" -ForegroundColor Cyan
}
function CheckExit([string]$What) {
if ($LASTEXITCODE -ne 0) {
throw "$What failed with exit code $LASTEXITCODE."
}
}
function Require([string]$Path, [string]$Name) {
if (-not (Test-Path $Path)) {
throw "$Name not found: $Path"
}
}
Require (Join-Path $WebUi "package.json") "WebUI package.json"
Require $VersionFile "VERSION"
Require $Solution "Desktop solution"
Require $ServerProject "Server project"
Require $DesktopProject "Desktop project"
Write-Host ""
Write-Host "DCCExpressHub Desktop build" -ForegroundColor Green
Write-Host "Repository : $Root"
Write-Host "WebUI : $WebUi"
Write-Host "wwwroot : $WwwRoot"
Write-Host "Solution : $Solution"
Write-Host "Config : $Configuration"
if ($Clean) {
Step "Cleaning generated output"
$cleanDirs = @(
$Dist,
(Join-Path $ServerRoot "bin"),
(Join-Path $ServerRoot "obj"),
(Join-Path $DesktopRoot "DCCExpressHub.Runtime\bin"),
(Join-Path $DesktopRoot "DCCExpressHub.Runtime\obj"),
(Join-Path $DesktopProjectRoot "bin"),
(Join-Path $DesktopProjectRoot "obj")
)
foreach ($dir in $cleanDirs) {
if (Test-Path $dir) {
Write-Host "Removing $dir"
Remove-Item $dir -Recurse -Force
}
}
}
Step "Preparing WebUI dependencies"
Push-Location $WebUi
try {
if ($RestoreNode -or -not (Test-Path "node_modules")) {
if (Test-Path "package-lock.json") {
& npm ci
CheckExit "npm ci"
}
else {
& npm install
CheckExit "npm install"
}
}
else {
Write-Host "node_modules already exists - restore skipped."
}
Step "Building WebUI"
& npm run build
CheckExit "npm run build"
}
finally {
Pop-Location
}
$Version = (Get-Content $VersionFile -Raw).Trim()
if ([string]::IsNullOrWhiteSpace($Version)) {
throw "VERSION file is empty."
}
[System.IO.File]::WriteAllText(
(Join-Path $Dist "version.json"),
('{"version":"' + $Version + '"}' + [Environment]::NewLine),
(New-Object System.Text.UTF8Encoding($false))
)
Require (Join-Path $Dist "index.html") "Built WebUI index.html"
Require (Join-Path $Dist "version.json") "Built WebUI version.json"
Step "Refreshing desktop\DCCExpressHub.Net\wwwroot"
# wwwroot is the committed Desktop/Web backend snapshot of web-ui/dist.
# Recreate it completely so deleted/renamed Vite assets cannot remain behind.
if (Test-Path $WwwRoot) {
Remove-Item $WwwRoot -Recurse -Force
}
New-Item -ItemType Directory -Path $WwwRoot -Force | Out-Null
# Copy the CONTENTS of dist into wwwroot.
Copy-Item (Join-Path $Dist "*") $WwwRoot -Recurse -Force
Require (Join-Path $WwwRoot "index.html") "Synchronized wwwroot index.html"
# Verify the sync by relative file list + SHA256.
$distFiles = @(
Get-ChildItem $Dist -File -Recurse |
ForEach-Object {
[PSCustomObject]@{
Relative = $_.FullName.Substring($Dist.Length).TrimStart('\','/')
Hash = (Get-FileHash $_.FullName -Algorithm SHA256).Hash
}
} |
Sort-Object Relative
)
$wwwFiles = @(
Get-ChildItem $WwwRoot -File -Recurse |
ForEach-Object {
[PSCustomObject]@{
Relative = $_.FullName.Substring($WwwRoot.Length).TrimStart('\','/')
Hash = (Get-FileHash $_.FullName -Algorithm SHA256).Hash
}
} |
Sort-Object Relative
)
$distMap = @{}
foreach ($f in $distFiles) { $distMap[$f.Relative] = $f.Hash }
$wwwMap = @{}
foreach ($f in $wwwFiles) { $wwwMap[$f.Relative] = $f.Hash }
if ($distMap.Count -ne $wwwMap.Count) {
throw "wwwroot sync verification failed: dist=$($distMap.Count), wwwroot=$($wwwMap.Count)"
}
foreach ($name in $distMap.Keys) {
if (-not $wwwMap.ContainsKey($name)) {
throw "wwwroot sync verification failed: missing '$name'"
}
if ($wwwMap[$name] -ne $distMap[$name]) {
throw "wwwroot sync verification failed: hash mismatch '$name'"
}
}
Write-Host "wwwroot synchronized and verified: $($distMap.Count) files." -ForegroundColor Green
Step "Building Desktop solution"
# Normal VS/debug builds intentionally remain ordinary DLL-based builds.
# Only the release package generated by -Publish is converted to single-file.
& dotnet build $Solution -c $Configuration
CheckExit "dotnet build"
$DesktopOutput = Join-Path $DesktopProjectRoot "bin\$Configuration\net10.0-windows"
$RuntimeIndex = Join-Path $DesktopOutput "backend\wwwroot\index.html"
Require $RuntimeIndex "Desktop runtime WebUI"
if ($Publish) {
Step "Publishing clean self-contained Windows x64 release"
$PublishRoot = Join-Path $Root "dist\desktop"
$PublishDir = Join-Path $PublishRoot "win-x64"
$TempRoot = Join-Path $PublishRoot ".publish-temp"
$DesktopTemp = Join-Path $TempRoot "desktop"
$ZipPath = Join-Path $PublishRoot "DCCExpressHub-$Version-win-x64.zip"
foreach ($dir in @($PublishDir, $TempRoot)) {
if (Test-Path $dir) {
Remove-Item $dir -Recurse -Force
}
}
New-Item -ItemType Directory -Path $PublishDir -Force | Out-Null
New-Item -ItemType Directory -Path $DesktopTemp -Force | Out-Null
Step "Publishing Desktop shell as single-file EXE"
& dotnet publish $DesktopProject `
-c $Configuration `
-r win-x64 `
--self-contained true `
-p:PublishSingleFile=true `
-p:IncludeNativeLibrariesForSelfExtract=true `
-p:EnableCompressionInSingleFile=true `
-p:PublishTrimmed=false `
-p:PublishReadyToRun=false `
-p:DebugSymbols=false `
-p:DebugType=None `
-o $DesktopTemp
CheckExit "Desktop single-file publish"
Require (Join-Path $DesktopTemp "DCCExpressHub.Desktop.exe") "Published Desktop executable"
# Copy all actual publish outputs except symbols. In a normal single-file
# publish this is essentially the EXE; if WebView2 leaves a required native
# loader beside it, that loader is preserved automatically.
Get-ChildItem $DesktopTemp -File -Recurse |
Where-Object {
$_.Extension -ne ".pdb" -and
-not (
$_.Extension -eq ".xml" -and
$_.Name -like "Microsoft.Web.WebView2.*.xml"
)
} |
ForEach-Object {
$relative = $_.FullName.Substring($DesktopTemp.Length).TrimStart('\','/')
$target = Join-Path $PublishDir $relative
$targetDir = Split-Path $target -Parent
if (-not (Test-Path $targetDir)) {
New-Item -ItemType Directory -Path $targetDir -Force | Out-Null
}
Copy-Item $_.FullName $target -Force
}
Require (Join-Path $PublishDir "DCCExpressHub.Desktop.exe") "Packaged Desktop executable"
Require (Join-Path $PublishDir "backend\wwwroot\index.html") "Packaged WebUI"
# Keep the human-readable product version beside the launcher. The desktop
# shell reads this at runtime, so the startup dialog shows the release
# version instead of falling back to the assembly default.
Copy-Item $VersionFile (Join-Path $PublishDir "VERSION") -Force
# Never ship symbols or WebView2 XML API documentation from the release package.
Get-ChildItem $PublishDir -Filter "*.pdb" -File -Recurse -ErrorAction SilentlyContinue |
Remove-Item -Force
Get-ChildItem $PublishDir -Filter "Microsoft.Web.WebView2.*.xml" -File -Recurse -ErrorAction SilentlyContinue |
Remove-Item -Force
if (Test-Path $ZipPath) {
Remove-Item $ZipPath -Force
}
Step "Creating release ZIP"
Compress-Archive `
-Path (Join-Path $PublishDir "*") `
-DestinationPath $ZipPath `
-CompressionLevel Optimal
Require $ZipPath "Windows release ZIP"
# Temp publish trees contain the uncurated intermediate output only.
Remove-Item $TempRoot -Recurse -Force
Write-Host ""
Write-Host "Clean release package:" -ForegroundColor Green
Write-Host " DCCExpressHub.Desktop.exe"
Write-Host " backend\wwwroot\..."
Write-Host " (+ only publish-required external files, if any)"
Write-Host ""
Write-Host "Release ZIP : $ZipPath" -ForegroundColor Green
}
Write-Host ""
Write-Host "============================================================" -ForegroundColor Green
Write-Host " DCCExpressHub Desktop build OK" -ForegroundColor Green
Write-Host "============================================================" -ForegroundColor Green
Write-Host "WebUI source : web-ui"
Write-Host "WebUI build : web-ui\dist"
Write-Host "Server UI : desktop\DCCExpressHub.Net\wwwroot"
Write-Host "Desktop out : desktop\DCCExpressHub.Desktop\bin\$Configuration\net10.0-windows"
Write-Host "Runtime UI : ...\backend\wwwroot"
if ($Publish) {
Write-Host "Release ZIP : dist\desktop\DCCExpressHub-$Version-win-x64.zip"
}
Write-Host ""