91 lines
4.9 KiB
PowerShell
91 lines
4.9 KiB
PowerShell
# Builds the dashboard exe.
|
|
#
|
|
# powershell -ExecutionPolicy Bypass -File build.ps1 -> ProjectDashboard.exe next to server.js
|
|
# small, for this folder: uses the installed Node.js and .NET 8 Desktop Runtime.
|
|
#
|
|
# powershell -ExecutionPolicy Bypass -File build.ps1 -Release -> release\ProjectDashboard.exe
|
|
# ONE exe to pass on: .NET runtime, node.exe and all dashboard files are inside.
|
|
# On another PC it unpacks itself to %LOCALAPPDATA%\ProjectDashboard on first start
|
|
# and asks for the projects folder and the backup target.
|
|
#
|
|
# Needs the .NET 8+ SDK (and Node.js on this PC, which is copied into the release exe).
|
|
param([switch]$Release)
|
|
$ErrorActionPreference = 'Stop'
|
|
$here = $PSScriptRoot
|
|
$launcher = Join-Path $here 'launcher'
|
|
$csproj = Join-Path $launcher 'ProjectDashboard.csproj'
|
|
|
|
if (-not (Test-Path (Join-Path $launcher 'app.ico'))) { & (Join-Path $launcher 'make-icon.ps1') }
|
|
|
|
if (-not $Release) {
|
|
$stage = Join-Path $launcher 'publish'
|
|
dotnet publish $csproj -c Release -o $stage --nologo -v q
|
|
if ($LASTEXITCODE -ne 0) { throw "dotnet publish failed ($LASTEXITCODE)" }
|
|
Copy-Item (Join-Path $stage 'ProjectDashboard.exe') (Join-Path $here 'ProjectDashboard.exe') -Force
|
|
Remove-Item $stage -Recurse -Force
|
|
Write-Host "-> $(Join-Path $here 'ProjectDashboard.exe')"
|
|
return
|
|
}
|
|
|
|
# ── release: assemble the payload ────────────────────────────────────────────
|
|
$payload = Join-Path $launcher 'payload-stage'
|
|
$zip = Join-Path $launcher 'payload.zip'
|
|
if (Test-Path $payload) { Remove-Item $payload -Recurse -Force }
|
|
New-Item -ItemType Directory $payload | Out-Null
|
|
|
|
Write-Host '1/3 Paket zusammenstellen ...'
|
|
foreach ($f in 'server.js', 'package.json') { Copy-Item (Join-Path $here $f) $payload }
|
|
foreach ($d in 'lib', 'public') { Copy-Item (Join-Path $here $d) (Join-Path $payload $d) -Recurse }
|
|
|
|
# node_modules: everything the server needs, but from lucide-static only the icon sprite
|
|
$nm = Join-Path $payload 'node_modules'
|
|
New-Item -ItemType Directory $nm | Out-Null
|
|
Get-ChildItem (Join-Path $here 'node_modules') -Directory -Force | Where-Object { $_.Name -ne 'lucide-static' -and $_.Name -ne '.bin' } |
|
|
ForEach-Object { Copy-Item $_.FullName (Join-Path $nm $_.Name) -Recurse }
|
|
$lucide = Join-Path $nm 'lucide-static'
|
|
New-Item -ItemType Directory $lucide | Out-Null
|
|
foreach ($f in 'sprite.svg', 'LICENSE', 'package.json') { Copy-Item (Join-Path $here "node_modules\lucide-static\$f") $lucide }
|
|
|
|
# cleanup.ps1 (shipped copy, used when the projects folder has no _Tools\Cleanup)
|
|
# dashboard inside _Tools (..\Cleanup) or next to it (..\_Tools\Cleanup); without it the
|
|
# shipped exe measures sizes but offers nothing to delete
|
|
$parent = Split-Path $here -Parent
|
|
$cleanup = @((Join-Path $parent 'Cleanup\cleanup.ps1'), (Join-Path $parent '_Tools\Cleanup\cleanup.ps1')) | Where-Object { Test-Path $_ } | Select-Object -First 1
|
|
if ($cleanup) {
|
|
New-Item -ItemType Directory (Join-Path $payload 'tools') | Out-Null
|
|
Copy-Item $cleanup (Join-Path $payload 'tools\cleanup.ps1')
|
|
} else { Write-Warning 'cleanup.ps1 nicht gefunden - die exe misst Groessen, bietet aber nichts zum Aufraeumen an.' }
|
|
|
|
# node.exe of this PC (MIT license, copied alongside)
|
|
$nodeExe = (Get-Command node -ErrorAction Stop).Source
|
|
New-Item -ItemType Directory (Join-Path $payload 'node') | Out-Null
|
|
Copy-Item $nodeExe (Join-Path $payload 'node\node.exe')
|
|
$nodeLicense = Join-Path (Split-Path $nodeExe -Parent) 'LICENSE'
|
|
if (Test-Path $nodeLicense) { Copy-Item $nodeLicense (Join-Path $payload 'node\LICENSE') }
|
|
Set-Content -Encoding UTF8 (Join-Path $payload 'THIRD-PARTY.txt') @"
|
|
Enthaltene Software:
|
|
- Node.js $(& $nodeExe --version) (MIT) - node\LICENSE
|
|
- Express (MIT) - node_modules\express
|
|
- Lucide Icons (ISC) - node_modules\lucide-static\LICENSE
|
|
"@
|
|
|
|
Write-Host '2/3 Packen ...'
|
|
if (Test-Path $zip) { Remove-Item $zip -Force }
|
|
Add-Type -AssemblyName System.IO.Compression.FileSystem
|
|
[IO.Compression.ZipFile]::CreateFromDirectory($payload, $zip, [IO.Compression.CompressionLevel]::Optimal, $false)
|
|
|
|
# ── release: one self-contained exe with the payload inside ─────────────────
|
|
Write-Host '3/3 exe bauen ...'
|
|
$stage = Join-Path $launcher 'publish-portable'
|
|
dotnet publish $csproj -c Release -p:Portable=true -o $stage --nologo -v q
|
|
if ($LASTEXITCODE -ne 0) { throw "dotnet publish failed ($LASTEXITCODE)" }
|
|
$outDir = Join-Path $here 'release'
|
|
New-Item -ItemType Directory -Force $outDir | Out-Null
|
|
$out = Join-Path $outDir 'ProjectDashboard.exe'
|
|
Copy-Item (Join-Path $stage 'ProjectDashboard.exe') $out -Force
|
|
|
|
Remove-Item $stage, $payload, $zip -Recurse -Force
|
|
# the normal build must not pick up the self-contained restore state
|
|
Remove-Item (Join-Path $launcher 'obj') -Recurse -Force -ErrorAction SilentlyContinue
|
|
Write-Host ("-> {0} ({1:N0} MB)" -f $out, ((Get-Item $out).Length / 1MB))
|