buzzcasting-storage 4.1.0 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -26,7 +26,15 @@
|
|
|
26
26
|
* namespace, so nothing is renamed on the way out - the one thing the build must get right is
|
|
27
27
|
* that `dist/<slug>/<slug>.esm.js` exists.
|
|
28
28
|
*
|
|
29
|
-
*
|
|
29
|
+
* Tenants built with only a `www` output target (ksa-moh, aramco) have no `dist/<slug>` to check,
|
|
30
|
+
* so they pass `--www <slug>`: the same page rewrite and dead-reference guard, then the bundle
|
|
31
|
+
* check asserts `www/build/<slug>.esm.js` exists and that no page loads another tenant's
|
|
32
|
+
* `/build/<other>.esm.js`. That one is not hypothetical: ksa-moh's page named
|
|
33
|
+
* `/build/axagroup.esm.js` while its own build wrote `/build/ksa-moh.esm.js`, so the widget 404s
|
|
34
|
+
* on a correctly built site.
|
|
35
|
+
*
|
|
36
|
+
* Usage: `buzzcasting-production-assets` in a tenant repo after `stencil build` (cwd = repo root),
|
|
37
|
+
* or `buzzcasting-production-assets --www <slug>` in a www-only tenant.
|
|
30
38
|
* Exit: 0 ready to publish, 1 something would 404 once deployed.
|
|
31
39
|
*/
|
|
32
40
|
import { readdirSync, readFileSync, realpathSync, statSync, writeFileSync } from 'node:fs'
|
|
@@ -49,6 +57,14 @@ export const FORBIDDEN = [
|
|
|
49
57
|
'cdn.buzzcasting.net/components/animate.css',
|
|
50
58
|
]
|
|
51
59
|
|
|
60
|
+
function isFile(path) {
|
|
61
|
+
try {
|
|
62
|
+
return statSync(path).isFile()
|
|
63
|
+
} catch {
|
|
64
|
+
return false
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
52
68
|
function htmlFiles(dir, out = []) {
|
|
53
69
|
for (const entry of readdirSync(dir)) {
|
|
54
70
|
const path = join(dir, entry)
|
|
@@ -90,9 +106,20 @@ export function findPublishableBundle(distDir = DIST) {
|
|
|
90
106
|
* Never throws for an ordinary "this build is not publishable" outcome: it reports and returns a
|
|
91
107
|
* non-zero exit code, so a failing build reads as a build failure rather than a crash.
|
|
92
108
|
*/
|
|
93
|
-
export function productionAssets({
|
|
109
|
+
export function productionAssets({
|
|
110
|
+
cwd = process.cwd(),
|
|
111
|
+
log = console.log,
|
|
112
|
+
error = console.error,
|
|
113
|
+
bundle = 'dist',
|
|
114
|
+
slug,
|
|
115
|
+
} = {}) {
|
|
94
116
|
let failures = 0
|
|
95
117
|
|
|
118
|
+
if (bundle === 'www' && !slug) {
|
|
119
|
+
error('production-assets: --www needs the tenant slug, e.g. `buzzcasting-production-assets --www ksa-moh`')
|
|
120
|
+
return { exitCode: 1, rewritten: 0, files: 0 }
|
|
121
|
+
}
|
|
122
|
+
|
|
96
123
|
let files = []
|
|
97
124
|
try {
|
|
98
125
|
files = htmlFiles(join(cwd, WWW))
|
|
@@ -122,17 +149,41 @@ export function productionAssets({ cwd = process.cwd(), log = console.log, error
|
|
|
122
149
|
}
|
|
123
150
|
}
|
|
124
151
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
152
|
+
if (bundle === 'www') {
|
|
153
|
+
const entry = `${slug}.esm.js`
|
|
154
|
+
const expected = join(cwd, WWW, 'build', entry)
|
|
155
|
+
|
|
156
|
+
if (!isFile(expected)) {
|
|
157
|
+
error(`production-assets: expected ${WWW}/build/${entry} - run stencil build first`)
|
|
158
|
+
failures++
|
|
159
|
+
} else {
|
|
160
|
+
log(`production-assets: publishable bundle ${WWW}/build/${entry}`)
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Stencil injects its own loader for the tenant entry, but a page may also name the
|
|
164
|
+
// bundle by hand. A page that loads another tenant's file finds nothing under this
|
|
165
|
+
// www/build/ and the widget never boots, so any other name is a deploy failure.
|
|
166
|
+
for (const file of files) {
|
|
167
|
+
for (const [, ref] of readFileSync(file, 'utf8').matchAll(/\/build\/([\w.-]+\.esm\.js)/g)) {
|
|
168
|
+
if (ref !== entry) {
|
|
169
|
+
error(`production-assets: ${file} loads /build/${ref}, not this tenant's /build/${entry}`)
|
|
170
|
+
failures++
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
132
174
|
} else {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
175
|
+
const { bundles, dirs } = findPublishableBundle(join(cwd, DIST))
|
|
176
|
+
if (bundles.length !== 1) {
|
|
177
|
+
error(
|
|
178
|
+
`production-assets: expected exactly one ${DIST}/<slug>/<slug>.esm.js, found ${bundles.length}` +
|
|
179
|
+
(dirs.length ? ` (directories: ${dirs.join(', ')})` : ` (no ${DIST}/ - run stencil build first)`),
|
|
180
|
+
)
|
|
181
|
+
failures++
|
|
182
|
+
} else {
|
|
183
|
+
log(
|
|
184
|
+
`production-assets: publishable bundle ${DIST}/${bundles[0]}/${bundles[0]}.esm.js -> /storage/customers/${bundles[0]}/`,
|
|
185
|
+
)
|
|
186
|
+
}
|
|
136
187
|
}
|
|
137
188
|
|
|
138
189
|
log(`production-assets: ${rewritten}/${files.length} file(s) rewritten to ${PROD}...`)
|
|
@@ -158,5 +209,7 @@ function invokedDirectly() {
|
|
|
158
209
|
}
|
|
159
210
|
|
|
160
211
|
if (invokedDirectly()) {
|
|
161
|
-
process.
|
|
212
|
+
const args = process.argv.slice(2)
|
|
213
|
+
const bundle = args[0] === '--www' ? 'www' : 'dist'
|
|
214
|
+
process.exit(productionAssets({ bundle, slug: bundle === 'www' ? args[1] : undefined }).exitCode)
|
|
162
215
|
}
|