Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pnpm start # Run CLI directly via jiti (no compile step needed)
This is a minimal Node.js library + CLI starter template written in TypeScript targeting Node 24 (ESM).

- **`src/lib.ts`** — The library's public API (currently a Fibonacci sequence generator as a placeholder example).
- **`src/bin.ts`** — CLI entry point built with Commander.js that wraps the library.
- **`src/bin.ts`** — CLI entry point built with CAC that wraps the library.
- **`src/*.test.ts`** — Vitest test files co-located with source.

### Build outputs
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ A minimal [Node.js](https://nodejs.org/en) project template written in [TypeScri

## What's Included

- **TypeScript** library with [ESM](https://nodejs.org/api/esm.html) support and a CLI entry point using [Commander.js](https://github.com/tj/commander.js)
- **TypeScript** library with [ESM](https://nodejs.org/api/esm.html) support and a CLI entry point using [CAC](https://github.com/cacjs/cac)
- **[pnpm](https://pnpm.io/)** as the package manager
- **Formatting** with [Prettier](https://prettier.io/) and **linting** with [ESLint](https://eslint.org/)
- **Testing** with [Vitest](https://vitest.dev/) — 100% code coverage required
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"test": "vitest run"
},
"dependencies": {
"commander": "^14.0.3"
"cac": "^7.0.0"
},
"devDependencies": {
"@eslint/js": "^10.0.1",
Expand Down
18 changes: 9 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 15 additions & 10 deletions src/bin.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
#!/usr/bin/env node

import { program } from "commander";
import cac from "cac";
import { fibonacciSequence } from "./lib.js";

program
.name("my_fibonacci")
.version("0.0.0")
.description("Generate a Fibonacci sequence up to the given number of terms.")
.argument("<n>", "The number of terms", parseInt)
.action((n: number) => {
const sequence = fibonacciSequence(n);
const cli = cac("my_fibonacci");

cli
.command(
"<n>",
"Generate a Fibonacci sequence up to the given number of terms.",
)
.action((n: string) => {
const sequence = fibonacciSequence(parseInt(n));
process.stdout.write(`${sequence.join(" ")}\n`);
})
.parse();
});

cli.version("0.0.0");
cli.help();
cli.parse();
Loading