Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grunt (node) - How to show available tasks?

While beeing used to using Rakefile, Cakefile and Jakefile, they all had some convenient way of listing the available tasks.

Like

jake -T 

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

..etc.

or even filtering "jake -T dum", to only show "the "jake db:dump" task.

So, is there a way to do the same using grunt? I was thinking of maybe creating a default task that iterates the entire grunt config object and write it to stdout via console.log, but does someone know a better way?

Thanks.

like image 733
borestad Avatar asked Jan 04 '13 01:01

borestad


3 Answers

grunt --help lists available tasks, as per following answer.

Example output

.....

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. *   
like image 169
Atilla Ozgur Avatar answered Oct 27 '22 11:10

Atilla Ozgur


As far as I know the only way (obviously without hacks) to show the available tasks is using the -h or --help option.

As you can see in grunt-cli source they clearly take care about only -h (help), -V (version), and -v (verbose) options.

So, I think that currently you have to create your own custom task to reach your goal.

like image 35
Ragnarokkr Avatar answered Oct 27 '22 12:10

Ragnarokkr


There is a better way! I'm currently working on a separate plugin, grunt-available-tasks to achieve this functionality. Add it to your project with:

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

Then run grunt availabletasks to get a list of your tasks. You may want to alias this with tasks to save some typing:

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

Then, with some configuration you can get lists like this one:

$ 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.

You can filter, group and sort tasks using a configuration object in your Gruntfile. A comprehensive list of options is available in the README.

like image 34
Ben Avatar answered Oct 27 '22 10:10

Ben