Grunt(节点)-如何显示可用的任务

Grunt (node) - How to show available tasks?

本文关键字:显示 任务 何显示 节点 Grunt      更新时间:2023-09-26

虽然习惯使用Rakefile、Cakefile和Jakefile,但它们都有一些方便的方法来列出可用的任务。

jake -T 
jake db:dump      # Dump the database  
jake db:load      # Populate the database  

. .等。

甚至过滤"jake -T dump",只显示"jake db:dump"任务。

那么,有没有一种方法可以使用grunt做同样的事情呢?我想也许创建一个默认任务,迭代整个grunt配置对象,并通过console.log将其写入stdout,但有人知道更好的方法吗?

谢谢。

grunt——帮助列出可用的任务,根据以下答案。

输出示例

.....
Available tasks
             clean  Clean files and folders. *                                
              jade  Compile jade templates. *                                 
        web_server  A Web Server similar to Python's SimpleHTTPServer, with   
                 Cross-Origin Resource Sharing and No-Cache options. *   

据我所知,显示可用任务的唯一方法(显然没有hack)是使用-h--help选项。

正如您在grunt-cli源代码中看到的,它们显然只关心-h(帮助)、-V(版本)和-v(详细)选项。

所以,我认为目前你必须创建自己的自定义任务来达到你的目标。

有更好的办法!我目前正在开发一个单独的插件grunt-available-tasks来实现这个功能。将其添加到您的项目中:

npm install grunt-available-tasks --save-dev

然后运行grunt availabletasks以获得任务列表。您可能需要将其别名为tasks,以节省一些输入:

grunt.registerTask('tasks', ['availabletasks']);

然后,通过一些配置,你可以得到像这样的列表:

$ grunt tasks
Running "availabletasks" task
Deployment Tasks
doc                => Build the documentation.
production         => Build a complete distribution for production; stricter linting and a full browser test.
Development Tasks
default            => Build a development distribution.
watch               > Run predefined tasks whenever watched files change.
Done, without errors.

你可以在你的Gruntfile中使用一个配置对象来过滤、分组和排序任务。在README中有一个全面的选项列表。