This repository has been archived by the owner on Feb 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 47
/
verify-git.js
64 lines (48 loc) · 1.52 KB
/
verify-git.js
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
51
52
53
54
55
56
57
58
59
60
61
62
var path = require('path');
var readJSON = require('./read-json');
var parallel = require('run-parallel');
var analyzeDependency = require('./analyze-dependency.js');
module.exports = verifyGit;
function verifyGit(opts, callback) {
if (typeof opts === 'string') {
opts = { dirname: opts };
}
var packageFile = path.join(opts.dirname, 'package.json');
readJSON(packageFile, onpackage);
function onpackage(err, package) {
if (err) {
return callback(err);
}
var deps = package.dependencies || {};
var devDeps = package.devDependencies || {};
parallel([
analyze.bind(null, deps, opts),
opts.dev ? analyze.bind(null, devDeps, opts) : null
].filter(Boolean), function (err, values) {
if (err) {
return callback(err);
}
var errors = values[0].concat(values[1] || []);
callback(null, errors);
});
}
}
function analyze(deps, opts, callback) {
var tasks = Object.keys(deps).map(function (key) {
return analyzeDependency.bind(null,
key, deps[key], opts);
});
parallel(tasks, function (err, results){
if (err) {
return callback(err);
}
var errors = Object.keys(results)
.reduce(function (acc, key) {
if (results[key]) {
acc.push(results[key]);
}
return acc;
}, []);
callback(null, errors);
});
}