ata.soy

How to Make CLI Tools in TypeScript with Komutan

5 min readAta Atasoy
CLI Tools Development in TypeScript

TL;DR: Learn how to create, develop, test, and publish CLI tools in TypeScript using Komutan. This toolkit streamlines the entire process of building command-line applications with modern tooling and best practices.

Introduction

I was playing with CLI tools and thought it would be cool to make one and publish. While I was searching for tech to use, I saw Cobra and cobra-cli in Go which is absolutely perfect. After playing with it for some time, I decided to make CLI tools also in TypeScript, but I had a hard time finding good resources, so here we are with Komutan.

What is Komutan?

Komutan is a CLI toolkit built on top of Commander.js that streamlines the process of creating, developing, testing, and publishing CLI apps.

Getting Started

Make sure that you have Node.js and npm on your system, and after that, you can just install Komutan with a simple command:

npx komutan

Tutorial: Building a Welcome CLI Tool

In this tutorial, let's create a simple CLI tool that welcomes a given name. Let's create a new directory:

mkdir welcome
cd welcome

After making sure that you are in the welcome directory, run the komutan init <name> command:

npx komutan init welcome

This will scaffold your CLI app. You can see the project tree in the GitHub repository.

Project structure after komutan init

Now let's test our CLI:

npx komutan test # you may need to add sudo
welcome
Testing the CLI tool

By default, you will have a hello command. Let's try that:

Running the hello command

Perfect! Everything is working. Now let's add a welcome command and modify it.

You can add a new command by using the komutan add <name> command:

npx komutan add welcome
Adding a new welcome command
Generated welcome command file

Now let's make it so it accepts a name:

Modifying the welcome command to accept a name

Run the test command again:

Testing the modified CLI

And now use it:

Using the welcome command with a name

Here it is! Everything is working fine.

Now for the last step, you will probably want to publish your CLI, and it's as easy as running:

npx komutan publish # you may need to use sudo

Conclusion

Done! You now know how to ship CLI apps like crazy. Komutan makes it incredibly easy to create, develop, test, and publish CLI tools in TypeScript with minimal setup and configuration.

Key Takeaways

  • Komutan Streamlines Development: From scaffolding to publishing, everything is handled with simple commands
  • TypeScript + Commander.js: Built on proven technologies for robust CLI development
  • Easy Command Management: Add new commands with a single command and focus on functionality
  • One-Click Publishing: Publish your CLI tools to npm with minimal configuration

Learn More

If you want to dive deeper into CLI development and TypeScript:

Have questions or feedback? Feel free to email me or connect with me on LinkedIn.