docfy generate
Scans your project and generates a pre-filled *.controller.docs.ts for each controller, static analysis only, no project code is executed.
Usage
bash
npx nestjs-docfy generate [options]Options
| Option | Default | Description |
|---|---|---|
--root <path> | . | Project root directory |
--tsconfig <path> | auto-detected | Path to tsconfig.json |
--pattern <glob> | **/*.controller.ts | Glob pattern to find controllers |
--out <path> | alongside each controller | Output directory for generated files |
--force | false | Merge new methods into existing docs files (preserves user edits) |
--dry-run | false | Print what would be generated without writing files |
--quiet | false | Suppress all output except errors (CI-friendly) |
--format | ts | Output format: ts or js |
Project types
The CLI auto-detects your project's layout, no configuration needed:
| Layout | Detected when |
|---|---|
| Simple project | tsconfig.json at root, no monorepo markers |
| Nx monorepo | nx.json present |
| Nest CLI monorepo | nest-cli.json with "monorepo": true |
| Generic monorepo | packages/ or apps/ with sub-package.json files |
Idempotency and --force
| Scenario | Behavior |
|---|---|
Run generate on a clean project | Creates all docs files |
Run generate again (no changes) | Skips all existing files, safe to run repeatedly |
Add a new endpoint, run generate --force | Merges new method block, preserves existing arrays |
Edit a method's decorators, run --force | Your edits are preserved |
npm script
Add to your package.json for convenience:
json
{
"scripts": {
"docs:generate": "nestjs-docfy generate",
"docs:preview": "nestjs-docfy generate --dry-run"
}
}