Reusable strict TypeScript CLI template for npm packages.
- Node 25 + npm + ESM TypeScript setup.
- Strict lint/typecheck/duplication/unused checks.
- Commander-based CLI parsing with native help and version flags.
- Shared Zod option contracts with inferred handler types.
- Path-based command definitions supporting one-level and two-level layouts.
- Starter commands:
helloandproject version.
- Node.js 25 or newer
- npm
Install dependencies:
npm installcommand-template hello [--name <name>]
command-template project version
command-template --versionExamples:
command-template hello
command-template hello --name Ada
command-template project versionnpm test
make lint-dry
make lint- Add
src/commands/<name>.ts. - Export a command definition using
defineCommand(...). - Register it in
src/command-dispatch.ts. - Add command tests under
tests/. - Update command usage in this README and
docs/api-reference.md.
Command definitions use path segments:
- One-level command:
path: ["publish"] - Two-level command:
path: ["project", "publish"]
Options are parsed by Commander and validated by Zod in optionsSchema.
- Human-first output: commands print short sentence-style text.
- Global flags:
--helpand--version. - Parse and validation failures map to usage errors (
exitCode=2). - Command runtime failures map to runtime errors (
exitCode=1).
Use one-level commands when verbs are distinct and few. Use two-level commands when grouping improves discoverability (user, project, release).
When cloning or generating a new package from this template, update:
package.json:namedescriptionbincommand key and path
bin/command-template.tsfilename (if command name changes).src/command-dispatch.ts:- top-level CLI title
- usage strings
- README examples and docs command names.
- tests that assert command names/output.
docs/api-reference.md