Reputation: 41
I have some scripts that I want to distribute with npm for developers to be able to install globally on their workstations and then use the commands of the scripts on their computers in their development workflow.
I can't work out how to get npm to actually add the script in its package to the path though.
I see that the firebase tools have this in their package.json:
"preferGlobal": true,
"bin": {
"firebase": "./bin/firebase"
},
...but I can't quite work out how this relates to my project.
The first project I am trying to distribute with npm is for controlling a Belkin WeMo light switch, it includes an executable 'wemo' and an included functions.inc.sh file, this can be seen @ https://github.com/agilemation/Belkin-WeMo-Command-Line-Tools.git
If anyone can point me in the right direction it will be really appreciated!!!
Thanks,
James
Upvotes: 2
Views: 872
Reputation: 22758
Any key/value pairs placed into the bin
key of the package.json
will be symlink'ed into the NPM bin-dir path.
The key
is what you want the command to be named and the value
part is the script in your package it should run.
Ergo, in your example, when npm install
finishes running it'll create a symlink from [package-install-path]/bin/firebase
to /usr/local/bin/firebase
(or whatever bin directory prefix NPM is using (npm bin -g
will tell you where this is).
If you only have one script you can also do:
{
"name": "my-awesome-package",
"bin": "./myscript.sh"
}
And it'll symlink myscript.sh
to my-awesome-package
Although you should be wary of including bash scripts since they won't work on Windows.
Here are the docs for this.
Upvotes: 4