Skip to content

Commit

Permalink
add the --verify option
Browse files Browse the repository at this point in the history
Closes #535
  • Loading branch information
pkozlowski-opensource authored and phated committed Jun 1, 2015
1 parent f627226 commit 54c255a
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ gulp has very few flags to know about. All other flags are for tasks to use if n
- `--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
- `-T` or `--tasks` will display the task dependency tree for the loaded gulpfile
- `--tasks-simple` will display a plaintext list of tasks for the loaded gulpfile
- `--verify` will verify plugins referenced in project's package.json against the plugins black list
- `--color` will force gulp and gulp plugins to display colors even when no color support is detected
- `--no-color` will force gulp and gulp plugins to not display colors even when color support is detected
- `--silent` will disable all gulp logging
Expand Down
37 changes: 37 additions & 0 deletions lib/blackList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
'use strict';

var http = require('http');

/**
* Given a collection of plugin names verifies this collection against
* the black-list. Invokes callback with an object:
* [plugin name]=>[black-listing reason]
* or undefined if none of the plugins to check is black-listed.
*
* @param pluginsToVerify - an array of plugin names to verify
* @param cb
*/
module.exports = function (pluginsToVerify, cb) {
http.get('http://gulpjs.com/plugins/blackList.json', function (res) {
var blackListJSONStr = '';

res.on('data', function (chunk) {
blackListJSONStr += chunk;
});

res.on('end', function () {
var blackList = JSON.parse(blackListJSONStr);
var result = pluginsToVerify.reduce(function(blackListed, pluginName) {
if (blackList[pluginName]) {
blackListed = blackListed || {};
blackListed[pluginName] = blackList[pluginName];
return blackListed;
}
});
cb(null, result);
});

}).on('error', function (e) {
cb(e);
});
};
30 changes: 30 additions & 0 deletions lib/verifyDependencies.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use strict';

var chalk = require('chalk');
var gutil = require('gulp-util');
var blackList = require('./blackList');
var formatError = require('./formatError');

module.exports = function verifyDependencies(depNames) {

blackList(Object.keys(depNames), function(err, blackListed) {
if (err) {
gutil.log(chalk.red('Error: failed to retrieve plugins black-list'));
gutil.log(formatError(err));
process.exit(1);
}

if (blackListed) {
gutil.log(chalk.red('Black-listed plugins found in this project:'));
for (var blDependency in blackListed) {
gutil.log(blDependency + ': ' + blackListed[blDependency]);
}
process.exit(1);
} else {
gutil.log(
chalk.green('There are no black-listed plugins in this project')
);
process.exit(0);
}
});
};

0 comments on commit 54c255a

Please sign in to comment.