forked from nodesecurity/gulp-nsp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
60 lines (45 loc) · 1.3 KB
/
index.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
'use strict';
var GulpUtil = require('gulp-util');
var Nsp = require('nsp');
var PLUGIN_NAME = require('./package.json').name;
var rsGulp = function (params, callback) {
var payload = {};
var formatter = Nsp.formatters.default;
if (params.package) {
payload.package = params.package;
}
if (params.shrinkwrap) {
payload.shrinkwrap = params.shrinkwrap;
}
// Enable builds behind the HTTP_PROXY
if (params.proxy) {
payload.proxy = params.proxy;
}
if (params.output) {
if (Nsp.formatters.hasOwnProperty(params.output)) {
formatter = Nsp.formatters[params.output];
}
else {
GulpUtil.log('Invalid formatter specified in options. Must be one of ' + Object.keys(Nsp.formatters).join(', ') + '\nUsing default formatter');
}
}
Nsp.check(payload, function (err, data) {
var output = formatter(err, data);
var pluginErr = new GulpUtil.PluginError(PLUGIN_NAME, output);
if (err) {
if (params.stopOnError === false) {
GulpUtil.log(output);
return callback();
}
return callback(pluginErr);
}
if (params.stopOnError === false || data && data.length === 0) {
GulpUtil.log(output);
return callback();
}
if (data.length > 0) {
return callback(pluginErr);
}
});
};
module.exports = rsGulp;