|
| 1 | +<# |
| 2 | +.SYNOPSIS |
| 3 | + Post-package safety net for StreamFLOW. |
| 4 | +
|
| 5 | +.DESCRIPTION |
| 6 | + Inspects electron-builder's unpacked output (dist/win-unpacked by default, |
| 7 | + produced before NSIS compression) and asserts that everything the app needs |
| 8 | + at runtime is actually present. If anything is missing it lists exactly what |
| 9 | + and exits non-zero, so a broken installer can never reach dist/ or be |
| 10 | + published by CI. |
| 11 | +
|
| 12 | + This is the last line of defence against the "R Portable Not Found" class of |
| 13 | + bug regardless of how the build was invoked. |
| 14 | +
|
| 15 | +.PARAMETER UnpackedDir |
| 16 | + Path to electron-builder's win-unpacked directory. Defaults to |
| 17 | + <repo>/dist/win-unpacked relative to this script. |
| 18 | +#> |
| 19 | +[CmdletBinding()] |
| 20 | +param( |
| 21 | + [string]$UnpackedDir |
| 22 | +) |
| 23 | + |
| 24 | +$ErrorActionPreference = 'Stop' |
| 25 | + |
| 26 | +$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path |
| 27 | +$rootDir = Split-Path -Parent $scriptDir |
| 28 | + |
| 29 | +if (-not $UnpackedDir -or $UnpackedDir.Trim() -eq '') { |
| 30 | + $UnpackedDir = Join-Path $rootDir 'dist\win-unpacked' |
| 31 | +} |
| 32 | + |
| 33 | +Write-Host '' |
| 34 | +Write-Host '== StreamFLOW package verification ==' -ForegroundColor Cyan |
| 35 | +Write-Host "Inspecting: $UnpackedDir" |
| 36 | +Write-Host '' |
| 37 | + |
| 38 | +$missing = New-Object System.Collections.Generic.List[string] |
| 39 | + |
| 40 | +function Require-File { |
| 41 | + param([string]$RelPath, [string]$Label) |
| 42 | + $full = Join-Path $UnpackedDir $RelPath |
| 43 | + if (Test-Path -LiteralPath $full -PathType Leaf) { |
| 44 | + Write-Host " [OK] $Label" -ForegroundColor Green |
| 45 | + } else { |
| 46 | + Write-Host " [MISSING] $Label" -ForegroundColor Red |
| 47 | + $script:missing.Add("$Label -> $RelPath") |
| 48 | + } |
| 49 | +} |
| 50 | + |
| 51 | +function Require-NonEmptyDir { |
| 52 | + param([string]$RelPath, [string]$Label) |
| 53 | + $full = Join-Path $UnpackedDir $RelPath |
| 54 | + if ((Test-Path -LiteralPath $full -PathType Container) -and |
| 55 | + (Get-ChildItem -LiteralPath $full -Force | Select-Object -First 1)) { |
| 56 | + Write-Host " [OK] $Label" -ForegroundColor Green |
| 57 | + } else { |
| 58 | + Write-Host " [MISSING] $Label (directory absent or empty)" -ForegroundColor Red |
| 59 | + $script:missing.Add("$Label -> $RelPath") |
| 60 | + } |
| 61 | +} |
| 62 | + |
| 63 | +if (-not (Test-Path -LiteralPath $UnpackedDir -PathType Container)) { |
| 64 | + Write-Host "FATAL: unpacked directory not found: $UnpackedDir" -ForegroundColor Red |
| 65 | + Write-Host 'Did electron-builder run? Expected dist\win-unpacked to exist.' -ForegroundColor Red |
| 66 | + exit 1 |
| 67 | +} |
| 68 | + |
| 69 | +# --- Bundled R runtime (extraResources -> resources/) --- |
| 70 | +Require-File 'resources\R-Portable\bin\Rscript.exe' 'R-Portable Rscript.exe' |
| 71 | +Require-NonEmptyDir 'resources\R-Portable\library\CytoExploreR' 'R-Portable CytoExploreR library' |
| 72 | + |
| 73 | +# --- Shiny app (extraResources -> resources/) --- |
| 74 | +Require-File 'resources\shiny\app.R' 'Shiny app.R' |
| 75 | + |
| 76 | +# --- Packaged Electron app (asar by default, or unpacked app/ dir) --- |
| 77 | +$asar = Join-Path $UnpackedDir 'resources\app.asar' |
| 78 | +$appMainDir = Join-Path $UnpackedDir 'resources\app\electron' |
| 79 | +if (Test-Path -LiteralPath $asar -PathType Leaf) { |
| 80 | + Write-Host ' [OK] Electron app (resources\app.asar)' -ForegroundColor Green |
| 81 | + # Best-effort: confirm the three entry files live inside the asar. |
| 82 | + $asarCli = Join-Path $rootDir 'node_modules\.bin\asar.cmd' |
| 83 | + if (Test-Path -LiteralPath $asarCli -PathType Leaf) { |
| 84 | + try { |
| 85 | + $listing = & $asarCli list $asar 2>$null |
| 86 | + foreach ($entry in @('/electron/main.js', '/electron/preload.js', '/electron/splash.html')) { |
| 87 | + if ($listing -contains $entry) { |
| 88 | + Write-Host " [OK] asar:$entry" -ForegroundColor Green |
| 89 | + } else { |
| 90 | + Write-Host " [MISSING] asar:$entry" -ForegroundColor Red |
| 91 | + $missing.Add("asar entry $entry") |
| 92 | + } |
| 93 | + } |
| 94 | + } catch { |
| 95 | + Write-Host ' [WARN] could not list app.asar contents; skipping inner check' -ForegroundColor Yellow |
| 96 | + } |
| 97 | + } |
| 98 | +} elseif (Test-Path -LiteralPath $appMainDir -PathType Container) { |
| 99 | + Require-File 'resources\app\electron\main.js' 'electron/main.js' |
| 100 | + Require-File 'resources\app\electron\preload.js' 'electron/preload.js' |
| 101 | + Require-File 'resources\app\electron\splash.html' 'electron/splash.html' |
| 102 | +} else { |
| 103 | + Write-Host ' [MISSING] Electron app (neither resources\app.asar nor resources\app\electron found)' -ForegroundColor Red |
| 104 | + $missing.Add('Electron app payload (app.asar or app/electron)') |
| 105 | +} |
| 106 | + |
| 107 | +Write-Host '' |
| 108 | +if ($missing.Count -gt 0) { |
| 109 | + Write-Host 'VERIFICATION FAILED. The following are missing from the build:' -ForegroundColor Red |
| 110 | + foreach ($m in $missing) { Write-Host " - $m" -ForegroundColor Red } |
| 111 | + Write-Host '' |
| 112 | + Write-Host 'This installer would be broken. Aborting before it can be shipped.' -ForegroundColor Red |
| 113 | + exit 1 |
| 114 | +} |
| 115 | + |
| 116 | +Write-Host 'VERIFICATION PASSED. Installer payload is complete.' -ForegroundColor Green |
| 117 | +exit 0 |
0 commit comments