Repository navigation
Expand file tree
/
Copy pathmake.ps1
More file actions
281 lines (261 loc) · 11.7 KB
/
Copy pathmake.ps1
File metadata and controls
281 lines (261 loc) · 11.7 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
# Windows wrapper that mirrors the Makefile targets one-for-one.
# Invoke through make.bat (`make build-keeper-frontend`, `make publish-dry-run`,
# etc.) or directly: `powershell -ExecutionPolicy Bypass -File make.ps1 <target>`.
#
# Pure ASCII on purpose: Windows PowerShell 5.1 reads BOM-less files as
# Windows-1252, so any non-ASCII char (em-dash, smart quote) corrupts on
# read. Don't introduce non-ASCII chars without also adding a UTF-8 BOM.
[CmdletBinding()]
param(
[Parameter(Position = 0)]
[string]$Target = 'help'
)
$ErrorActionPreference = 'Stop'
Set-Location $PSScriptRoot
# Module versions - mirrors KEEPER_VERSION / USAGE_VERSION in the Makefile.
# Override at invocation: `$env:KEEPER_VERSION = '0.5.17'; make publish-keeper`
$keeperVersion = if ($env:KEEPER_VERSION) { $env:KEEPER_VERSION } else { '0.5.65' }
$usageVersion = if ($env:USAGE_VERSION) { $env:USAGE_VERSION } else { '0.1.1' }
$wippyExe = if ($env:WIPPY) { $env:WIPPY } else { Join-Path $PSScriptRoot 'wippy.exe' }
# (name, dir, out) tuples - single source of truth for every build-* target.
# `out` is relative to the build dir, NOT the repo root, to mirror the
# original Makefile's `--outDir ../../../...` recipe semantics.
$builds = @(
@{ name = 'keeper-frontend'; dir = 'keeper/frontend/applications/keeper'; out = '../../../static/keeper' }
@{ name = 'keeper-git-frontend'; dir = 'keeper/plugins/git/frontend/applications/git'; out = '../../../../../static/keeper-git' }
@{ name = 'wippy-monaco-frontend'; dir = 'keeper/frontend/web-components/wippy-monaco'; out = '../../../static/wippy-monaco' }
@{ name = 'usage-frontend'; dir = 'usage/frontend/applications/usage'; out = '../../../static/keeper-usage' }
)
# (target, modulePath, lintArgs) tuples for `lint-*` recipes. Mirrors the
# Makefile's `cd <module> && wippy lint ...` invocations.
$lints = @(
@{ name = 'keeper'; dir = 'keeper/test'; args = @('lint', '--ns', 'keeper,keeper.*', '--summary', '--limit', '200', '--no-color') }
@{ name = 'usage'; dir = 'usage'; args = @('lint', '--summary', '--limit', '200', '--no-color') }
)
function Invoke-Build {
param(
[Parameter(Mandatory)][string]$Dir,
[Parameter(Mandatory)][string]$Out
)
Push-Location $Dir
try {
Write-Host "==> $Dir" -ForegroundColor Cyan
npm install --no-audit --no-fund --prefer-offline
if ($LASTEXITCODE -ne 0) { throw "npm install failed in $Dir (exit $LASTEXITCODE)" }
npm run build -- --outDir $Out --emptyOutDir
if ($LASTEXITCODE -ne 0) { throw "npm run build failed in $Dir (exit $LASTEXITCODE)" }
}
finally {
Pop-Location
}
}
function Invoke-Lint {
param(
[Parameter(Mandatory)][string]$Dir,
[Parameter(Mandatory)][string[]]$Args
)
Push-Location $Dir
try {
Write-Host "==> lint $Dir" -ForegroundColor Cyan
& $wippyExe @Args
if ($LASTEXITCODE -ne 0) { throw "wippy lint failed in $Dir (exit $LASTEXITCODE)" }
}
finally {
Pop-Location
}
}
function Invoke-Publish {
param(
[Parameter(Mandatory)][string]$Dir,
[Parameter(Mandatory)][string]$Version,
[switch]$DryRun
)
Push-Location $Dir
try {
Write-Host "==> publish $Dir @ $Version$(if ($DryRun) { ' (dry-run)' })" -ForegroundColor Cyan
$args = @('publish', '--version', $Version)
if ($DryRun) { $args = @('publish', '--dry-run', '--version', $Version) }
& $wippyExe @args
if ($LASTEXITCODE -ne 0) { throw "wippy publish failed in $Dir (exit $LASTEXITCODE)" }
}
finally {
Pop-Location
}
}
function Invoke-BuildKeeperBundle {
# publish-keeper / publish-keeper-dry-run depend on these three FE bundles.
Invoke-Build -Dir 'keeper/frontend/applications/keeper' -Out '../../../static/keeper'
Invoke-Build -Dir 'keeper/plugins/git/frontend/applications/git' -Out '../../../../../static/keeper-git'
Invoke-Build -Dir 'keeper/frontend/web-components/wippy-monaco' -Out '../../../static/wippy-monaco'
}
function Invoke-BuildAll {
# Aggregator — every FE app + the monaco WC. Mirrors Makefile `build`.
foreach ($i in $builds) {
Invoke-Build -Dir $i.dir -Out $i.out
}
}
function Invoke-CleanStatic {
# Nuke all built FE artifacts. Forces the next `make build` to rebuild
# from scratch when a stale chunk hash or hoisted asset blocks a fix.
$paths = @(
'keeper/static/keeper',
'keeper/static/keeper-git',
'keeper/static/wippy-monaco',
'usage/static/keeper-usage'
)
foreach ($p in $paths) {
$full = Join-Path $PSScriptRoot $p
if (Test-Path $full) {
Write-Host "==> rm -rf $p" -ForegroundColor Cyan
Remove-Item -Recurse -Force $full
}
}
}
function Invoke-Dev {
param(
[Parameter(Mandatory)][string]$Dir,
[Parameter(Mandatory)][string]$Out
)
Push-Location $Dir
try {
Write-Host "==> dev $Dir" -ForegroundColor Cyan
npm install --no-audit --no-fund --prefer-offline
if ($LASTEXITCODE -ne 0) { throw "npm install failed in $Dir (exit $LASTEXITCODE)" }
npm run dev -- --outDir $Out
if ($LASTEXITCODE -ne 0) { throw "npm run dev failed in $Dir (exit $LASTEXITCODE)" }
}
finally {
Pop-Location
}
}
function Invoke-Smoke {
# Headless-browser smoke against the keeper-test harness on $env:BASE_URL
# (defaults to http://localhost:8085 inside smoke.mjs). Phase 1 verifies
# dist/app.html exists for each app; phase 2 logs into keeper-test and
# boots keeper-main + keeper-git in dark + light themes, asserting no
# console errors. See test/smoke/README.md.
Push-Location 'test/smoke'
try {
Write-Host '==> smoke (test/smoke)' -ForegroundColor Cyan
npm install --no-audit --no-fund --prefer-offline
if ($LASTEXITCODE -ne 0) { throw "npm install failed in test/smoke (exit $LASTEXITCODE)" }
npm run smoke
if ($LASTEXITCODE -ne 0) { throw "npm run smoke failed (exit $LASTEXITCODE)" }
}
finally {
Pop-Location
}
}
function Show-Help {
Write-Host "make - Windows mirror of the Makefile (via make.bat -> make.ps1)`n"
Write-Host "Build targets:"
Write-Host " build Build everything (every FE app + monaco WC)"
Write-Host " build-keeper-frontend Build keeper main FE -> keeper/static/keeper"
Write-Host " build-keeper-git-frontend Build keeper-git plugin FE -> keeper/static/keeper-git"
Write-Host " build-wippy-monaco-frontend Build wippy-monaco WC -> keeper/static/wippy-monaco"
Write-Host " build-usage-frontend Build usage FE -> usage/static/keeper-usage"
Write-Host " clean-static Remove all built FE artifacts under static/`n"
Write-Host "Dev (watch) targets:"
Write-Host " dev Alias for dev-keeper (most common entry)"
Write-Host " dev-keeper Watch-rebuild keeper main FE into keeper/static/keeper"
Write-Host " dev-keeper-git Watch-rebuild keeper-git FE into keeper/static/keeper-git"
Write-Host " dev-wippy-monaco Watch-rebuild wippy-monaco WC into keeper/static/wippy-monaco"
Write-Host " dev-usage Watch-rebuild usage FE into usage/static/keeper-usage`n"
Write-Host "Smoke target:"
Write-Host " smoke Headless-browser smoke against keeper-test (test/smoke/README.md)`n"
Write-Host "Lint targets:"
Write-Host " lint lint-keeper + lint-usage"
Write-Host " lint-keeper wippy lint --ns 'keeper,keeper.*' in keeper/"
Write-Host " lint-usage wippy lint in usage/`n"
Write-Host "Publish targets:"
Write-Host " publish publish-keeper + publish-usage"
Write-Host " publish-dry-run publish-keeper-dry-run + publish-usage-dry-run"
Write-Host " publish-keeper build keeper FE bundles, then wippy publish"
Write-Host " publish-keeper-dry-run build keeper FE bundles, then wippy publish --dry-run"
Write-Host " publish-usage build usage FE, then wippy publish"
Write-Host " publish-usage-dry-run build usage FE, then wippy publish --dry-run`n"
Write-Host "Versions (override via env):"
Write-Host " KEEPER_VERSION = $keeperVersion"
Write-Host " USAGE_VERSION = $usageVersion"
Write-Host " WIPPY = $wippyExe"
}
try {
switch -Regex ($Target) {
'^help$|^-h$|^--help$' { Show-Help; break }
'^build$' { Invoke-BuildAll; break }
'^smoke$' { Invoke-Smoke; break }
'^clean-static$' { Invoke-CleanStatic; break }
'^build-(.+)$' {
$name = $Matches[1]
$item = $builds | Where-Object { $_.name -eq $name }
if (-not $item) { throw "Unknown build target: $name. Run 'make help' for the list." }
Invoke-Build -Dir $item.dir -Out $item.out
break
}
'^dev$' {
# Alias — most common entry is the main keeper FE.
$item = $builds | Where-Object { $_.name -eq 'keeper-frontend' }
Invoke-Dev -Dir $item.dir -Out $item.out
break
}
'^dev-(.+)$' {
$name = "$($Matches[1])-frontend"
$item = $builds | Where-Object { $_.name -eq $name }
if (-not $item) { throw "Unknown dev target: $($Matches[1]). Run 'make help' for the list." }
Invoke-Dev -Dir $item.dir -Out $item.out
break
}
'^lint$' {
foreach ($l in $lints) { Invoke-Lint -Dir $l.dir -Args $l.args }
break
}
'^lint-(.+)$' {
$name = $Matches[1]
$item = $lints | Where-Object { $_.name -eq $name }
if (-not $item) { throw "Unknown lint target: $name. Run 'make help' for the list." }
Invoke-Lint -Dir $item.dir -Args $item.args
break
}
'^publish$' {
Invoke-BuildKeeperBundle
Invoke-Publish -Dir 'keeper' -Version $keeperVersion
Invoke-Build -Dir 'usage/frontend/applications/usage' -Out '../../../static/keeper-usage'
Invoke-Publish -Dir 'usage' -Version $usageVersion
break
}
'^publish-dry-run$' {
Invoke-BuildKeeperBundle
Invoke-Publish -Dir 'keeper' -Version $keeperVersion -DryRun
Invoke-Build -Dir 'usage/frontend/applications/usage' -Out '../../../static/keeper-usage'
Invoke-Publish -Dir 'usage' -Version $usageVersion -DryRun
break
}
'^publish-keeper$' {
Invoke-BuildKeeperBundle
Invoke-Publish -Dir 'keeper' -Version $keeperVersion
break
}
'^publish-keeper-dry-run$' {
Invoke-BuildKeeperBundle
Invoke-Publish -Dir 'keeper' -Version $keeperVersion -DryRun
break
}
'^publish-usage$' {
Invoke-Build -Dir 'usage/frontend/applications/usage' -Out '../../../static/keeper-usage'
Invoke-Publish -Dir 'usage' -Version $usageVersion
break
}
'^publish-usage-dry-run$' {
Invoke-Build -Dir 'usage/frontend/applications/usage' -Out '../../../static/keeper-usage'
Invoke-Publish -Dir 'usage' -Version $usageVersion -DryRun
break
}
default {
throw "Unknown target: $Target. Run 'make help' for the list."
}
}
}
catch {
Write-Host $_.Exception.Message -ForegroundColor Red
exit 1
}