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!

1 Answer 1

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)

Sign up to request clarification or add additional context in comments.

1 Comment

Here I found this interesting repo

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.