So far, we’ve defined a Grunt task using two arguments: a name and a callback function, or a name and an array of tasks that we want to call. But the registerTask method can take three arguments. After the name, we can specify a text description of the task.
Let’s define a simple task called praise that makes Grunt say some words of encouragement to you.
basics/kicking_tires/Gruntfile.js | |
| grunt.registerTask('praise', |
| 'Have Grunt say nice things about you.', function(){ |
| var praise = [ |
| "You're awesome.", |
| "You're the best developer ever!", |
| "You are extremely attractive.", |
| "Everyone loves you!" |
| ] |
| var pick = praise[(Math.floor(Math.random() * praise.length))]; |
| grunt.log.writeln(pick); |
| |
| }); |
Now type this:
| $ grunt --help |
This shows Grunt’s basic help page, but in the middle of the output you’ll see this:
| Available tasks |
| default Custom task. |
| greet Custom task. |
| addNumbers Custom task. |
| all Alias for "default", "greet:Brian", "addNumbers:2:3" tasks. |
| praise Have Grunt say nice things about you. |
All the tasks we didn’t document just say “Custom task,” but our praise task shows its description. It’s really important that we document the tasks that we create so others who follow our work will know what those tasks do. As we go forward we’ll be sure to do that.
If you’d like a nicer way to see your tasks, take a look at the grunt-available-tasks plug-in, which gives a simple list of the tasks that isn’t buried in the help.[4]
3.138.170.81