npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@jkhong/cli-js

v1.2.0

Published

cli-js allows you to quickly set up a command line interface.

Readme

Purpose

cli-js allows you to quickly set up a command line interface.

Let's say you want to create a command line program (myBoilerplateGenerator) which creates your own boiler plate for:

  • react
  • react native
  • meteor

Provided you have written the code to generate your boiler plates, you can use them this way:

./myBoilerplateGenerator generateReact --projectName myNewReactProject --namespace NRP --useRedux

./myBoilerplateGenerator generateReactNative --projectName myNewReactNativeProject

./myBoilerplateGenerator generateMeteor --projectName myNewMeteorProject --namespace NRP --version 1.6

How to create a minimum cli

create your myBoilerplateGenerator file (no extension)

#!/usr/bin/env node
const CLI = require("@jkhong/cli-js");

try {
    // minimal manual content 
    const manualContent = {
        appName: "Boiler plate generator",
        binName: "myBoilerplateGenerator",
        actionsGroups: []
    };
    const cli = new CLI.Interface();
    cli.setManualContent(manualContent);
    cli.launch();
}
catch (e) {
    console.log(e);
}

make your script executable

chmod +x myBoilerplateGenerator

and run the following commands

# notifies no action is given
./myBoilerplateGenerator

# displays default help menu
./myBoilerplateGenerator help

How to plug your code to the cli

configure the manualContent object

// import your code
const ReactActions = require('./react.js');
const ReactNativeActions = require('./reactNative.js');
const MeteorActions = require('./meteor.js');

// use your code in methods to be plugged to the manual
// the methods get the user input values with the cliOptions object
function ReactPlug(cliOptions){
    ReactActions.genBoilerPlate(
        cliOptions.getSwitchValue("projectName"),
        cliOptions.getSwitchValue("namespace"),
        cliOptions.getSwitchValue("useRedux")
    );
}
function ReactNativePlug(cliOptions){
    ReactNativeActions.genBoilerPlate(
        cliOptions.getSwitchValue("projectName")
    );
}
function MeteorPlug(cliOptions){
    MeteorActions.genBoilerPlate(
        cliOptions.getSwitchValue("projectName"),
        cliOptions.getSwitchValue("namespace"),
        cliOptions.getSwitchValue("version")
    );
}

// build the manual content
const manualContent = {
    appName: "Boiler plate generator",
    binName: "myBoilerplateGenerator",
    actionsGroups: [
        {
            name: "react actions",
            desc: "some cli utils for react projects",
            actions: [{
                name: "generateReact",
                desc: "generate a react boiler plate",
                switches: [
                    {
                        name: "projectName",
                        desc: "the name of the project"
                    },
                    {
                        name: "namespace",
                        desc: "the namespace of the project"
                    },
                    {  // optional switch due to the default value
                        name: "useRedux",
                        desc: "configure for redux",
                        default: {value: false}
                    }
                ],
                action: ReactPlug
            }
            ]
        },
        {
            name: "react native actions",
            desc: "some cli utils for react native projects",
            actions: [{
                name: "generateReactNative",
                desc: "generate a react native boiler plate",
                switches: [
                    {
                        name: "projectName",
                        desc: "the name of the project"
                    }
                ],
                action: ReactNativePlug
            }
            ]
        },
        {
            name: "meteor actions",
            desc: "some cli utils for meteor projects",
            actions: [{
                name: "generateMeteor",
                desc: "generate a meteor boiler plate",
                switches: [
                    {
                        name: "projectName",
                        desc: "the name of the project"
                    },
                    {
                        name: "namespace",
                        desc: "the namespace of the project"
                    },
                    {  // optional switch due to the default value
                        name: "version",
                        desc: "meteor version to use",
                        default: {value: 1.5}
                    }
                ],
                action: MeteorPlug
            }
            ]
        }
    ]
};

Customize your cli

The manual

You can add optional values to the header like a subtitle and the version and add to help an about.

const manualContent = {
    appName: "Boiler plate generator",
    binName: "myBoilerplateGenerator",
    appSubTitle: " the best on the market place",
    appVersion: `v.1.2.3`,
    about: "some descriptive information about your script"
};

If you don't like the way things are displayed, you can inherit the Manual class to redefine your way.

const CLI = require("@jkhong/cli-js");

[...]

class CustomManual extends CLI.Manual {
// methods that can be overriden
    // about(cliOptions) { }
    // getSwitchPrefix() {}
    // printHelp(cliOptions) {}
    // displaySectionHeader(section) {}
    // displayAction(action) {}
}

try {
    const cli = new CLI.Interface();
    cli.setManual(new CustomManual(manualContent));
    cli.launch();
}
catch (e) {
    console.log(e);
}

The cli

You can customize the way cli displays error by inheriting methods

class CustomCli extends CLI.Interface {
// methods that can be overriden
    displayHeader() {
        // display what you want here
    }
    manageException(e) {
        // display what you want here
    }
}