<# .SYNOPSIS Packages the modular SciFi-XZBT project into a single, standalone, offline HTML file. .EXAMPLE .\package.ps1 #> [CmdletBinding()] param( [string]$OutputFile = "" ) $rootDir = (Resolve-Path "$PSScriptRoot\..").Path $indexFile = Join-Path $rootDir "index.html" if ([string]::IsNullOrWhiteSpace($OutputFile)) { $OutputFile = Join-Path $rootDir "dist\SciFiAmbientDisplay_v4.html" } if (-not (Test-Path $indexFile)) { Write-Error "index.html not found in $rootDir" exit 1 } Write-Host "Packaging SciFi Ambient Display from $rootDir..." -ForegroundColor Cyan $indexLines = [System.IO.File]::ReadAllLines($indexFile) $output = [System.Collections.Generic.List[string]]::new() foreach ($line in $indexLines) { # Inline CSS stylesheet if ($line -match '') { $cssRel = $matches[1] $cssPath = Join-Path $rootDir $cssRel if (Test-Path $cssPath) { Write-Host " -> Inlining CSS: $cssRel" -ForegroundColor Green $output.Add(" ") } else { Write-Warning "CSS file not found: $cssPath" $output.Add($line) } continue } # Inline JS scripts if ($line -match '') { $jsRel = $matches[1] $jsPath = Join-Path $rootDir $jsRel if (Test-Path $jsPath) { Write-Host " -> Inlining JS: $jsRel" -ForegroundColor Green $output.Add(" ") } else { Write-Warning "JS file not found: $jsPath" $output.Add($line) } continue } $output.Add($line) } $outDir = [System.IO.Path]::GetDirectoryName($OutputFile) if (-not (Test-Path $outDir)) { New-Item -ItemType Directory -Path $outDir -Force | Out-Null } [System.IO.File]::WriteAllLines($OutputFile, $output) $fileSize = (Get-Item $OutputFile).Length $fileSizeKb = [math]::Round($fileSize / 1KB, 2) Write-Host "Build Successful!" -ForegroundColor Green Write-Host "Output: $OutputFile ($fileSizeKb KB, $($output.Count) lines)" -ForegroundColor Yellow