UNPKG

1.55 kBJavaScriptView Raw
1'use strict';
2
3/* jshint unused: true */
4var colors = require('colors');
5/* jshint unused: false */
6
7module.exports = function (gulp) {
8
9 var originalTaskFn = gulp.task;
10
11 gulp.task = function(name, help, dep, fn) {
12
13 /* jshint noempty: false */
14 if (typeof help === 'function') {
15 // .task('test', function(){})
16 fn = undefined;
17 dep = help;
18 help = undefined;
19 } else if (Array.isArray(help) && typeof dep === 'function') {
20 // .task('test', ['dep'], function(){})
21 fn = dep;
22 dep = help;
23 help = undefined;
24 } else if (typeof dep === 'function') {
25 // .task('test', '...', function(){})
26 // nothing needs to be re-assigned
27 } else if (Array.isArray(dep)) {
28 // .task('test', '...', ['dep'], function(){})
29 // nothing needs to be re-assigned
30 } else {
31 // not sure what they passed. Probably malformed. Just send through and let gulp handle it.
32 return originalTaskFn.call(gulp, name, help, dep, fn);
33 }
34 /* jshint noempty: true */
35
36 originalTaskFn.call(gulp, name, dep, fn);
37 gulp.tasks[name].help = help;
38 };
39
40 gulp.task('help', 'Display this help text', function () {
41 var tasks = Object.keys(gulp.tasks).sort();
42
43 console.log('');
44 console.log('Usage:'.underline);
45 console.log(' gulp [task]');
46 console.log('');
47 console.log('Available tasks:'.underline);
48 tasks.forEach(function(name) {
49 var helpText = gulp.tasks[name].help || '';
50 console.log(' ', name.cyan, helpText);
51 });
52 console.log('');
53 });
54};
\No newline at end of file