Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

npm-cmd

Package Overview
Dependencies
Maintainers
2
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

npm-cmd - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

7

example/example.js
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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc