Skip to content

A Typescript CLI Template to quickly create command line tools with Typescript

Notifications You must be signed in to change notification settings

JackHumphries9/typescript-cli-template

Repository files navigation


Logo

Typescript CLI Template

A template for creating CLIs with Typescript, Chalk and Commander

Table of Contents

About The Project

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)

Built With

Getting Started

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!

Common Problems

Heres a list of common problems you may encounter when using this template.

Importing files

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";

Publishing to NPM

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.

Roadmap

See the open issues for a list of proposed features (and known issues).

Contributing

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.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the GNU General Public License v3.0 License. See LICENSE for more information.

Contact

Jack Humphries - me@jackhumphries.io

Project Link: https://github.com/JackHumphries9/typescript-cli-template

About

A Typescript CLI Template to quickly create command line tools with Typescript

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published