2.0.0 • Published 7 years ago
othernpm v2.0.0
Othernpm
Othernpm provides a way to run npm commands in other directories.
A typical use of this module would be to run npm scripts of subdirectories
that have own package.json
.
Usage
CLI
Othernpm allows you to specify a path where npm commands run.
# 'cd ./templates && npm install'
% onpm ./templates install
You can also define paths in package.json
and use them to specify
a path.
{
"name": "package name",
...
"othernpm": {
"examples": "./examples",
"site": "./site"
}
}
# 'cd ./site && npm run build'
% onpm site run build
# 'cd ./examples && npm test'
% onpm examples test
For example, this repository defines a npm-script named eg
in its package.json.
By this, we can run any npm command in test/example from the root directory like:
# Check defined npm-scripts in 'test/example'.
% npm run eg -- run
# Install Mocha as a dev-dependency of 'test/example'.
% npm run eg -- install --save-dev mocha
Node.js API
Othernpm also provides API used in Node.js scripts.
The module loads configurations from package.json
automatically
so that you can use them as functions.
const onpm = require('othernpm');
// Run the 'start' script in the examples directory.
onpm.examples('start');
// Run the 'build' script in the site directory.
onpm.site('run build');
// Run npm commands in another directory.
onpm('./templates')('test');
The othernpm function returns a spawn object.
const build = onpm.examples('run build');
build.on('exit', exitCode => console.log(exitCode));
Installation
npm install --save-dev othernpm
License
MIT