Skip to content

Commit abd73b7

Browse files
pkozlowski-opensourcephated
authored andcommitted
New: Add the --verify flag (closes #535)
1 parent 5368d2c commit abd73b7

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

docs/CLI.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ gulp has very few flags to know about. All other flags are for tasks to use if n
1010
- `--cwd <dir path>` will manually set the CWD. The search for the gulpfile, as well as the relativity of all requires will be from here
1111
- `-T` or `--tasks` will display the task dependency tree for the loaded gulpfile
1212
- `--tasks-simple` will display a plaintext list of tasks for the loaded gulpfile
13+
- `--verify` will verify plugins referenced in project's package.json against the plugins black list
1314
- `--color` will force gulp and gulp plugins to display colors even when no color support is detected
1415
- `--no-color` will force gulp and gulp plugins to not display colors even when color support is detected
1516
- `--silent` will disable all gulp logging

lib/blackList.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
'use strict';
2+
3+
var http = require('http');
4+
5+
/**
6+
* Given a collection of plugin names verifies this collection against
7+
* the black-list. Invokes callback with an object:
8+
* [plugin name]=>[black-listing reason]
9+
* or undefined if none of the plugins to check is black-listed.
10+
*
11+
* @param pluginsToVerify - an array of plugin names to verify
12+
* @param cb
13+
*/
14+
module.exports = function (pluginsToVerify, cb) {
15+
http.get('http://gulpjs.com/plugins/blackList.json', function (res) {
16+
var blackListJSONStr = '';
17+
18+
res.on('data', function (chunk) {
19+
blackListJSONStr += chunk;
20+
});
21+
22+
res.on('end', function () {
23+
var blackList = JSON.parse(blackListJSONStr);
24+
var result = pluginsToVerify.reduce(function(blackListed, pluginName) {
25+
if (blackList[pluginName]) {
26+
blackListed = blackListed || {};
27+
blackListed[pluginName] = blackList[pluginName];
28+
return blackListed;
29+
}
30+
});
31+
cb(null, result);
32+
});
33+
34+
}).on('error', function (e) {
35+
cb(e);
36+
});
37+
};

lib/verifyDependencies.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
'use strict';
2+
3+
var chalk = require('chalk');
4+
var gutil = require('gulp-util');
5+
var blackList = require('./blackList');
6+
var formatError = require('./formatError');
7+
8+
module.exports = function verifyDependencies(depNames) {
9+
10+
blackList(Object.keys(depNames), function(err, blackListed) {
11+
if (err) {
12+
gutil.log(chalk.red('Error: failed to retrieve plugins black-list'));
13+
gutil.log(formatError(err));
14+
process.exit(1);
15+
}
16+
17+
if (blackListed) {
18+
gutil.log(chalk.red('Black-listed plugins found in this project:'));
19+
for (var blDependency in blackListed) {
20+
gutil.log(blDependency + ': ' + blackListed[blDependency]);
21+
}
22+
process.exit(1);
23+
} else {
24+
gutil.log(
25+
chalk.green('There are no black-listed plugins in this project')
26+
);
27+
process.exit(0);
28+
}
29+
});
30+
};

0 commit comments

Comments
 (0)