name, description
| name |
description |
| cli-tool |
Node.js CLI tool template principles. Commander.js, interactive prompts. |
CLI Tool Template
Tech Stack
| Component |
Technology |
| Runtime |
Node.js 20+ |
| Language |
TypeScript |
| CLI Framework |
Commander.js |
| Prompts |
Inquirer.js |
| Output |
chalk + ora |
| Config |
cosmiconfig |
Directory Structure
CLI Design Principles
| Principle |
Description |
| Subcommands |
Group related actions |
| Options |
Flags with defaults |
| Interactive |
Prompts when needed |
| Non-interactive |
Support --yes flags |
Key Components
| Component |
Purpose |
| Commander |
Command parsing |
| Inquirer |
Interactive prompts |
| Chalk |
Colored output |
| Ora |
Spinners/loading |
| Cosmiconfig |
Config file discovery |
Setup Steps
- Create project directory
npm init -y
- Install deps:
npm install commander @inquirer/prompts chalk ora cosmiconfig
- Configure bin in package.json
npm link for local testing
Publishing
Best Practices
- Provide helpful error messages
- Support both interactive and non-interactive modes
- Use consistent output styling
- Validate inputs with Zod
- Exit with proper codes (0 success, 1 error)