22

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

喜欢

jake -T 

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

..ETC。

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

那么,有没有办法使用 grunt 来做同样的事情?我正在考虑创建一个默认任务来迭代整个 grunt 配置对象并通过 console.log 将其写入标准输出,但是有人知道更好的方法吗?

谢谢。

4

3 回答 3

17

grunt --help 根据以下答案列出可用任务。

示例输出

.....

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. *   
于 2014-08-23T10:55:55.057 回答
11

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

正如您在grunt-cli 源代码中看到的那样,它们显然只关心-h(help)、-V(version) 和-v(verbose) 选项。

因此,我认为目前您必须创建自己的自定义任务才能实现目标。

于 2013-01-09T17:14:20.063 回答
9

有一个更好的方法!我目前正在开发一个单独的插件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 中的配置对象过滤、分组和排序任务。自述文件中提供了完整的选项列表。

于 2013-11-26T22:41:04.413 回答