4.5 KiB
4.5 KiB
name, description
| name | description |
|---|---|
| node-ts-cli | Generate new Node.js CLI tool projects using TypeScript with ESM modules, tsc for building, tsx for development, Biome for linting/formatting, and Node's built-in test runner. Use this skill when the user requests to create a new Node TypeScript CLI project or CLI tool. |
Node TypeScript CLI Generator
Overview
Generate production-ready Node.js CLI tool projects configured with TypeScript, ESM modules, and modern tooling. Each generated project includes a complete setup with build scripts, development workflow, testing, and linting.
When to Use This Skill
Use this skill when the user requests:
- "Create a new Node TypeScript CLI tool"
- "Generate a CLI project in TypeScript"
- "Set up a new TypeScript CLI"
- "Make me a Node.js command-line tool"
Project Setup
Quick Start
To generate a new CLI project:
- Specify the project name and desired CLI command name.
- The skill will create a new directory unless specified otherwise.
- Inside the directory, the skill will perform the following steps:
- Initialize a new Git repository.
- Run
npm init -yto initialize a new npm project. - Run
npm i -D typescript @types/node @biomejs/biometo install dev dependencies. - Run
npm i @clack/promptsto install runtime dependencies. - Run
npx tsc --initto create atsconfig.jsonfile. - Run
npx biome initto create abiome.jsonfile. - Set up the
package.json,tsconfig.json, andbiome.jsonfiles with the appropriate configurations. - Create the necessary source files in
src/includingindex.tswith a basic CLI structure using the@clack/promptslibrary. - Create example test files in
src/to demonstrate testing with Node's built-in test runner. - Add npm scripts for building, developing, testing, linting, and formatting.
- Inform the user about the available npm scripts
Technology Stack
The generated project uses:
- TypeScript with strict mode enabled
- ESM modules (type: "module")
- tsc for building production builds to
./dist - tsx for running TypeScript directly in development
- Biome for fast linting and formatting
- Node's built-in test runner with TypeScript support via
--experimental-strip-types
Available NPM Scripts
Each generated project includes these scripts:
npm run build- Compile TypeScript to JavaScript in./distnpm run dev- Run the CLI in development mode with tsxnpm run test- Run tests with Node's built-in test runnernpm run lint- Check code with Biomenpm run lint:fix- Fix linting issues automaticallynpm run format- Format code with Biome
Project Configuration
package.json
- Configured as ESM with
"type": "module" - Includes
binfield for CLI installation - Main entry points to
./dist/index.js
tsconfig.json
- Target: ES2022
- Module: ESNext with bundler resolution
- Outputs to
./dist, sources from./src - Strict mode enabled
- Generates declaration files and source maps
biome.json
- Enables linting with recommended rules
- Configured to format code on save
CLI Entry Point Structure
The template src/index.ts includes:
- Shebang for executable scripts (
#!/usr/bin/env node) - Argument parsing with help and version flags for non-interactive use
- Interactive prompts using
@clack/prompts - Async main function with error handling
- Process exit codes for proper CLI behavior
Customization After Generation
After generating a project, users should:
- Update
nameanddescriptioninpackage.json - Update the
bincommand name inpackage.json - Set the
authorandlicensefields - Update version number in both
package.jsonandsrc/index.tsshowVersion() - Modify
src/index.tswith their CLI logic - Update the README with specific usage instructions
Installation for Users
After building the project, users can:
- Run locally:
node dist/index.js - Install globally:
npm install -g .then use the bin command - Publish to npm and install:
npm install -g package-name
Example Usage
When a user says: "Create a new TypeScript CLI tool called todo-manager"
- Run the project generation steps outlined above
- Update
package.json:- Change
"name"to"todo-manager" - Update
"description"appropriately - Change
binto"todo-manager": "./dist/index.js"
- Change
- Update README.md with the project name
- Run
npm installin the project directory - Inform the user: "Project created! Run
npm run devto start developing, ornpm run buildto compile."