Files
ProjectDashboard/build.ps1
Michi ca9bde64f7 demo knacksicherer: edition im code + launcher prüft dateien
- edition.json entfällt; die Edition steckt als Marker im Code
  (const BUILD_EDITION). build.ps1 -Demo flippt ihn nur in der gestagten
  Kopie auf 'demo'; die Quelle bleibt 'full'. Keine lösch-/editierbare
  Extra-Datei mehr.
- Launcher: beim Auspacken wird ein Fingerabdruck (SHA-256 über server.js,
  package.json, lib\, public\, tools\) in .ok gespeichert und bei JEDEM
  Start neu geprüft. Wurde im entpackten App-Ordner etwas geändert oder
  gelöscht (z. B. der Demo-Marker zurückgesetzt), wird automatisch das
  Original neu ausgepackt. node_modules/node bleiben aussen vor (gross,
  nicht Teil der Demo-Logik → schneller Start).

Getestet: Marker im entpackten server.js auf 'full' gepatcht → nach
Neustart wieder 'full'->'demo', Server meldet wieder Demo.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-11-25 09:47:17 +01:00

121 lines
6.6 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).
#
# powershell -ExecutionPolicy Bypass -File build.ps1 -Demo -> release\ProjectDashboard-Demo.exe (+ -Demo-Setup.exe)
# the free demo: at most 6 projects (edition marker in server.js). The full build is not touched.
param([switch]$Release, [switch]$Demo)
$ErrorActionPreference = 'Stop'
if ($Demo) { $Release = [switch]$true }
$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
"@
# demo edition: flip the marker in the STAGED server.js only (the source stays 'full')
if ($Demo) {
$sf = Join-Path $payload 'server.js'
$txt = [IO.File]::ReadAllText($sf)
$flip = $txt.Replace("const BUILD_EDITION = 'full'", "const BUILD_EDITION = 'demo'")
if ($flip -eq $txt) { throw "Demo-Marker nicht gefunden in server.js (const BUILD_EDITION = 'full')" }
[IO.File]::WriteAllText($sf, $flip, (New-Object Text.UTF8Encoding $false))
Write-Host ' edition: demo'
}
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 $(if ($Demo) { 'ProjectDashboard-Demo.exe' } else { '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))
# ── installer: release\ProjectDashboard-Setup.exe wraps the exe (Inno Setup 6, optional) ──
$iscc = @("$env:LOCALAPPDATA\Programs\Inno Setup 6\ISCC.exe", "${env:ProgramFiles(x86)}\Inno Setup 6\ISCC.exe", "$env:ProgramFiles\Inno Setup 6\ISCC.exe") |
Where-Object { Test-Path $_ } | Select-Object -First 1
if ($iscc) {
Write-Host 'Setup bauen ...'
$ver = (Get-Content (Join-Path $here 'package.json') -Raw | ConvertFrom-Json).version
$isccArgs = @('/Q', "/DAppVer=$ver")
if ($Demo) { $isccArgs += '/DDemo' }
& $iscc @isccArgs (Join-Path $here 'installer\ProjectDashboard.iss')
if ($LASTEXITCODE -ne 0) { throw "Inno Setup failed ($LASTEXITCODE)" }
$setup = Join-Path $outDir $(if ($Demo) { 'ProjectDashboard-Demo-Setup.exe' } else { 'ProjectDashboard-Setup.exe' })
Write-Host ("-> {0} ({1:N0} MB)" -f $setup, ((Get-Item $setup).Length / 1MB))
} else {
Write-Host 'Setup übersprungen: Inno Setup 6 nicht gefunden (winget install JRSoftware.InnoSetup).'
}