1

I have a simple package called for example: mypkg

I have registered this package in npm, so I can install it globally:

$ npm install -g mypkg

My question is how can I bind command options for my package, similar to:

$ mypkg build
$ mypkg serve --remote-access
$ mypkg deploy
$ mypkg test

Etc.. Exists documentation for this?

Thanks in advance!

joseluisq
  • 508
  • 1
  • 7
  • 19

1 Answers1

4

According to npm documentation

You should firstly modify package.json

{
  ...
  "preferGlobal": "true",
  "directories": {
    "bin": "./bin"
  },
  ...
}

Create a directory called lib in your modules folder, and create mypgk.js inside of it.

Then create a script which gets command line params like this

var argv = require('optimist').argv;

if (argv.make === 'deploy') {
  //do some stuff here
} else if (argv.make === 'test') {
  //another stuff
}
//...

Then install it install -g ./

then you can use it mypgk --make=deploy

If you don't like to pass arguments like I did here you can change the way you do it, refer to this question

P.S Here is brief summary what you need to do, to more precise information refer to the link at the beginning (recommended)

Community
  • 1
  • 1
Slow Harry
  • 1,857
  • 3
  • 24
  • 42