Skip to content

Commit

Permalink
add the --verify option
Browse files Browse the repository at this point in the history
  • Loading branch information
pkozlowski-opensource committed Sep 6, 2014
1 parent 22404d3 commit f18c506
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
32 changes: 32 additions & 0 deletions bin/gulp.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env node

'use strict';
var path = require('path');
var gutil = require('gulp-util');
var prettyTime = require('pretty-hrtime');
var chalk = require('chalk');
Expand All @@ -12,6 +13,7 @@ var interpret = require('interpret');
var completion = require('../lib/completion');
var argv = require('minimist')(process.argv.slice(2));
var taskTree = require('../lib/taskTree');
var checkBlackList = require('../lib/blackList');

// set env var for ORIGINAL cwd
// before anything touches it
Expand All @@ -34,6 +36,7 @@ process.once('exit', function(code) {
// parse those args m8
var cliPackage = require('../package');
var versionFlag = argv.v || argv.version;
var verifyFlag = argv.verify;
var tasksFlag = argv.T || argv.tasks;
var tasks = argv._;
var toRun = tasks.length ? tasks : ['default'];
Expand Down Expand Up @@ -73,6 +76,10 @@ function handleArguments(env) {
process.exit(0);
}

if (verifyFlag) {
return verifyPlugins(env);
}

if (!env.modulePath) {
gutil.log(
chalk.red('Local gulp not found in'),
Expand Down Expand Up @@ -122,6 +129,31 @@ function handleArguments(env) {
});
}

function verifyPlugins(env) {
//assume package.json is located next to gulpfile.js
var pkgPath = path.join(env.configBase, 'package.json');
var devDependencies = require(pkgPath).devDependencies || {};

checkBlackList(Object.keys(devDependencies), 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 in this project'));
process.exit(0);
}
});
}

function logTasks(env, localGulp) {
var tree = taskTree(localGulp.tasks);
tree.label = 'Tasks for ' + chalk.magenta(tildify(env.configPath));
Expand Down
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>` 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);
});
};

0 comments on commit f18c506

Please sign in to comment.