Libraries to build a strong and beautiful CLI tool with Javascript

Walter Reyes
Sudo by Icalia Labs
4 min readOct 28, 2017

Recently I started an Open Source Contributing journey, there are tons of benefits to do it but I have two main motivations:

  1. Add my 2 cents to try to make the coding community a better place.
  2. To become the best Developer I can be by learning how better developers build their projects and receiving code reviews from them.

I think this article explains very well more benefits of Open Source.

A couple of weeks ago I decided to jump into one of the libraries I am using in a project and solve an issue:

The library is redux-cli, which is a CLI tool to generate boilerplate code to build redux/react apps quicker. Which can save you a lot of time if you find yourself copy and pasting the same boilerplate code for your components/reducers/actions/etc.and their specs.

So I decided to tackle a new feature which they have marked as good first contribution.

I made a PR after digging into the code, looking how everything was wired up, how they built it and trying to solve the issue I signed up for.

And in the process I learnt cool things about building CLI tools. Especially I gathered a set of libraries that helps you build a strong, confident and beautiful CLI tool with javascript.

So, if you are planning to build one these libraries could aid you in your journey:

Yargs — http://yargs.js.org/

A very useful library to build a CLI tool.

I think they can explain what they do better than I could:

Yargs helps you build interactive command line tools by parsing arguments and generating an elegant user interface.

They also have a sense of humor and cool identity.

If you are planning to build a CLI go ahead and read trough their documentation.

Ora — https://github.com/sindresorhus/ora

Ora is an elegant terminal spinner. It’s worth using if you want your CLI to feel fresh.

Chalk — https://github.com/chalk/chalk

Terminal string styling done right.

Simple, but It’s great if you plan to display info, warning, error, success messages.

Figlet — https://github.com/patorjk/figlet.js

I love this one.

This library let’s you display big text using ASCII symbols in the terminal, it works well in the browser too.

Prettyjson — https://github.com/rafeca/prettyjson

Package for formatting JSON data in a coloured YAML-style, perfect for CLI output.

rc — https://github.com/dominictarr/rc

If you CLI will have some configuration file (e.g. .appnamerc) this library will help you load that configuration easily.

It’s super cool.

Prompt — https://github.com/flatiron/prompt

A beautiful command-line prompt for node.js

If you need to ask your user for data this is your best choice.

Jsonfile — https://github.com/jprichardson/node-jsonfile

Easily read/write JSON files.

Why?

Writing JSON.stringify() and then fs.writeFile() and JSON.parse() with fs.readFile() enclosed in try/catchblocks became annoying.

Summary

Before I started trying to contribute to redux-cli I knew very little about building a CLI tool with javascript. But now I know a collection of libraries that could help me build one.

Because when I use a CLI tool with these features, it just feels confident and well made.

And this was also a very good example that through Open Source we don’t have to reinvent the wheel for every little thing. It just feels good that we support each other in this community.

Feel free to share any other library you know of. Also, please recommend (❤) this post if you think this may be useful for someone.

Tweet/follow me @walreyes11.

--

--