Giter Club home page Giter Club logo

cli-typescript-boilerplate's Introduction

cli-typescript-boilerplate

A boilerplate for writing CLI tools in TypeScript.

Motivation

I write short self-contained CLI tools quite often, and they all follow a basic structure that I decided to "formalize" in this boilerplate, and minimize the time of setting this up.

TypeScript is also a great workflow improvement (type-safety and autocompletion in the editor are awesome!) but it takes a while to configure if you start from scratch.

Another thing that's not straightforward is how to test interactive CLI. In this boilerplate I give an example of how to test a CLI command using Jest's Snapshot Testing.

Technology (opinionated) choices

The CLI "interface" uses yargs, which provides arguments/options parsing and validation, as well as a convenient separation in sub-commands.

Another library that's showcased (and that I heavily use in real projects) is Inquirer.js, that provides a delightful experience to the users, with rich and interactive prompts that are a pleasure to use.

As mentioned, TypeScript is awesome for speeding up the workflow and catching errors early on in the development phase, especially in the starting phase where many refactors occur. Even if you don't explicitly annotate your functions, you will still get benefits from TS.

Jest is also an amazing tool, which provides a very pleasant testing experience, with almost no configuration. It's snapshot feature has become known for React components, but it's also very appropriate for testing the output of a CLI program.

Finally, linting is done via ESLint (with typescript-eslint-parser for TypeScript support) and prettier runs automatically on git commits, leaving no room for mis-formatted code and bad code practices.

cli-typescript-boilerplate's People

Contributors

gabro avatar rmolinamir avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.