如何快速获得可用任务列表

嗨,以前我使用的 grunt,因为我想知道可用的任务使用 grunt --help。但是和在 gulp中使用 gulp --help一样,它不显示。什么是命令,以了解可用的任务列表中吞

32544 次浏览

There is no native command that does that but i use this plugin with the following code:

module.exports.help = require('gulp-help')(gulp, {description : false});

I can then just run the default gulp task in the console and it'll display a list of tasks and definitions.

Yes I got it use the gulp --tasks in command then it display the tasks list.

you can also use this plugin gulp-task-listing. It gives the main-tasks and sub-tasks list

As an alternative you can write detailed documentation to your tasks in js comments using gulp-task-doc

Another possibility is to use gulp-help-doc module, which provides possibility to print usage information based on jsDoc-like comments in a gulpfile. Currently it also supports TypeScript as well. The benefit is that you simply commenting your code without changing gulp API and you have usage info in command-line as well.

gulp --tasks-simple

This command print a plaintext list of tasks. My local project:

~ gulp --tasks-simple
clean
default

From gulp CLI documentation:

~ gulp --version
[03:00:05] CLI version 1.2.1
[03:00:05] Local version 4.0.0-alpha.2
~ gulp --help | grep 'tasks-simple'
--tasks-simple   Print a plaintext list of tasks for the loaded gulpfile. [boolean]

If you are using Gulp 4 you can do the following:

const tasks = gulp.registry().tasks();


// Outputs a JS object: { <task name>: <function>, ...}
console.log(tasks);


const taskNames = Object.Keys(tasks);


// Outputs a JS array: ['<task name>', ...]
console.log(taskNames);

inspired by @matt-gaunt https://stackoverflow.com/a/65571474/1347601

// gulp task
const list = () => {
    

const tasks = gulp.registry().tasks();


for (const [key, value] of Object.entries(tasks)) {
console.log(key);
}


}
gulp.task('list', list);


// gulp process default
gulp.task('list', gulp.series(
list
));