Scripts & help CLI
This page describes the changes introduced in PR #135 โ Add scriptsInfo metadata and CI validation for script documentation
and documents how to use the new scriptsInfo metadata, the validate-scripts tool, the refactored help CLIs, and the CI integration that validates script documentation on PRs.
Package-level scriptsInfo is now the single source of truth for documenting custom npm scripts.
The repo includes a validate-scripts check in ci.yml that enforces a strict 1:1 mapping between scripts and scriptsInfo.
The help CLIs were refactored to read this metadata and a GitHub Actions workflow runs this validation on script-related changes and can annotate PRs when validation fails.
What's in this pageโ
scriptsInfoschema and examples- How to add or update scripts
validate-scriptsusage and CI integration- Refactored
helpCLI and fuzzy search usage - Location of shared libraries and utilities
- Troubleshooting & tips
scriptsInfo โ schema & examplesโ
package.json (root and docs/package.json) now support a top-level scriptsInfo object. It provides structured documentation for custom npm scripts and is intended to be human- and machine-readable.
A minimal example:
{
"scriptsInfo": {
"build-wasm": {
"group": "build",
"desc": "Build the WebAssembly modules used by the app.",
"args": ["<target>", "Optional target; e.g. 'release' or 'debug'"]
},
"help": {
"group": "dev",
"desc": ["Interactive help for available npm scripts."],
"args": []
}
},
"scripts": {
"build-wasm": "make -C src/wasm build",
"help": "node scripts/help.js"
}
}
-
scriptsInfois an object whose keys exactly match thescriptskeys inpackage.json. -
Each script entry may include:
groupโ logical grouping used in the help CLI (e.g.dev,build,docs).descโ a string or an array of strings (multi-line descriptions supported).argsโ an array describing positional or named args the script accepts.
-
The validator enforces a strict 1:1 mapping; every
scriptsentry must have a correspondingscriptsInfoentry and vice versa.- This ensures the scripts are properly documented.
Adding or updating scriptsโ
-
Add your script command under
scriptsinpackage.json. -
Add a matching entry in
scriptsInfousing the schema above."<script-name>": {
"group": "<category-it-falls-under>",
"desc": "<script's-description>",
"args": [
"<optional-arg1>",
"<optional-arg2>",
...
"<optional-argx>"
]
} -
Run the validator locally before pushing:
npm run validate-scriptsIf the validator exits non-zeroFix any missing or mismatched
scriptsInfoentries.
validate-scripts tool & CIโ
The repository includes scripts/validate-scripts.js (and an npm script validate-scripts) which:
- Loads
./package.jsonand./docs/package.json. - Flattens the
scriptsInfostructure (if grouped) and compares the set of keys with thescriptsobject. - Exits with non-zero status if there are missing or extra entries, printing helpful error messages.
CI integrationโ
A GitHub Actions workflow (.github/workflows/ci.yml) was added to:
- Detect if changes in a push/PR touched script-related files.
- Run
npm ciand thennpm run validate-scriptswhen relevant. - Capture validator output and โ on failures โ call a reusable commenter workflow that posts the validation output back to the PR as a comment.
This ensures documentation for scripts can't be accidentally left out of a PR.
Tip: If you're working on a branch and the CI complains, run the validator locally and iterate until it passes.
Refactored help CLIโ
help.js was refactored to:- Read
scriptsandscriptsInfofrompackage.json(the source of truth). - Delegate the fuzzy listing/search UI to a shared orchestrator (
scripts/lib/cli-fuzzy.js). - Support multi-line descriptions and CLI args rendering.
Usage Examplesโ
npm run help
npm run help -- help build
CLI featuresโ
- Fuzzy search of script names and descriptions.
- Grouped presentation of scripts.
- Colorized & formatted output for readability.
Shared utilitiesโ
Shared helper modules live under scripts/lib/ and are used by both the root app and docs app:
cli-fuzzy.jsโ orchestrates rendering of fuzzy-search-based interactive help.colors.jsโ terminal color helpers and formatting.read-packageJson-scripts.jsโ small helper to safely read and returnscripts+scriptsInfofrom package manifests.validate-scripts.jsโ the validator described above (also present atscripts/validate-scripts.js).
When modifying or adding helpers, keep in mind both root and docs apps import these relative utilities.
Troubleshooting & common failuresโ
- Validator fails saying a script is missing from
scriptsInfo: add the scriptsInfo entry with the correct key. - Validator finds an extra
scriptsInfokey: remove or rename thescriptsorscriptsInfoentry to match. - CI workflow errors about
actions/checkoutrunner: update theactions/checkout@v3action ref if actionlint or GitHub Actions suggests a newer pinned version (the existing workflow contains a small actionlint note โ consider updating to the latest stable minor release if needed).
Contributing & making changesโ
- Update both
package.json(ordocs/package.json)scriptsandscriptsInfotogether. - Run
npm run validate-scriptslocally before opening a PR. - If you touch scripts, remember CI will run the validator and may annotate your PR with the output if validation fails.
Files touched in the PR (helpful reference)โ
.github/workflows/ci.yml.github/workflows/commenter.yml(reusable commenter)package.jsondocs/package.jsonscripts/help.jsdocs/scripts/help.jsscripts/lib/cli-fuzzy.jsscripts/lib/colors.jsscripts/lib/read-packageJson-scripts.jsscripts/validate-scripts.js