nackjicholson
nackjicholson

Reputation: 4839

npm link with git-style sub commands

I'm having a problem using npm link with a nodejs cli tool built using commander.

Using commander to make a git-style sub command style cli tool I have these files:

foo.js

foo-config.js

And foo.js (the main file looks like this)

#!/usr/bin/env node  
'use strict';

var program = require('commander');
var pkg = require('./package.json');

program
  .version(pkg.version)
  .command('config', 'Creates default configuration files')
  .parse(process.argv);

My package.json has this config

"bin": {
  "foo": "foo.js"
}

When I run npm link it successfully makes the symlink. I can even run the command and see that the config cmd shows up in the help menu.

However when I try to run $ foo config I get the following message

foo-config(1) does not exist, try --help

What do I do now?

Upvotes: 1

Views: 920

Answers (2)

I do it including all of commands in package.json bin section. In your example:

"bin": {
    "foo": "foo.js",
    "foo-config": "foo-config.js"
}

With this configuration, npm link will install all executables and all commands will work.

Upvotes: 1

nackjicholson
nackjicholson

Reputation: 4839

The file foo-config.js should be named foo-config without the extension.

Also if installing globally all the executables should be chmod 755

Upvotes: 3

Related Questions