Skip to content

Instantly share code, notes, and snippets.

@mildmojo
Created May 30, 2019 18:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mildmojo/ffbd599825bbedbcb12d6e584473559f to your computer and use it in GitHub Desktop.
Save mildmojo/ffbd599825bbedbcb12d6e584473559f to your computer and use it in GitHub Desktop.
Gulp task definition helper so all gulp tasks can have descriptions for `gulp -T`.
'use strict';
const exec = require('child_process').exec;
// Quick shortcut for shortcomings in `gulp.task` API:
// 1. `gulp.task` doesn't accept a description, has to be a prop on the function.
// 2. Since description has to be on the task function, it's harder to add a
// description to tasks whose functions were created by a helper (e.g.
// `gulp.series` or `gulp.parallel`) since you didn't define the functions
// they return.
function gulpTask(name, desc, fn) {
gulp.task(name, fn);
gulp.task(name).unwrap().description = desc;
}
gulpTask(
'ls_js',
'Task for listing Javascript files',
done => exec('ls *.js', done)
);
gulpTask(
'ls_html',
'Task for listing HTML files',
done => exec('ls *.html', done)
);
gulpTask(
'ls_all',
'Task for listing JS and HTML files',
gulp.series('ls_js', 'ls_html')
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment