aboutsummaryrefslogtreecommitdiffstats
path: root/packaging/win/build-win-common.ps1
blob: e60abc547b71d260a001b1b12032c0beb546e182 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<#
.SYNOPSIS
    Steps shared by build-win.ps1 (Full) and build-win-light.ps1 (Light).

.DESCRIPTION
    Dot-sourced, not run directly -- it defines functions, it does not call
    them. The two orchestrators differ only in whether they freeze a node
    runtime and which electron-builder config they hand to the final step;
    everything before that (Node version check, npm ci, the Electron-bump
    policy, sync-ui) is identical, and living in one place means it cannot
    drift between the two the way a copy-paste would.

    Every function assumes it runs from packages/meshbay-client (both
    orchestrators Push-Location there first).
#>

function Step($msg) { Write-Host "==> $msg" -ForegroundColor Cyan }

function Assert-NodeVersion {
    if (-not (Get-Command node -ErrorAction SilentlyContinue)) {
        throw "Node.js not found. Install Node 22 or newer from nodejs.org."
    }
    $nodeMajor = [int](& node -e "process.stdout.write(String(process.versions.node.split('.')[0]))")
    if ($nodeMajor -lt 22) { throw "Node $nodeMajor is too old -- need 22 or newer for Electron" }
    Step "Node $(& node --version)"
}

function Invoke-NpmCi {
    Step "npm ci"
    & npm ci --ignore-scripts
    if ($LASTEXITCODE -ne 0) { throw "npm ci failed" }
}

# Chromium-CVE policy: build against the latest Electron release unless
# -NoElectronBump was passed. Writes package.json + package-lock.json when it
# actually bumps something (that is by design -- commit the new pin); the
# Chromium download itself always runs, bump or not, same as before this was
# factored out.
function Invoke-ElectronBump {
    param(
        [switch]$NoElectronBump,
        [Parameter(Mandatory = $true)][string]$WinDir
    )
    if (-not $NoElectronBump) {
        Step "checking for a newer Electron"
        $bumped = & node (Join-Path $WinDir "bump-electron.mjs")
        if ($LASTEXITCODE -ne 0) { throw "electron bump failed" }
        if ($bumped) {
            Write-Host "    Electron -> $bumped  (package.json + lock updated, commit them)" -ForegroundColor Yellow
        } else {
            Write-Host "    Electron is already current"
        }
    }

    Step "downloading Electron's Chromium"
    & npm approve-scripts electron 2>$null
    & node node_modules/electron/install.js
}

function Invoke-SyncUi {
    Step "npm run sync-ui"
    & npm run sync-ui
    if ($LASTEXITCODE -ne 0) { throw "sync-ui failed" }
}