2013-09-22 34 views
1

我想通过终端从gruntfile获取已注册的任务。有没有办法通过终端读取咕噜声?

例子:

grunt.registerTask('test', ['clean', 'compass', 'uglify', 'cssmin', 'imagemin', 'copy:test', 'ftp-deploy:test', 'clean']); 

然后在终端上我会键入类似

$> grunt --listtasks 

更妙的是,如果我能有像这样的说明注册每个任务:

grunt.registerTask('test', 'this task deploys to testserver',['clean', 'compass', 'uglify', 'cssmin', 'imagemin', 'copy:test', 'ftp-deploy:test', 'clean']); 

然后输出可能是这样的:

$> test: this task deploys to testserver (clean, compass, uglify, cssmin, imagemin, copy:test, ftp-deploy:test, clean) 

回答

1

运行grunt --help获取所有注册任务的列表。这显示了命令和任务描述。示例输出:

$ grunt --help 
Grunt: The JavaScript Task Runner (v0.4.1) 

Usage 
grunt [options] [task [task ...]] 

Options 
     --help, -h Display this help text. 
      --base Specify an alternate base path. By default, all file paths 
        are relative to the Gruntfile. (grunt.file.setBase) * 
     --no-color Disable colored output. 
     --gruntfile Specify an alternate Gruntfile. By default, grunt looks in 
        the current or parent directories for the nearest 
        Gruntfile.js or Gruntfile.coffee file. 
     --debug, -d Enable debugging mode for tasks that support it. 
      --stack Print a stack trace when exiting with a warning or fatal 
        error. 
     --force, -f A way to force your way past warnings. Want a suggestion? 
        Don't use this option, fix your code. 
      --tasks Additional directory paths to scan for task and "extra" 
        files. (grunt.loadTasks) * 
       --npm Npm-installed grunt plugins to scan for task and "extra" 
        files. (grunt.loadNpmTasks) * 
     --no-write Disable writing files (dry run). 
     --verbose, -v Verbose mode. A lot more information output. 
     --version, -V Print the grunt version. Combine with --verbose for more 
        info. 
     --completion Output shell auto-completion rules. See the grunt-cli 
        documentation for more information. 

Options marked with * have methods exposed via the grunt API and should instead 
be specified inside the Gruntfile wherever possible. 

Available tasks 
      rosetta Shared variables between JS and CSS. * 
      asciify Ascii awesomizer. A Grunt task for better banners and hot 
        logs. * 
       clear Clear your terminal window 
       clean Clean files and folders. * 
      concat Concatenate files. * 
      jshint Validate files with JSHint. * 
       sass Compile Sass to CSS * 
       watch Run predefined tasks whenever watched files change. 
       csso Minify CSS files with CSSO. * 
     lintspaces Checking spaces * 
       newer Run a task with only those source files that have been 
        modified since the last successful run. 
      any-newer Run a task with all source files if any have been modified 
        since the last successful run. 
    newer-timestamp Internal task. 
      svgmin Minify SVG * 
trimtrailingspaces Removing the trailing spaces * 
      webfont Compile separate SVG files to webfont * 

Tasks run in the order specified. Arguments may be passed to tasks that accept 
them by using colons, like "lint:files". Tasks marked with * are "multi tasks" 
and will iterate over all sub-targets if no argument is specified. 

The list of available tasks may change based on tasks directories or grunt 
plugins specified in the Gruntfile or via command-line options. 

For more information, see http://gruntjs.com/ 
+0

这是种它。也许描述将是一个很好的功能?或者也许是一个单独的命令只显示任务? – Markus

+0

我不相信那里已经有提供这个输出的简化版本,正如你所描述的那样。这可能是一个潜在的插件机会。 :) – Ben

+0

由于Grunt的工作方式,当任务被注册时,任务列表被转换为一个函数,所以目前不可能显示任务别名。但是,我设法得到一个单独的命令列出所有注册的任务工作。你可以在这里查看:https://github.com/ben-eb/grunt-available-tasks – Ben