index.js
function build(gulp) {
    // make sure we don't lose anything from required files
    // @see https://github.com/Mikhus/gulp-help-doc/issues/2
    // currently this is not supported for typescript

    var source = OPTIONS.isTypescript ?
        fs.readFileSync('gulpfile.ts').toString() :
        OPTIONS.gulpfile ?
            fs.readFileSync(OPTIONS.gulpfile).toString() :
        Object.keys(require.cache || {'gulpfile.js': ''}).map(function(file) {
            if (!/node_modules|\.json$/.test(file)) {
                return fs.readFileSync(file).toString() + '\n';
            }
        }).join('');

    var rxDoc = '\\/\\*\\*\\r?\n(((?!\\*\\/)[\\s\\S])*?)' +
        '@task\\s+\\{(.*)?\\}((?!\\*\\/)[\\s\\S])*?\\*\\/';

    var rxArgs = '@arg\\s+\\{(.*?)\\}(.*?)\\r?\\n';
    var rxOrder = '@order\\s+\\{(\\d+)\\}(.*?)\\r?\\n';
    var rxGroup = '@group\\s+\\{(.*?)\\}(.*?)\\r?\\n';

    var globalRxDoc = new RegExp(rxDoc, 'g');
    var localRxDoc = new RegExp(rxDoc);

    var globalRxArgs = new RegExp(rxArgs, 'g');
    var localRxArgs = new RegExp(rxArgs);

    var globalRxOrder = new RegExp(rxOrder, 'g');
    var localRxOrder = new RegExp(rxOrder);

    var globalRxGroup = new RegExp(rxGroup, 'g');
    var localRxGroup = new RegExp(rxGroup);

    var jsDoc  = (source.match(globalRxDoc) || []);
    var tasks = gulpTasks(gulp);

    Object.keys(tasks).forEach(function (task) {
        reflection[task] = {
            name: tasks[task].name,
            desc: '',
            dep: tasks[task].dep
        };
    });

    jsDoc.map(function (block) {
        var parts = block.match(localRxDoc);

        var name = parts[3].trim();
        var desc = parts[1].replace(/\s*\*/g, ' ')
            .replace(/\s{2,}/g, ' ')
            .trim();

        if (!reflection[name]) {
            return;
        }

        reflection[name].desc = desc;
        reflection[name].public = true;
        reflection[name].args = (block.match(globalRxArgs) || [])
            .map(function (def) {
                var argsParts = def.match(localRxArgs);

                return {
                    name: argsParts[1],
                    desc: argsParts[2].replace(/\s*\*/g, ' ')
                        .replace(/\s{2,}/g, ' ')
                        .trim()
                };
            });

        reflection[name].order = (function () {
            var orderParts = block.match(globalRxOrder);

            if (orderParts) {
                return +orderParts[0].match(localRxOrder)[1];
            }

            return Number.MAX_SAFE_INTEGER;
        })();

        reflection[name].group = (function () {
            var groupParts = block.match(globalRxGroup);

            if (groupParts) {
                return groupParts[0].match(localRxGroup)[1];
            }

            return OPTIONS.defaultGroupName;
        })();
    });

    // Re-group tasks using user-defined groups
    var tmp = {};

    Object.keys(reflection).forEach(function(task) {
        var group = reflection[task].group || OPTIONS.defaultGroupName;

        tmp[group] = tmp[group] || {};
        tmp[group][task] = reflection[task];
    });

    reflection = tmp;
}
function build(gulp) {
    // make sure we don't lose anything from required files
    // @see https://github.com/Mikhus/gulp-help-doc/issues/2
    // currently this is not supported for typescript

    var source = OPTIONS.isTypescript ?
        fs.readFileSync('gulpfile.ts').toString() :
        OPTIONS.gulpfile ?
            fs.readFileSync(OPTIONS.gulpfile).toString() :
        Object.keys(require.cache || {'gulpfile.js': ''}).map(function(file) {
            if (!/node_modules|\.json$/.test(file)) {
                return fs.readFileSync(file).toString() + '\n';
            }
        }).join('');

    var rxDoc = '\\/\\*\\*\\r?\n(((?!\\*\\/)[\\s\\S])*?)' +
        '@task\\s+\\{(.*)?\\}((?!\\*\\/)[\\s\\S])*?\\*\\/';

    var rxArgs = '@arg\\s+\\{(.*?)\\}(.*?)\\r?\\n';
    var rxOrder = '@order\\s+\\{(\\d+)\\}(.*?)\\r?\\n';
    var rxGroup = '@group\\s+\\{(.*?)\\}(.*?)\\r?\\n';

    var globalRxDoc = new RegExp(rxDoc, 'g');
    var localRxDoc = new RegExp(rxDoc);

    var globalRxArgs = new RegExp(rxArgs, 'g');
    var localRxArgs = new RegExp(rxArgs);

    var globalRxOrder = new RegExp(rxOrder, 'g');
    var localRxOrder = new RegExp(rxOrder);

    var globalRxGroup = new RegExp(rxGroup, 'g');
    var localRxGroup = new RegExp(rxGroup);

    var jsDoc  = (source.match(globalRxDoc) || []);
    var tasks = gulpTasks(gulp);

    Object.keys(tasks).forEach(function (task) {
        reflection[task] = {
            name: tasks[task].name,
            desc: '',
            dep: tasks[task].dep
        };
    });

    jsDoc.map(function (block) {
        var parts = block.match(localRxDoc);

        var name = parts[3].trim();
        var desc = parts[1].replace(/\s*\*/g, ' ')
            .replace(/\s{2,}/g, ' ')
            .trim();

        if (!reflection[name]) {
            return;
        }

        reflection[name].desc = desc;
        reflection[name].public = true;
        reflection[name].args = (block.match(globalRxArgs) || [])
            .map(function (def) {
                var argsParts = def.match(localRxArgs);

                return {
                    name: argsParts[1],
                    desc: argsParts[2].replace(/\s*\*/g, ' ')
                        .replace(/\s{2,}/g, ' ')
                        .trim()
                };
            });

        reflection[name].order = (function () {
            var orderParts = block.match(globalRxOrder);

            if (orderParts) {
                return +orderParts[0].match(localRxOrder)[1];
            }

            return Number.MAX_SAFE_INTEGER;
        })();

        reflection[name].group = (function () {
            var groupParts = block.match(globalRxGroup);

            if (groupParts) {
                return groupParts[0].match(localRxGroup)[1];
            }

            return OPTIONS.defaultGroupName;
        })();
    });

    // Re-group tasks using user-defined groups
    var tmp = {};

    Object.keys(reflection).forEach(function(task) {
        var group = reflection[task].group || OPTIONS.defaultGroupName;

        tmp[group] = tmp[group] || {};
        tmp[group][task] = reflection[task];
    });

    reflection = tmp;
}
Analyzes given gulp instance and build internal cache
for further printing

@param {Gulp} gulp
@access private