bor*_*tad 22 javascript command-line-interface node.js jake gruntjs
虽然过去常常使用Rakefile,Cakefile和Jakefile,但它们都有一些方便的列出可用任务的方法.
喜欢
jake -T
jake db:dump # Dump the database
jake db:load # Populate the database
Run Code Online (Sandbox Code Playgroud)
..等等.
甚至过滤"jake -T dum",只显示"the jake db:dump"任务.
那么,有没有办法使用grunt做同样的事情?我在考虑创建一个默认任务,迭代整个grunt配置对象并通过console.log将其写入stdout,但有人知道更好的方法吗?
谢谢.
Ati*_*gur 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. *
Run Code Online (Sandbox Code Playgroud)
Rag*_*kkr 11
据我所知,显示可用任务的唯一方法(显然没有黑客)是使用-h或--help选项.
正如您在grunt-cli源中所看到的,它们显然只关注-h(帮助),-V(版本)和-v(详细)选项.
所以,我认为目前您必须创建自己的自定义任务才能实现目标.
有一个更好的方法!我目前正在开发一个单独的插件,grunt-available-tasks来实现这个功能.将其添加到您的项目中:
npm install grunt-available-tasks --save-dev
Run Code Online (Sandbox Code Playgroud)
然后运行grunt availabletasks以获取您的任务列表.您可能希望使用别名tasks来保存一些输入:
grunt.registerTask('tasks', ['availabletasks']);
Run Code Online (Sandbox Code Playgroud)
然后,通过一些配置,您可以获得如下列表:
$ 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.
Run Code Online (Sandbox Code Playgroud)
您可以使用Gruntfile中的配置对象对任务进行筛选,分组和排序.README中提供了一个完整的选项列表.
| 归档时间: |
|
| 查看次数: |
8500 次 |
| 最近记录: |