-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd-bundle.mjs
More file actions
38 lines (36 loc) · 1.54 KB
/
Copy pathadd-bundle.mjs
File metadata and controls
38 lines (36 loc) · 1.54 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
#!/usr/bin/env node
/**
* Add a package to a DSH profile's `dsh.profile.bundles`.
*
* `dsh plugin add` installs the package and nothing else. A plugin composes only
* when it is listed in the profile's bundles array, so an installed-but-unlisted
* plugin is inert: it appears in `package.json`, is absent from `--dump-config`,
* and contributes no rows at all. That is what left the `web` profile running
* without a Feature Loop page while reporting a successful install.
*
* Idempotent, and it rewrites only that one array — the file is the user's, and
* reformatting it would bury the change in a diff nobody asked for.
*
* Usage: node scripts/add-bundle.mjs <profilePackageJson> <packageName>
*/
import { readFileSync, writeFileSync } from 'node:fs'
const [file, pkg] = process.argv.slice(2)
if (file === undefined || pkg === undefined) {
process.stderr.write('usage: add-bundle.mjs <profile-package.json> <package-name>\n')
process.exit(2)
}
const manifest = JSON.parse(readFileSync(file, 'utf8'))
const bundles = manifest.dsh?.profile?.bundles
if (!Array.isArray(bundles)) {
process.stderr.write(`${file}: no dsh.profile.bundles array to add to\n`)
process.exit(1)
}
if (bundles.includes(pkg)) {
console.log(`already listed: ${pkg}`)
process.exit(0)
}
// Bundles compose in order, and this plugin is an add-on to the web app rather
// than a layer beneath it, so it goes last.
bundles.push(pkg)
writeFileSync(file, `${JSON.stringify(manifest, null, 2)}\n`, 'utf8')
console.log(`added ${pkg} to dsh.profile.bundles (${bundles.length} bundles)`)