This repository was archived by the owner on Nov 26, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathindex.js
More file actions
50 lines (44 loc) · 1.25 KB
/
Copy pathindex.js
File metadata and controls
50 lines (44 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
var async = require('async'),
npm = require('npm');
exports = module.exports = NpmRetryInstall;
function NpmRetryInstall(options) {
options = options || {};
};
NpmRetryInstall.getMissing = function(path, cb){
npm.load(function(err){
if (err) throw err;
npm.commands.outdated(function(err, data){
if (err) throw err;
var missing_modules = [];
data.forEach(function(module){
if(module[2] === undefined)
missing_modules.push([module[1], module[3]]);
});
cb(missing_modules);
});
});
};
NpmRetryInstall.installModule = function(module, cb){
npm.load(function(err){
if (err) throw err;
npm.commands.install([module[0] + '@' + module[1]], function(err, data){
cb(err, module);
});
});
};
NpmRetryInstall.init = function(cb){
var msg = [];
NpmRetryInstall.getMissing(process.cwd(), function(data){
if(data.length > 0){
console.log(data);
async.map(data, NpmRetryInstall.installModule, function(err, result){
result.forEach(function(module){
msg.push(module[0] + "@" + module[1]);
});
return cb("Successfully installed: " + msg.join(', '));
});
} else {
cb('No modules seem to be missing. Huzzah!');
}
});
};