How To Publish A Command-Line Tool To NPM

October 12, 2022 Annika Pastrana

How To Publish A Command-Line Tool To NPM

The Command-Line Interface, or otherwise referred to as CLI, is a common way for developers to interact with different processes. CLI tools are often used in software development, DevOps, or even application structure. Overall, the command-line provides a more streamlined developer experience as well as automation tools for routine maintenance.

NPM, on the other hand, is the world’s largest software registry. The registry contains over one million code packages, supporting open-source developers in their mission to not only share software, but provide an accessible playing field for the management of private development projects.

With NPM supporting command-line tools, developers are given the opportunity to expedite collaboration amongst teammates.

Popular Libraries

Yargs and Commander.js are two of the most popular libraries used for parsing user input. While both have their own collection of pros and cons per developer style, the primary difference between them is:

Yargs

  • Uses types to check for invalid user inputs

Commander.js

  • Routes commands to functions, in order to clean up code

With Yargs and Commander.js leading the charge, there are a number of sub-libraries that provide interactive user-experiences to your application.

Inquirer

  • Provides real-time error feedback
  • Prompts user identity verification questions and validates the answers
  • Manages hierarchical prompts

Yargs-Interactive

  • Based on inquirer
  • Supports mixed mode, in which a user doesn’t need a direct prompt for all navigation options

Chalk

  • Changes color of terminal output
  • Intuitively bolds, dims, and underlines text
  • Creates reusable style code

Ora

jasmine-spec-builder

A jasmine-spec-builder is a command-line tool to build and update jasmine spec files. It allows you to build a spec folder from scratch and/or update an existing file’s providers. It provides developers the option to utilize a MasterServiceStub to initialize service stubs before each unit test. Overall, giving the developer the opportunity to automate tests for both synchronous and asynchronous code.

jasmine-spec-builder has a number of features, including:

  • Speed and low overhead with no external dependencies
  • An all inclusive library that offers everything needed to test code pre-development
  • Availability for both Node and browser
  • Use with other languages like Python and Ruby
  • Does not require the DOM
  • Providing a clean and easy to understand syntax and a rich, straightforward API
  • Using natural language to describe the tests and the expected results

Building Complex Packages

The common requirements for developers looking to run more complex tests with the command-line for their NPM packages are:

  • Running tests before every publish
  • Consistently updating versions using semantic versioning
  • Creating a git tag using semantic versioning
  • Pushing the package to Github or NPM
  • Creating manual release notes for the update

Live Demonstrations

You’ve unpacked quite a few introductory principles to the publishing of command-line tools to NPM…But the best way to learn is through practical and tangible demonstration.

William Kimak has crafted an intuitive demonstration to help guide you through these principles in practicum:

Be sure to follow Kimak’s entire Lightning Talk to view this impressive demonstration in real time.

Closing Thoughts

Publishing Command-Line Tools To NPM has given developers the ability to expedite their team’s backend processes. Overall, bringing more power and innovation to your “coder’s toolbox!” The properties explored above are the primary stepping stones to experimenting with the primary knowledge needed to test how publishing command-line tools to NPM can help streamline processes for your current (or future!) development portfolio. Be sure to explore, have fun, and match up the components that work best for your project!

Happy coding!

To learn more about Publishing Command-Line Tools To NPM, along with some live test samples, and to experience William Kimak’s full Lightning Talk session, watch here.

Let's Work Together

InRhythm drives AI-driven digital transformation and platform modernization for Fortune 500 companies in wealth & asset management, payments, and enterprise retail sectors. Our expert team delivers innovative solutions to accelerate technology adoption and improve time to market.

© 2024 InRhythm all rights reserved.

195 Broadway
Suite 2400, Floor 24
New York, NY 10007



ge*@in******.com











1 800 683 7813

© 2024 InRhythm all rights reserved.

contact-section