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 🙏

© 2024 – Pkg Stats / Ryan Hefner

split-command

v0.0.7

Published

a framework for write separable command line application

Downloads

8

Readme

SplitCommand

a framework for write split command line application

Background

As your Node command line application became more functional day by day, the size of the application, the dependence number of npm package both
endure inevitable expansion. The situation make your application hard to install.

When intruduce new Node command line application to user, we wish that our application can be installed as soon as possible. In some of case, easy to install and easy to use is more critical then powerful.

SplitCommand try to solve this dilemma.

If your Node command line application is versatile, we encourage you to ship the application as multi-part. At first just let user install a small but crucial core application. The core application don't need to declare dependence of every sub command explicitly in package.json, this means some part of your application don't need downloaded at the time main application is installed. With the help of SplitCommand some sub commands you specified can be installed when they be used first time.

Usage

Step.1 package.json configuration

In the package.json file of your core application, add a "splitCommands" section like following example. The "splitCommands" section should as top layer property of the package.json file JSON structure:

  "splitCommands": {
      "up": {
          "exec":"my-app-above-part",
          "install": "npm install my-app-above-part -g"
      },
      "down":{
         "exec": "my-app-below-part",
          "install": "npm install my-app-below-part -g"         
      }
  }

The up and down are "split" sub command of main application,their real name of executable command are described using exec field and their install command are described using install field.

If the executable command name of your main application is "my-app". User can type following cmd

$my-app up arg1 arg2 

instead of

$my-app-above-part arg1 arg2 

Step.2 main application entry code

Beside package.json configuration , you need add 2 lines to your code for enabling SplitCommand.

var projectPackageJSON = require('../package.json');  // configuration file of your project 
require('split-command')(projectPackageJSON);

We demonstrate an example of combining yargs and split-command:

var yargs = require('yargs');
var splitCommand = require('split-command');

var argv = yargs
    .usage('\nUsage: $0 coreCommand'                      // normal sub command in your main application
           + '\nUsage: $0 up(split cmd) '                 // split command 
           + '\nUsage: $0 down(split cmd) '               // another split command       
          )
    .command('coreCommand' , 'internal core feature')
    .command('up' ,  'some cool feature suitable lazy install')
    .command('down' ,'another cool feature suitable lazy install too')    
    .argv  ;


(function argvProcess(){
    if (argv._[0] === 'coreCommand') {    
        console.log("coreCommand running....")             // any awesome logic  of your normal sub command
    }
    var projectPackageJSON = require('../package.json');  // configuration file of your project     
    var isSplitCommandMatched = splitCommand(projectPackageJSON); // let's split command do the rest
})()

After package.json configuration and code added,your command line application became a versatile but separable one. When user install the application,they don't need to download implementation code and lib of the up and down sub command. They will be installed when the up and down sub command used for the first time.

The split sub commands should be write as normal Node command line application. When they used with splitCommand these command line arguments after main application's sub command became their full arguments.

TODO

  • ~~windows support~~
  • check the version of sub application
  • auto install sub application

Release History

  • 161102(0.0.7): add windows support & document update
  • 161101(0.0.4): remove dependence of yargs
  • 161027(0.0.3): first version