create-grunt-tasks
Create Grunt tasks as a chain of sub-tasks
This module simplifies Grunt tasks creation and increases code readability and maintainability by eliminating the configuration mess.
Install
$ npm install create-grunt-tasks --save-dev
Usage
Start creating tasks by calling task()
or tasks()
methods.
Method sub()
can be used to configure a plug-in, set a task function or include another task.
While creating multiple tasks, use for()
, not()
methods or pass factory function to sub()
method for tuning tasks configuration.
Finally Gruntfile.js
may look like this:
module { grunt { create // Create task "task1": // configure task function, ; // configure plug-in "plugin1". create // Create multiple tasks: // same config for both tasks, ; create // Create task "complex-task": // include task "task1", ; // include task "task2". };);
There is no need to call grunt.loadNpmTasks()
as far as plug-in tasks are loaded using the load-grunt-tasks module.
As soon as arguments are passed to create-grunt-tasks module it internally calls grunt.initConfig()
and grunt.registerTask()
methods.
Now run the created "complex-task" in the console:
$ grunt complex-task
Example
// Gruntfile.jsmodule { grunt { //-------------- // RELEASE tasks //-------------- create // // Copy HTML // (optionally edit content) // // Compile TypeScript and move typing // // Compile LESS // // Start server ; //------------ // DEBUG tasks //------------ // Compile TypeScript create ; // Compile LESS create ; // Compile both TypeScript and LESS create ; };}
This is equivalent to:
// Gruntfile.jsmodule { grunt; // Add this for every grunt; // newly installed plug-in :( grunt; grunt; grunt; grunt; grunt; //-------------- // RELEASE tasks //-------------- grunt; grunt; // in another place :( //------------ // DEBUG tasks //------------ // Compile TypeScript grunt; // Compile LESS grunt; // Compile both TypeScript and LESS grunt;}
Does your Gruntfile look like this mess? Then use create-grunt-tasks
plug-in to clean it up.
Changelog
0.8.0
- Register multiple tasks using
tasks()
method. - Pass factory function to
sub()
method for customizing plug-in options depending on task. - Added
for()
method for configuring optional sub-task for specified tasks. - Added
not()
method for configuring optional sub-task for all tasks excluding specified.
0.7.1
- Pass function to
sub()
method for registering a task function. - Pass task name to
sub()
method to include another task. other()
method is obsolete.
0.6.2
- Added
other(taskName)
method for registering tasks that contain other tasks.
0.5.0
- Released.