An all-inclusive starter kit for crafting command-line interfaces (CLI) using TypeScript, driven by Node.js. This kit is meticulously designed to kick-start your development journey with a solid foundation, encompassing features such as argument parsing, environment setup, logging, testing suites, as well as code formatting and linting capabilities.
This template incorporates several key tools and libraries to enhance your CLI development experience:
- Yargs: A powerful library for parsing command-line arguments.
- Dotenv: Loads environment variables from a
.envfile intoprocess.env, making it easy to manage application configuration. - PicoColors: Lightweight and fast library for styling terminal text.
- Consola: 🐨Elegant Console Logger for Node.js and Browser
- Jest: A delightful JavaScript Testing Framework with a focus on simplicity.
- TS-Node: TypeScript execution and REPL for Node.js.
- TSUP: The simplest and fastest way to bundle your TypeScript libraries.
- Oxlint: Ultra-fast linter for JavaScript and TypeScript (~30x faster than ESLint).
- Oxfmt: High-performance code formatter with Prettier compatibility.
- jscpd: Copy/paste detector for code duplication detection.
- giget: ✨ Download templates and git repositories with pleasure!
- Dependabot: Automated dependency updates via GitHub.
Before you begin, ensure you have installed Node.js and pnpm on your system.
To start using this CLI TypeScript starter, follow these steps:
npx cli-typescript-starter create my-projector
npx giget@latest gh:kucherenko/cli-typescript-starter my-projector
pnpm exec degit kucherenko/cli-typescript-starter my-projectNavigate to your project directory and install the necessary dependencies:
cd my-project && pnpm installUpdate the package.json to reflect your project's details:
- Rename the package:
"name": "my-project",
- Set the command name:
"bin": { "my-project": "./bin/run" }
Create a .env file in the root directory and configure your environment variables as needed.
This starter comes equipped with several predefined scripts to facilitate development, alongside sample commands to demonstrate the capabilities of the CLI application.
- In development mode, use
pnpm start [command name]to run any command. This utilizests-nodefor a seamless development experience. - In production, execute the CLI application directly with
my-project [command name]to run the desired command from the built project (the name of command should be provided inpackage.jsoninbin).
info: Prints information about the current system and Node.js configuration. This command is useful for verifying the environment in which the CLI is running.greeting: Demonstrates interactive prompts within the CLI. It's a great way to see how user inputs can be handled in a friendly manner.create: Create new project based oncli-typescript-starter.
All commands are located in the src/commands/ folder. This organization makes it easy to find and modify commands or
add new ones as needed.
This starter comes with several predefined scripts to help with development:
pnpm build- Build the project usingtsup.pnpm build:watch- Automatically rebuild the project on file changes.pnpm commit- runcommitizentool for helping with commit messages.pnpm commitlint- lint commit messages.pnpm compile- Compile TypeScript files usingtsc.pnpm clean- Remove compiled code from thedist/directory.pnpm format- Check files for code style issues using Oxfmt.pnpm format:fix- Automatically fix code formatting issues with Oxfmt.pnpm lint- Check code for style issues with Oxlint.pnpm lint:fix- Format code with Oxfmt and check with Oxlint.pnpm cpd- Check for code duplication using jscpd.pnpm start [command]- Run the CLI application usingts-node.pnpm start:node [command]- Run the CLI application from thedist/directory.pnpm test- Run unit tests.pnpm test:watch- Run tests and watch for file changes.
This project uses GitHub Dependabot to automatically keep dependencies up to date. Dependabot creates pull requests weekly to update npm dependencies, ensuring the project stays current with the latest security patches and features.
The Dependabot configuration (.github/dependabot.yml) is set to:
- Check for npm package updates weekly
- Create up to 10 pull requests at a time
- Automatically open PRs for security updates
This project utilizes semantic-release to automate version management and the NPM publishing
process. Semantic-release automates the workflow of releasing new versions, including the generation of detailed
release notes based on commit messages that follow the conventional commit format.
The publishing process is triggered automatically when changes are merged into the main branch. Here's how it works:
- Automated Versioning: Based on the commit messages,
semantic-releasedetermines the type of version change ( major, minor, or patch) and updates the version accordingly. - Release Notes: It then generates comprehensive release notes detailing new features, bug fixes, and any breaking changes, enhancing clarity and communication with users.
- NPM Publishing: Finally,
semantic-releasepublishes the new version to the NPM registry and creates a GitHub release with the generated notes.
To ensure a smooth semantic-release process:
- Merge feature or fix branches into the main branch following thorough review and testing.
- Use conventional commit messages to help
semantic-releaseaccurately determine version changes and generate meaningful release notes. - Configure an NPM access token as a GitHub secret under the name
NPM_TOKENfor authentication during the publication process.
By integrating semantic-release, this project streamlines its release process, ensuring that versions are managed
efficiently and that users are well-informed of each update through automatically generated release notes.
To contribute to this project or customize it for your needs, consider the following guidelines:
- Code Styling: Follow the predefined code style, using Oxfmt for formatting and Oxlint for linting, to ensure consistency.
- Commit Messages: We use
commitizenandcommitlintto ensure our commit messages are consistent and follow the conventional commit format, recommended by@commitlint/config-conventional. To make a commit, you can runpnpm commit, which will guide you through creating a conventional commit message. - Testing: Write unit tests for new features or bug fixes using Jest. Make sure to run tests before pushing any changes.
- Environment Variables: Use the
.envfile for local development. For production, ensure you configure the environment variables in your deployment environment. - Husky Git Hooks: This project utilizes Husky to automate formatting, linting, code duplication checks, testing,
and commit message verification via git hooks. This ensures that code commits meet our quality and style standards
without manual checks. The pre-commit hook runs Oxfmt, Oxlint, jscpd, tests, and build verification. The commit-msg
hook validates commit messages with
commitlint.
Contributions are welcome! If you'd like to improve this CLI TypeScript starter, please follow the standard fork-and-pull request workflow. Here are a few guidelines to keep in mind:
- Make sure your code adheres to the project's coding standards, including using Oxfmt for code formatting and Oxlint for linting.
- Follow the conventional commit format for your commit messages. This project uses
commitizenandcommitlintwith the@commitlint/config-conventionalconfiguration, enforced by Husky git hooks. - Include tests for new features or bug fixes when applicable.
- Ensure your changes are properly formatted and linted before submitting a pull request.
By adhering to these guidelines, you help maintain the quality and consistency of the project, making it easier for others to contribute and for users to understand and utilize the project effectively.
This project is licensed under the MIT License - see the LICENSE file for details.
Andrey Kucherenko
- GitHub: @kucherenko
Happy Coding!