Files
SciFi-XZBT/tools/package.ps1
T
2026-09-03 21:09:32 -07:00

78 lines
2.2 KiB
PowerShell

<#
.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 '<link\s+rel="stylesheet"\s+href="([^"]+)"\s*/?>') {
$cssRel = $matches[1]
$cssPath = Join-Path $rootDir $cssRel
if (Test-Path $cssPath) {
Write-Host " -> Inlining CSS: $cssRel" -ForegroundColor Green
$output.Add(" <style>")
$cssContent = [System.IO.File]::ReadAllLines($cssPath)
foreach ($cl in $cssContent) { $output.Add($cl) }
$output.Add(" </style>")
} else {
Write-Warning "CSS file not found: $cssPath"
$output.Add($line)
}
continue
}
# Inline JS scripts
if ($line -match '<script\s+src="([^"]+)"></script>') {
$jsRel = $matches[1]
$jsPath = Join-Path $rootDir $jsRel
if (Test-Path $jsPath) {
Write-Host " -> Inlining JS: $jsRel" -ForegroundColor Green
$output.Add(" <script>")
$jsContent = [System.IO.File]::ReadAllLines($jsPath)
foreach ($jl in $jsContent) { $output.Add($jl) }
$output.Add(" </script>")
} 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