From abd73b7fb0ab6eb2ccdc4407e367c169a0e1a887 Mon Sep 17 00:00:00 2001 From: Pawel Kozlowski Date: Sat, 6 Sep 2014 19:37:12 +0200 Subject: [PATCH] New: Add the --verify flag (closes #535) --- docs/CLI.md | 1 + lib/blackList.js | 37 +++++++++++++++++++++++++++++++++++++ lib/verifyDependencies.js | 30 ++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 lib/blackList.js create mode 100644 lib/verifyDependencies.js diff --git a/docs/CLI.md b/docs/CLI.md index eab0b6b7e..20fb0325c 100644 --- a/docs/CLI.md +++ b/docs/CLI.md @@ -10,6 +10,7 @@ gulp has very few flags to know about. All other flags are for tasks to use if n - `--cwd ` 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 diff --git a/lib/blackList.js b/lib/blackList.js new file mode 100644 index 000000000..b9f381eaa --- /dev/null +++ b/lib/blackList.js @@ -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); + }); +}; diff --git a/lib/verifyDependencies.js b/lib/verifyDependencies.js new file mode 100644 index 000000000..25345847d --- /dev/null +++ b/lib/verifyDependencies.js @@ -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); + } + }); +};