Skip to content
Merged
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
34 changes: 34 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: CI

on:
push:
branches: [main]
pull_request:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: pnpm/action-setup@v4
with:
version: 9.15.1

- uses: actions/setup-node@v4
with:
node-version: 20
cache: pnpm

- run: pnpm install --frozen-lockfile=false

- run: pnpm typecheck
- run: pnpm test
- run: pnpm build

- name: Verify dual output
run: |
test -f dist/index.mjs
test -f dist/index.cjs
test -f dist/index.d.ts
test -f dist/index.d.cts
2 changes: 2 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
strict-peer-dependencies=false
auto-install-peers=true
96 changes: 96 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# clippy

> Modern TypeScript-first CLI builder with first-principles `opts` type inference.

A tiny, dependency-free CLI framework with the same builder ergonomics as
`commander`, but with **typed `opts` baked into the core** — no `extra-typings`
bolt-on, no `as const`, no manual generic plumbing. Just write `.option()` and
your `action((opts) => …)` callback receives a fully-typed `opts` object.

```ts
import { Command } from '@acp-code/clippy';

new Command('serve')
.option('-p, --port <number>', 'port', {
default: 3000,
parser: (v) => Number.parseInt(v, 10),
})
.option('--no-open', 'do not open browser')
.option('-l, --log-level <level>', 'log level', { default: 'info' })
.action((opts) => {
// ^? { port: number; open: boolean; logLevel: string }
})
.parseAsync();
```

## Features

- Zero runtime dependencies
- Dual ESM + CJS output with proper `exports` map and `.d.ts` / `.d.cts`
- Full type inference for `.option()` / `.requiredOption()` / `.argument()`
- Required `<value>` vs optional `[value]` vs variadic `<values...>`
- Negatable `--no-flag` → key without the `no-` prefix
- kebab-case → camelCase key
- Parser return type wins
- `default` removes `undefined` from the value type
- Built-in interactive prompts (`prompt.text`, `prompt.select`, …)

## Installation

```sh
pnpm add @acp-code/clippy
```

## Project layout

```
src/
index.ts # public entrypoint
command.ts # Command builder
types.ts # type-level inference machinery
prompts.ts # readline-based prompts
help.ts # help formatter
tests/
command.test.ts # runtime parsing tests (vitest)
opts-types.test-d.ts # type-level tests for `opts` inference
examples/
demo.ts # runnable demo (pnpm demo)
```

## Scripts

| Command | What it does |
| ----------------- | ----------------------------------------------- |
| `pnpm build` | bundle ESM + CJS + types via `tsup` |
| `pnpm dev` | `tsup --watch` |
| `pnpm demo` | run `examples/demo.ts` via `tsx` |
| `pnpm typecheck` | `tsc --noEmit` |
| `pnpm test` | runtime + type-level tests via `vitest` |
| `pnpm test:types` | only type-level tests (`vitest --typecheck.only`) |
| `pnpm test:watch` | `vitest` watch mode |
| `pnpm clean` | remove `dist/` and `coverage/` |

## Module formats

`exports` is configured for Node + bundlers:

```jsonc
{
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"exports": {
".": {
"import": { "types": "./dist/index.d.mts", "default": "./dist/index.mjs" },
"require": { "types": "./dist/index.d.cts", "default": "./dist/index.cjs" }
}
}
}
```

This means consumers get correct types under both `import` and `require`,
including with `"moduleResolution": "Node16" | "NodeNext" | "Bundler"`.

## License

MIT
63 changes: 63 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"name": "@acp-code/clippy",
"version": "0.0.1",
"description": "Modern TypeScript-first CLI builder with first-principles option type inference.",
"license": "MIT",
"author": "ACP-CODE",
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"exports": {
".": {
"import": {
"types": "./dist/index.d.ts",
"default": "./dist/index.mjs"
},
"require": {
"types": "./dist/index.d.cts",
"default": "./dist/index.cjs"
}
},
"./package.json": "./package.json"
},
"files": [
"dist",
"README.md",
"LICENSE"
],
"sideEffects": false,
"engines": {
"node": ">=18"
},
"packageManager": "pnpm@9.15.1",
"scripts": {
"build": "tsup",
"dev": "tsup --watch",
"demo": "tsx examples/demo.ts",
"clean": "rimraf dist coverage",
"typecheck": "tsc --noEmit",
"test": "vitest run",
"test:watch": "vitest",
"test:types": "vitest run --typecheck.only",
"test:coverage": "vitest run --coverage",
"prepublishOnly": "pnpm run clean && pnpm run build && pnpm run typecheck && pnpm run test"
},
"keywords": [
"cli",
"command-line",
"argv",
"commander",
"typescript",
"type-inference",
"prompts"
],
"devDependencies": {
"@types/node": "^22.10.2",
"rimraf": "^6.0.1",
"tsup": "^8.3.5",
"tsx": "^4.19.2",
"typescript": "^5.7.2",
"vitest": "^2.1.8"
}
}
Loading
Loading