A template for creating CLIs with Typescript, Chalk and Commander
This is a template for creating CLIs with Typescript, Chalk and Commander. It allows you to quickly create a CLI without having to worry about the setup.
(Icon by Smashicons)
To get a local copy up and running follow these simple steps.
Clone the repo (or you can click the "Use this template" button to create a new repo from this template):
git clone https://github.com/JackHumphries9/typescript-cli-template.git
Install NPM packages:
npm i
Run the example command:
npm run build && node ./dist/index.js hello
You should change the name, the name of the binary, version and description of the project in the package.json
file as well as add your name to the author field.
If you want to build your command so you can test it anywhere, run:
npm run build && npm i -g
Then you can run your command anywhere:
$ my_command
Your command is working!
Heres a list of common problems you may encounter when using this template.
If your trying to import another file in the src
directory, you may get an error like this:
Error: Cannot find module '/x/y/z/typescript-cli-template/dist/your_file.ts' imported from /x/y/z/typescript-cli-templatee/dist/index.js
This is because the tsconfig.json
file is set to use the latest version of ES. You have to import your file with the .js
extension:
import { YourFuncs } from "./your_file.js";
If the command your trying to publish already exists on npmjs, you will get an error which states it is the same or similar to an existing package. To fix this, you need to change the name of the binary in the package.json
file. Either use a more abstract name or add a prefix to the name (i.e. @your-npm-username/your_command
). You will also need to change the name of the package in the package.json
file.
See the open issues for a list of proposed features (and known issues).
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the GNU General Public License v3.0 License. See LICENSE
for more information.
Jack Humphries - me@jackhumphries.io
Project Link: https://github.com/JackHumphries9/typescript-cli-template