Comparing version 0.1.0 to 0.2.0
var npm = require('..'); | ||
npm.install(['foobar'], {cwd: 'c:/tmp'}, function(err) { | ||
npm.install(['digitaledgeit-view', 'digitaledgeit-view-collection'], {cwd: 'c:/tmp', save: true}, function(err) { | ||
console.log('installed?', err); | ||
npm.dedupe({cwd: 'c:/tmp'}, function(err) { | ||
console.log('dedupeed?', err); | ||
}); | ||
}); |
146
index.js
@@ -50,4 +50,66 @@ var debug = require('debug')('npm-cmd'); | ||
/** | ||
* Set the default args | ||
* | ||
* @param {string} cmd | ||
* @param {string|Array.<string>} [pkgs] | ||
* @param {Object} [opts] | ||
* @param {function(Error)} [done] | ||
* @param {function()} callback | ||
* | ||
*/ | ||
function args(cmd, pkgs, opts, done, callback) { | ||
var | ||
execArgs = [cmd], | ||
execOpts = {} | ||
; | ||
// --- decide what options were passed --- | ||
switch (typeof(pkgs)) { | ||
case 'object': | ||
if (!Array.isArray(pkgs)) { | ||
done = opts; | ||
opts = pkgs; | ||
pkgs = []; | ||
} | ||
break; | ||
case 'function': | ||
done = pkgs; | ||
opts = {}; | ||
pkgs = []; | ||
break; | ||
default: | ||
pkgs = [pkgs]; | ||
} | ||
if (arguments.length > 1) { | ||
if (typeof(opts) === 'function') { | ||
done = opts; | ||
opts = {}; | ||
} | ||
} | ||
//default callback to a noop | ||
opts = opts || {}; | ||
done = done || function(){}; | ||
if (opts.cwd) { | ||
execOpts.cwd = opts.cwd; | ||
} | ||
execArgs = execArgs.concat(pkgs); | ||
callback(execArgs, execOpts, done); | ||
} | ||
module.exports = { | ||
exec: exec, | ||
/** | ||
@@ -64,65 +126,37 @@ * Run `npm install` | ||
install: function(pkgs, opts, done) { | ||
args('install', pkgs, opts, done, function(execArgs, execOpts, execDone) { | ||
var | ||
execArgs = ['install'], | ||
execOpts = {} | ||
; | ||
if (opts.global) { | ||
execArgs.push('-g'); | ||
} | ||
// --- decide what options were passed --- | ||
if (opts.save) { | ||
execArgs.push('--save'); | ||
} | ||
switch (typeof(pkgs)) { | ||
if (opts.saveDev) { | ||
execArgs.push('--save-dev'); | ||
} | ||
case 'object': | ||
if (!Array.isArray(pkgs)) { | ||
done = opts; | ||
opts = pkgs; | ||
pkgs = []; | ||
} | ||
break; | ||
case 'function': | ||
done = pkgs; | ||
opts = {}; | ||
pkgs = []; | ||
break; | ||
default: | ||
pkgs = [pkgs]; | ||
} | ||
if (arguments.length > 1) { | ||
if (typeof(opts) === 'function') { | ||
done = opts; | ||
opts = {}; | ||
if (opts.registry) { | ||
execArgs.push('--registry='+opts.registry); | ||
} | ||
} | ||
//default callback to a noop | ||
opts = opts || {}; | ||
done = done || function(){}; | ||
exec(execArgs, execOpts, execDone) | ||
}); | ||
}, | ||
if (opts.global) { | ||
execArgs.push('-g'); | ||
} | ||
if (opts.save) { | ||
execArgs.push('--save'); | ||
} | ||
if (opts.saveDev) { | ||
execArgs.push('--save-dev'); | ||
} | ||
if (opts.registry) { | ||
execArgs.push('--registry='+opts.registry); | ||
} | ||
if (opts.cwd) { | ||
execOpts.cwd = opts.cwd; | ||
} | ||
execArgs = execArgs.concat(pkgs); | ||
exec(execArgs, execOpts, done); | ||
/** | ||
* Run `npm dedupe` | ||
* | ||
* @see https://docs.npmjs.com/cli/dedupe | ||
* | ||
* @param {string|Array.<string>} [pkgs] | ||
* @param {Object} [opts] | ||
* @param {function(Error)} [done] | ||
*/ | ||
dedupe: function(pkgs, opts, done) { | ||
args('dedupe', pkgs, opts, done, function(execArgs, execOpts, execDone) { | ||
exec(execArgs, execOpts, execDone) | ||
}); | ||
} | ||
@@ -129,0 +163,0 @@ |
{ | ||
"name": "npm-cmd", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "An API to execute `npm` commands programmatically.", | ||
"keywords": ["npm", "cmd", "run", "exec", "command", "spawn", "install", "dedupe"], | ||
"dependencies": { | ||
"debug": "^2.2.0" | ||
} | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git@github.com:digitaledgeit/npm-cmd.git" | ||
}, | ||
"license": "MIT" | ||
} |
@@ -27,2 +27,26 @@ # npm-cmd | ||
Run `npm install`. | ||
Run `npm install` where: | ||
- `pkgs` is an array of packages to install - optional | ||
- `opts` is an object of key-value pairs - optional | ||
- `opts.global` whether npm should install | ||
- `opts.save` whether npm should save the packages to the `dependencies` key in `package.json` | ||
- `opts.saveDev` whether npm should save the packages to the `devDependencies` key in `package.json` | ||
- `opts.registry` the registry which npm should source package information from | ||
- `done` is a function called when the command has finished - optional | ||
#### .dedupe(pkgs, opts, done) | ||
Run `npm dedupe` where: | ||
- `pkgs` is an array of packages to dedupe - optional | ||
- `opts` is an object of key-value pairs - optional | ||
- `done` is a function called when the command has finished - optional | ||
### Options | ||
Global options accepted by all commands: | ||
- `opts.cwd` is the directory where the command will be run |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No License Found
License(Experimental) License information could not be found.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
5474
0
136
51
0
2