CLI Reference
Quick Reference
All CLI commands and options in one place.
Common Commands
Generate Single Builder
bash
# Basic
npx fluent-gen-ts generate ./src/types.ts User
# With output directory
npx fluent-gen-ts generate ./src/types.ts User -o ./src/builders/
# All options
npx fluent-gen-ts generate ./src/types.ts User \
--output ./src/builders/ \
--tsconfig ./tsconfig.build.json \
--defaults \
--no-commentsBatch Generation
bash
# Use default config (fluentgen.config.js)
npx fluent-gen-ts batch
# Custom config file
npx fluent-gen-ts batch --config custom.config.js
# Dry run (preview only)
npx fluent-gen-ts batch --dry-run
# Run in parallel
npx fluent-gen-ts batch --parallelInteractive Setup
bash
# Create config interactively
npx fluent-gen-ts init
# Overwrite existing config
npx fluent-gen-ts init --overwriteScan for Types
bash
# Scan files
npx fluent-gen-ts scan "src/**/*.ts"
# Ignore non-exported types
npx fluent-gen-ts scan "src/**/*.ts" --ignore-private
# Filter specific types
npx fluent-gen-ts scan "src/**/*.ts" --types User,Product,Order
# Interactive selection mode
npx fluent-gen-ts scan "src/**/*.ts" --interactiveSetup Common File
bash
# Create common.ts
npx fluent-gen-ts setup-common
# Custom output path
npx fluent-gen-ts setup-common --output ./src/builders/common.ts
# Overwrite existing
npx fluent-gen-ts setup-common --overwriteCommand Reference Table
| Command | Purpose | Quick Example |
|---|---|---|
generate | Single builder | fluent-gen-ts generate file.ts Type |
batch | Multiple builders | fluent-gen-ts batch |
init | Interactive setup | fluent-gen-ts init |
scan | List types | fluent-gen-ts scan "src/**/*.ts" |
setup-common | Create common file | fluent-gen-ts setup-common |
Option Reference
Global Options
bash
-h, --help # Show help
-V, --version # Show versiongenerate Options
bash
<file> # TypeScript file path (required)
<type> # Type name to generate (required)
-o, --output <path> # Output file path
-c, --config <path> # Path to configuration file
-t, --tsconfig <path> # Path to tsconfig.json
-p, --plugins <paths...> # Path(s) to plugin files
-d, --defaults # Use default values for optional properties
--dry-run # Preview without writing files
--no-comments # Don't include JSDoc commentsbatch Options
bash
-c, --config <path> # Config file path (default: fluentgen.config.js)
-p, --plugins <paths...> # Path(s) to plugin files
-d, --dry-run # Dry run without writing files
--parallel # Generate builders in parallelinit Options
bash
--overwrite # Overwrite existing configurationscan Options
bash
<pattern> # Glob pattern (required)
-o, --output <pattern> # Output file pattern (use {file} and {type} placeholders)
-c, --config <path> # Path to configuration file
-p, --plugins <paths...> # Path(s) to plugin files
-e, --exclude <patterns...> # Patterns to exclude from scanning
-t, --types <types> # Comma-separated list of type names to include
-i, --interactive # Interactive mode to select types
--dry-run # Preview discovered types without generating
--ignore-private # Ignore non-exported interfacessetup-common Options
bash
-o, --output <path> # Output path (default: ./common.ts)
--overwrite # Overwrite existing fileCommon Workflows
Development Workflow
bash
# 1. Setup
npx fluent-gen-ts init
# 2. Generate once
npx fluent-gen-ts batch
# 3. Add to package.json
npm pkg set scripts.generate="fluent-gen-ts batch"
# 4. Use in development
npm run generateTest Data Generation
bash
# Scan to see available types
npx fluent-gen-ts scan "src/**/*.ts"
# Generate builders for testing
npx fluent-gen-ts batch --config test.config.js
# Run tests
npm testCI/CD Pipeline
bash
# Install
npm install
# Generate builders
npx fluent-gen-ts batch
# Type check
npx tsc --noEmit
# Test
npm test
# Build
npm run buildEnvironment Variables
Environment variables are not currently supported by the CLI. Use configuration files or command-line flags instead.
Exit Codes
| Code | Meaning | Action |
|---|---|---|
0 | Success | Continue |
1 | General error | Check error message |
2 | Invalid arguments | Check command syntax |
3 | File not found | Verify file path |
4 | Type not found | Check type name/export |
5 | Config error | Validate config file |
Quick Debugging
See What Will Be Generated
bash
# Dry run to preview
npx fluent-gen-ts batch --dry-runCheck Available Types
bash
# List all types in a file
npx fluent-gen-ts scan "./src/types.ts"
# List exported types only
npx fluent-gen-ts scan "./src/types.ts" --ignore-privateVerify Config
bash
# Use Node to validate
node -e "console.log(require('./fluentgen.config.js'))"Integration Examples
package.json Scripts
json
{
"scripts": {
"generate": "fluent-gen-ts batch",
"generate:watch": "chokidar 'src/types/**/*.ts' -c 'npm run generate'",
"generate:dev": "fluent-gen-ts batch --config dev.config.js",
"generate:prod": "fluent-gen-ts batch --config prod.config.js",
"prebuild": "npm run generate",
"pretest": "npm run generate"
}
}Git Hooks (Husky)
bash
# .husky/pre-commit
#!/bin/sh
npm run generate
git add src/buildersGitHub Actions
yaml
# .github/workflows/ci.yml
- name: Generate builders
run: npx fluent-gen-ts batch
- name: Check for changes
run: |
git diff --exit-code src/builders || \
(echo "Builders out of sync!" && exit 1)Docker
dockerfile
# Dockerfile
FROM node:18
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
# Generate builders
RUN npx fluent-gen-ts batch
CMD ["npm", "start"]Tips & Tricks
Alias for Faster Access
bash
# Add to ~/.bashrc or ~/.zshrc
alias fgen="npx fluent-gen-ts"
# Usage
fgen batch
fgen generate ./src/types.ts UserAutomatic Regeneration
bash
# Install nodemon
npm install -D nodemon
# Add to package.json
{
"scripts": {
"dev": "nodemon --watch src/types --exec 'npm run generate && npm start'"
}
}Batch Generate Multiple Configs
bash
# generate-all.sh
#!/bin/bash
configs=("config1.js" "config2.js" "config3.js")
for config in "${configs[@]}"; do
echo "Generating with $config..."
npx fluent-gen-ts batch --config $config
doneCommon Patterns
Generate on File Change
bash
# Using watchman
watchman-make -p 'src/types/**/*.ts' -t generate
# Using chokidar
npx chokidar 'src/types/**/*.ts' -c 'npx fluent-gen-ts batch'
# Using nodemon
npx nodemon --watch src/types --exec 'npx fluent-gen-ts batch'Conditional Generation
bash
# Only in development
if [ "$NODE_ENV" != "production" ]; then
npx fluent-gen-ts batch
fi
# Only if types changed
if git diff --quiet src/types; then
echo "No type changes, skipping generation"
else
npx fluent-gen-ts batch
fiParallel Generation (Monorepo)
bash
# Using GNU parallel
find packages -name 'fluentgen.config.js' -execdir npx fluent-gen-ts batch \;
# Using npm workspaces
npm run generate --workspacesKeyboard Shortcuts (Interactive Mode)
When using fluent-gen-ts init:
| Key | Action |
|---|---|
↑ ↓ | Navigate options |
Space | Select/deselect |
Enter | Confirm selection |
a | Select all |
i | Invert selection |
Ctrl+C | Cancel |
Quick Reference by Task
"I want to..."
| Task | Command |
|---|---|
| Generate one builder | fluent-gen-ts generate file.ts Type |
| Generate all configured builders | fluent-gen-ts batch |
| Set up config interactively | fluent-gen-ts init |
| See what types exist | fluent-gen-ts scan "src/**/*.ts" |
| Preview without generating | fluent-gen-ts batch --dry-run |
| Run generation in parallel | fluent-gen-ts batch --parallel |
| Create common utilities | fluent-gen-ts setup-common |
| Use custom config | fluent-gen-ts batch -c custom.config.js |
Related Resources
- Configuration - All configuration options
- Workflows - Integration patterns
- Troubleshooting - Common issues
- Getting Started - Quick start guide