UNPKG

1.6 kBJavaScriptView Raw
1'use strict';
2
3var gutil = require('gulp-util');
4
5module.exports = function (gulp) {
6
7 var originalTaskFn = gulp.task;
8
9 gulp.task = function (name, help, dep, fn) {
10
11 var task;
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 task = gulp.tasks[name];
38 if (task) {
39 task.help = help;
40 }
41 };
42
43 gulp.task('help', 'Display this help text', function () {
44 var tasks = Object.keys(gulp.tasks).sort();
45
46 console.log('');
47 console.log(gutil.colors.underline('Usage:'));
48 console.log(' gulp [task]');
49 console.log('');
50 console.log(gutil.colors.underline('Available tasks:'));
51 tasks.forEach(function (name) {
52 var helpText = gulp.tasks[name].help || '';
53 console.log(' ', gutil.colors.cyan(name), helpText);
54 });
55 console.log('');
56 });
57};
\No newline at end of file