A starter kit generator for CLI applications. This tool helps you quickly scaffold a new command-line interface application with all the necessary configurations.
- 📂 Generates a complete CLI application structure
- 🧪 Sets up testing with Jest
- 🔍 Configures ESLint for code quality
- 🔄 Initializes Git repository
- 🛠️ Sets up Command parsing with Commander.js
- 💬 User input handling with Inquirer
# Install globally
npm install -g create-cli-template
# Or use directly with npx
npx create-cli-template my-cli-app
# For development
git clone <repository-url>
cd create-cli-template
npm install
npm link
# Create a new CLI application with interactive prompts
create-cli-template my-cli-app
# Skip prompts and use defaults
create-cli-template my-cli-app --yes
# Skip git initialization
create-cli-template my-cli-app --no-git
# Skip dependency installation
create-cli-template my-cli-app --no-install
[name]
- Project directory/package name (optional)-y, --yes
- Skip all prompts and use defaults--no-git
- Skip git initialization--no-install
- Skip dependency installation
When creating a new CLI application, you'll be asked for:
- Package/directory name: The npm package name and directory name (lowercase with hyphens)
- Human-readable title: A prettier title for display in README and CLI output
- Project description: A brief description of what your CLI does
- Author: Your name (defaults to Git config)
- License: The license to use (MIT, ISC, Apache-2.0, GPL-3.0)
my-cli-app/
├── bin/
│ └── index.mjs # CLI entry point
├── src/
│ ├── index.mjs # Main module exports
│ └── index.test.js # Tests for main module
├── tests/
│ └── index.test.mjs # Additional tests
├── .gitignore
├── eslint.config.mjs
├── jest.config.mjs
├── package.json
└── README.md
This project uses a sophisticated approach to testing interactive CLI applications:
The core of our testing framework is a timing-based approach that reliably interacts with CLI prompts:
function testCLITiming({ command, args, inputs, cwd, timeout, debug }) {
// Spawn the process
// Send inputs with fixed timing
// Collect and verify output
}
Key advantages:
- More reliable than prompt detection methods
- Works with complex, nested prompts
- Simpler to maintain and extend
- Handles ANSI color codes and formatting
We've organized tests into different suites to cover all aspects of CLI functionality:
- Basic Functionality: Tests that the CLI generator works correctly
- Error Handling: Verifies the CLI responds gracefully to invalid inputs
- Scaffolded Features: Tests the CLI applications created by the generator
- End-to-End: Tests the full workflow from generation to usage
Tests can be run individually or all at once:
# Run all tests
npm test
# Run specific test suites
npm run test:timing # Run timing-based CLI tests
npm run test:errors # Run error handling tests
npm run test:features # Run scaffolded CLI feature tests
npm run test:all # Run all test suites
To add new tests for CLI functionality:
- Use the
testCLITiming
function in your test files - Define the command to run and input sequence
- Verify the output matches expectations
Example:
test('Create CLI application with custom inputs', async () => {
const inputs = [
'my-app', // Project name
'My Application', // Title
'A test app', // Description
'Test Author', // Author
'', // License (default)
];
const result = await testCLITiming({
command: 'node',
args: [path.join(rootDir, 'bin/index.js')],
inputs,
cwd: tempDir,
timeout: 30000,
debug: false
});
expect(result.code).toBe(0);
expect(result.stdout).toContain('created successfully');
});
# Clone this repository
git clone <repository-url>
cd create-cli-template
# Install dependencies
npm install
# Link the package locally for testing
npm link
# Run the CLI
create-cli-template test-app
# Run tests
npm test
# Run specific test suites
npm run test:timing
npm run test:errors
npm run test:features
npm run test:all
# Run linting
npm run lint
MIT © Richard Gaunt