Repository navigation
Expand file tree
/
Copy pathbuild.ps1
More file actions
124 lines (100 loc) · 4.36 KB
/
Copy pathbuild.ps1
File metadata and controls
124 lines (100 loc) · 4.36 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<#
.SYNOPSIS
Local (non-CI) build of the Source Addons plugin on Windows.
.DESCRIPTION
Does what .github/workflows/build.yml does, minus the Ubuntu runner and
`make` (not present on this machine):
1. builds ..\gameap-api\web\plugin-sdk - the frontend's `file:` dependency
2. builds the Vue frontend into frontend\dist (embedded by build.rs)
3. builds the wasm and copies it to source-addons.wasm
Node is installed at C:\Program Files\nodejs but is not on PATH, so it is
prepended for the duration of this script only - nothing global changes.
Rust comes from rustup (.cargo\bin, already on the user PATH); the pinned
toolchain and wasm32-wasip1 target come from rust-toolchain.toml.
.PARAMETER Test
Run both test suites (cargo test + vitest) before building the wasm.
.PARAMETER SkipFrontend
Reuse the existing frontend\dist and build only the wasm.
.EXAMPLE
.\build.ps1
.EXAMPLE
.\build.ps1 -Test
#>
param(
[switch]$Test,
[switch]$SkipFrontend
)
$ErrorActionPreference = 'Stop'
$root = $PSScriptRoot
$frontend = Join-Path $root 'frontend'
$sdk = Join-Path (Split-Path $root -Parent) 'gameap-api\web\plugin-sdk'
$wasmOut = Join-Path $root 'target\wasm32-wasip1\release\source_addons.wasm'
$artifact = Join-Path $root 'source-addons.wasm'
foreach ($dir in @('C:\Program Files\nodejs', (Join-Path $env:USERPROFILE '.cargo\bin'))) {
if (Test-Path $dir) { $env:PATH = "$dir;$env:PATH" }
}
function Invoke-Step {
param([string]$Label, [string]$WorkDir, [scriptblock]$Body)
Write-Host ""
Write-Host "==> $Label" -ForegroundColor Cyan
Push-Location $WorkDir
try {
# Native tools (cargo, npm) write progress to stderr, which PowerShell 5.1
# turns into terminating ErrorRecords when the caller pipes with 2>&1.
# Failure is detected from $LASTEXITCODE below, so don't stop on those.
$ErrorActionPreference = 'Continue'
& $Body
if ($LASTEXITCODE -ne 0) { throw "$Label failed (exit code $LASTEXITCODE)" }
} finally {
Pop-Location
}
}
# --- preflight ---------------------------------------------------------------
if (-not (Get-Command node -ErrorAction SilentlyContinue)) {
throw "node not found. Install Node.js 22+ (expected at C:\Program Files\nodejs)."
}
if (-not (Get-Command cargo -ErrorAction SilentlyContinue)) {
throw "cargo not found. Install rustup: winget install --id Rustlang.Rustup --exact"
}
if (-not (Test-Path $sdk)) {
throw @"
The gameap panel checkout is missing: $sdk
The frontend depends on it as file:../../gameap-api/web/plugin-sdk. Create it with:
git clone --depth 1 https://github.com/gameap/gameap.git "$(Split-Path $root -Parent)\gameap-api"
"@
}
# --- 1. plugin SDK -----------------------------------------------------------
# Built with vite directly: `npm run build` also runs tsc, which fails on
# @gameap/ui's missing type declarations. The frontend only needs dist\index.js.
# The @gameap/ui tarball on npm ships without its icons\ directory, so the
# package from the gameap checkout is installed over it.
if (-not $SkipFrontend) {
if (-not (Test-Path (Join-Path $sdk 'dist\index.js'))) {
Invoke-Step 'Building plugin SDK' $sdk {
npm ci
npm install --no-save ..\frontend\packages\gameap-ui
npx vite build
}
} else {
Write-Host "==> Plugin SDK already built (delete its dist\ to rebuild)" -ForegroundColor DarkGray
}
}
# --- 2. frontend -------------------------------------------------------------
if (-not $SkipFrontend) {
Invoke-Step 'Building frontend' $frontend {
if (-not (Test-Path 'node_modules')) { npm ci }
npm run build
}
}
# --- 3. tests ----------------------------------------------------------------
if ($Test) {
Invoke-Step 'Testing frontend' $frontend { npm test }
Invoke-Step 'Testing backend' $root { cargo test }
}
# --- 4. wasm -----------------------------------------------------------------
Invoke-Step 'Building wasm' $root { cargo build --target wasm32-wasip1 --release }
Copy-Item $wasmOut $artifact -Force
$version = (Select-String -Path (Join-Path $root 'Cargo.toml') -Pattern '^version\s*=\s*"(.+)"').Matches[0].Groups[1].Value
$size = [math]::Round((Get-Item $artifact).Length / 1KB)
Write-Host ""
Write-Host "Built source-addons.wasm v$version ($size KB)" -ForegroundColor Green