-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmake.ps1
More file actions
169 lines (160 loc) · 6.46 KB
/
Copy pathmake.ps1
File metadata and controls
169 lines (160 loc) · 6.46 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
# Windows wrapper that mirrors the Makefile targets one-for-one.
# Invoke through make.bat (`make build`, `make build-app-main`, 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
# (name, dir, out) tuples - single source of truth for every build-app-* /
# build-wc-* target. Keep in sync with the Makefile when adding apps.
$apps = @(
@{ name = 'main'; dir = 'frontend/applications/main'; out = 'static/app/main' }
@{ name = 'iframe-demo'; dir = 'frontend/applications/iframe-demo'; out = 'static/app/iframe-demo' }
)
$wcs = @(
@{ name = 'reaction-bar'; dir = 'frontend/web-components/reaction-bar'; out = 'static/wc/reaction-bar' }
@{ name = 'websocket-log'; dir = 'frontend/web-components/websocket-log'; out = 'static/wc/websocket-log' }
@{ name = 'chart-circle'; dir = 'frontend/web-components/chart-circle'; out = 'static/wc/chart-circle' }
@{ name = 'mermaid'; dir = 'frontend/web-components/mermaid'; out = 'static/wc/mermaid' }
@{ name = 'markdown'; dir = 'frontend/web-components/markdown'; out = 'static/wc/markdown' }
@{ name = 'model-gallery'; dir = 'frontend/web-components/model-gallery'; out = 'static/wc/model-gallery' }
@{ name = 'counter-persist'; dir = 'frontend/web-components/counter-persist'; out = 'static/wc/counter-persist' }
)
# Subset that runs `npm run lint` - mirrors Makefile's `lint:` recipe.
$lintDirs = @(
'frontend/applications/main'
'frontend/web-components/reaction-bar'
'frontend/web-components/websocket-log'
'frontend/web-components/chart-circle'
'frontend/web-components/mermaid'
'frontend/web-components/markdown'
'frontend/web-components/model-gallery'
'frontend/web-components/counter-persist'
)
function Invoke-Recipe {
param(
[Parameter(Mandatory)][string]$Dir,
[Parameter(Mandatory)][string]$Out,
[switch]$Clean
)
Push-Location $Dir
try {
Write-Host "==> $Dir" -ForegroundColor Cyan
# Clean = wipe both node_modules AND package-lock.json. Removing the
# lockfile is what makes a "clean reinstall" actually clean: a stale
# lockfile from before a @wippy-fe/* version bump pins the resolver
# to the OLD versions (npm ERESOLVE) even when package.json now asks
# for the new range.
if ($Clean) {
if (Test-Path 'node_modules') { Remove-Item -Recurse -Force 'node_modules' }
if (Test-Path 'package-lock.json') { Remove-Item -Force 'package-lock.json' }
}
npm install
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)
Push-Location $Dir
try {
Write-Host "==> lint $Dir" -ForegroundColor Cyan
npm run lint
if ($LASTEXITCODE -ne 0) { throw "npm run lint failed in $Dir (exit $LASTEXITCODE)" }
}
finally {
Pop-Location
}
}
function Invoke-BuildAll {
foreach ($i in $script:apps + $script:wcs) {
Invoke-Recipe -Dir $i.dir -Out $i.out
}
}
function Show-Help {
Write-Host "make - Windows mirror of the Makefile (via make.bat -> make.ps1)`n"
Write-Host "Targets:"
Write-Host " build Build every app and web component"
Write-Host " build-app-<name> Build a single app (e.g. build-app-main)"
Write-Host " build-wc-<name> Build a single web component"
Write-Host " lint npm run lint across every package"
Write-Host " clean-build Wipe node_modules + reinstall + rebuild"
Write-Host " dev npm run dev in frontend/applications/main"
Write-Host " run build, then ./wippy.exe run -c"
Write-Host " help Show this message`n"
Write-Host "Apps: $($apps.name -join ', ')"
Write-Host "Web components: $($wcs.name -join ', ')"
}
# Top-level dispatch wrapped in try/catch so a thrown error surfaces as a
# single clean red line + exit 1, instead of PowerShell's default 5-line
# stack trace. `finally` blocks inside the recipe helpers still run via
# normal exception unwinding before control reaches this catch.
try {
switch -Regex ($Target) {
'^help$|^-h$|^--help$' {
Show-Help
break
}
'^build$' {
Invoke-BuildAll
break
}
'^build-app-(.+)$' {
$name = $Matches[1]
$item = $apps | Where-Object { $_.name -eq $name }
if (-not $item) { throw "Unknown app: $name. Run 'make help' for the list." }
Invoke-Recipe -Dir $item.dir -Out $item.out
break
}
'^build-wc-(.+)$' {
$name = $Matches[1]
$item = $wcs | Where-Object { $_.name -eq $name }
if (-not $item) { throw "Unknown web component: $name. Run 'make help' for the list." }
Invoke-Recipe -Dir $item.dir -Out $item.out
break
}
'^lint$' {
foreach ($d in $lintDirs) { Invoke-Lint -Dir $d }
break
}
'^clean-build$' {
# Same set as `build` (every app + web component), wiped clean first so a
# @wippy-fe/* version bump resolves against fresh node_modules + lockfile.
foreach ($i in $script:apps + $script:wcs) { Invoke-Recipe -Dir $i.dir -Out $i.out -Clean }
break
}
'^dev$' {
Push-Location 'frontend/applications/main'
try {
npm run dev
}
finally {
Pop-Location
}
break
}
'^run$' {
Invoke-BuildAll
& "$PSScriptRoot/wippy.exe" run -c
break
}
default {
throw "Unknown target: $Target. Run 'make help' for the list."
}
}
}
catch {
Write-Host $_.Exception.Message -ForegroundColor Red
exit 1
}