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 Dec 28, 2014
1 parent bedd768 commit 09e2126
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 0 deletions.
11 changes: 11 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 chalk = require('chalk');
var nomnom = require('nomnom');
Expand All @@ -11,6 +12,7 @@ var interpret = require('interpret');
var v8flags = require('v8flags');
var cliOptions = require('../lib/cliOptions');
var completion = require('../lib/completion');
var verifyDeps = require('../lib/verifyDependencies');
var cliVersion = require('../package.json').version;

// logging functions
Expand Down Expand Up @@ -76,6 +78,15 @@ function handleArguments(env) {
process.exit(0);
}

if (opts.verify) {
var pkgPath = opts.verify !== true ? opts.verify : 'package.json';
if (path.resolve(pkgPath) !== path.normalize(pkgPath)) {
pkgPath = path.join(env.configBase, pkgPath);
}
gutil.log('Verifying plugins in ' + pkgPath);
return verifyDeps(require(pkgPath).devDependencies || {});
}

if (!env.modulePath) {
gutil.log(
chalk.red('Local gulp not found in'),
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>` 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);
});
};
7 changes: 7 additions & 0 deletions lib/cliOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ module.exports = {
'Manually set the CWD. The search for the gulpfile, ' +
'as well as the relativity of all requires will be from here.'
},
verify: {
metavar: '<package.json path>',
flag: true,
help:
'Will verify plugins referenced in project\'s package.json against ' +
'the plugins black list.'
},
tasks: {
full: 'tasks',
abbr: 'T',
Expand Down
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 09e2126

Please sign in to comment.