/**
 * @file Automation tasks with grunt.
 * @see {@link http://gruntjs.com/ | grunt}
 * @param grunt
 *
 */

"use strict";

var path = require('path'),
    fs = require('fs');


module.exports = function (grunt) {

    /**
     * Task defined as ci.
     * @param {string} filename
     * @returns {function}
     */
    function ciTask(filename) {
        return function () {
            var done = this.async(),
                config = this.data;
            require(filename).call(this, grunt, config, function (err) {
                if (err) {
                    grunt.log.error(err);
                }
                done();
            });
        }
    }


    grunt.initConfig({
        badge: require('./ci/config/badge-task-config.js'),
        catalog: require('./ci/config/catalog-task-config.js'),
        chmod: require('./ci/config/chmod-task-config'),
        exec: require('./ci/config/exec-task-config.js'),
        favicon: require('./ci/config/favicon-task-config.js'),
        ico: require('./ci/config/ico-task-config.js'),
        jsdoc: require('./ci/config/jsdoc-task-config'),
        tag: require('./ci/config/tag-task-config.js'),
        gallery: require('./ci/config/gallery-task-config.js'),
        mkdir: require('./ci/config/mkdir-task-config'),
        nodeunit: require('./ci/config/nodeunit-task-config'),
        readme: require('./ci/config/readme-task-config.js'),
        scaffold: require('./ci/config/scaffold-task-config'),
        versionup: require('./ci/config/versionup-task-config')
    });

    grunt.loadNpmTasks('grunt-mkdir');
    grunt.loadNpmTasks('grunt-chmod');
    grunt.loadNpmTasks('grunt-contrib-nodeunit');
    grunt.loadNpmTasks('grunt-exec');
    grunt.loadNpmTasks('grunt-jsdoc');

    grunt.registerMultiTask('badge', ciTask('./ci/tasks/badge_task'));
    grunt.registerMultiTask('favicon', ciTask('./ci/tasks/favicon_task'));
    grunt.registerMultiTask('ico', ciTask('./ci/tasks/ico_task'));
    grunt.registerMultiTask('catalog', ciTask('./ci/tasks/catalog_task'));
    grunt.registerMultiTask('gallery', ciTask('./ci/tasks/gallery_task'));
    grunt.registerMultiTask('readme', ciTask('./ci/tasks/readme_task'));
    grunt.registerMultiTask('tag', ciTask('./ci/tasks/tag_task'));
    grunt.registerMultiTask('scaffold', ciTask('./ci/tasks/scaffold_task'));
    grunt.registerMultiTask('versionup', ciTask('./ci/tasks/versionup_task'));


    grunt.registerTask('build', [
        'chmod',
        'mkdir',
        'scaffold',
        'catalog',
        'gallery',
        'readme'
    ]);

    grunt.registerTask('test', [
        'nodeunit'
    ]);

    grunt.registerTask('coverage', [
        'exec:coverage'
    ]);

    grunt.registerTask('doc', [
        'jsdoc',
        'coverage',
        'readme',
        'exec:doctoc'
    ]);

    grunt.registerTask('publishDoc', [
        'doc',
        'exec:commitDoc',
        'exec:pushDoc'
    ]);

    grunt.registerTask('draw', [
        'badge',
        'favicon',
        'ico'
    ]);

    grunt.registerTask('publish', [
        'draw',
        'publishDoc'
    ]);

    grunt.registerTask('default', [
        'build'
    ]);
};
@@ -1782,16 +1782,47 @@
 'badge',
+ 'Generate badge image files.',
  ciTask(
@@ -1886,16 +1886,48 @@
 avicon',
+ 'Generate favicon image files',
  ciTask(
@@ -1989,16 +1989,45 @@
 k('ico',
+ 'Generate ico image files.',
  ciTask(
@@ -2089,16 +2089,43 @@
 atalog',
+ 'Generate catalog files.',
  ciTask(
@@ -2191,16 +2191,43 @@
 allery',
+ 'Generate gallery files.',
  ciTask(
@@ -2292,16 +2292,39 @@
 readme',
+ 'Update readme file.',
  ciTask(
@@ -2385,16 +2385,43 @@
 k('tag',
+ 'Create a tag on github.',
  ciTask(
@@ -2484,16 +2484,44 @@
 affold',
+ 'Generate scaffold files.',
  ciTask(
@@ -2590,16 +2590,46 @@
 sionup',
+ 'Increment project version.',
  ciTask(
@@ -2693,18 +2693,44 @@
 build', 
-%5B%0A
+'Build this project.' %5B%0A    
         
@@ -2746,16 +2746,20 @@
         
+    
 'mkdir',
@@ -2767,16 +2767,20 @@
         
+   
+ 
 'scaffol
@@ -2791,16 +2791,20 @@
         
+    
 'catalog
@@ -2814,16 +2814,20 @@
         
+ 
+   
 'gallery
@@ -2829,32 +2829,36 @@
 llery',%0A        
+   
+ 
 'readme'%0A    %5D);
@@ -2850,16 +2850,20 @@
 readme'%0A
+    
     %5D);%0A
@@ -2893,16 +2893,29 @@
 ('test',
+ 'Run tests',
  %5B%0A     
@@ -2971,16 +2971,45 @@
 verage',
+ 'Generate coverage report.',
  %5B%0A     
@@ -3061,24 +3061,46 @@
 rTask('doc',
+ 'Generate documents.'
  %5B%0A        '
@@ -3115,16 +3115,20 @@
         
+ 
+   
 'coverag
@@ -3131,32 +3131,36 @@
 erage',%0A        
+   
+ 
 'readme',%0A      
@@ -3149,24 +3149,28 @@
   'readme',%0A
+    
         'exe
@@ -3175,32 +3175,36 @@
 xec:doctoc'%0A    
+ 
+   
 %5D);%0A%0A    grunt.r
@@ -3228,16 +3228,38 @@
 ishDoc',
+ 'Publish documents.',
  %5B%0A     
@@ -3356,16 +3356,32 @@
 ('draw',
+ 'Draw images.',
  %5B%0A     
@@ -3467,16 +3467,41 @@
 ublish',
+ 'Publish project files',
  %5B%0A     

add task descrptions [ci skip]