2013-12-19 23:07:19 +00:00
|
|
|
/*!
|
|
|
|
* Merge jsduck configuration files with a downstream one
|
|
|
|
*/
|
|
|
|
|
2016-10-28 00:22:30 +00:00
|
|
|
/* eslint-env node */
|
2013-12-19 23:07:19 +00:00
|
|
|
module.exports = function ( grunt ) {
|
|
|
|
var _ = grunt.util._;
|
|
|
|
|
|
|
|
grunt.registerMultiTask( 'jsduckcatconfig', function () {
|
|
|
|
var targetFile = this.data.target,
|
|
|
|
from = this.data.from,
|
|
|
|
output = [];
|
|
|
|
|
|
|
|
from.forEach( function ( src ) {
|
|
|
|
var srcCategories;
|
|
|
|
|
|
|
|
if ( typeof src === 'string' ) {
|
|
|
|
src = {
|
|
|
|
file: src
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
srcCategories = grunt.file.readJSON( src.file );
|
|
|
|
|
|
|
|
if ( !src.include && !src.aggregate ) {
|
|
|
|
// Default to a straight inclusion
|
|
|
|
output.push.apply( output, srcCategories );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( src.aggregate ) {
|
|
|
|
_.forIn( src.aggregate, function ( targetCat, targetCatName ) {
|
|
|
|
var targetGroups = [];
|
|
|
|
// For each of the target category groups...
|
|
|
|
targetCat.forEach( function ( targetGroupName ) {
|
|
|
|
// ... find the category in the aggregate source
|
|
|
|
srcCategories.forEach( function ( aggrCat ) {
|
2015-08-19 18:05:01 +00:00
|
|
|
var targetGroup;
|
2013-12-19 23:07:19 +00:00
|
|
|
if ( aggrCat.name === targetGroupName ) {
|
2015-08-19 18:05:01 +00:00
|
|
|
targetGroup = {
|
2013-12-19 23:07:19 +00:00
|
|
|
name: targetGroupName,
|
|
|
|
classes: []
|
|
|
|
};
|
|
|
|
aggrCat.groups.forEach( function ( group ) {
|
|
|
|
targetGroup.classes = targetGroup.classes.concat( group.classes );
|
|
|
|
} );
|
|
|
|
targetGroups.push( targetGroup );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
output.push( {
|
|
|
|
name: targetCatName,
|
|
|
|
groups: targetGroups
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( src.include ) {
|
|
|
|
src.include.forEach( function ( targetCatName ) {
|
|
|
|
srcCategories.forEach( function ( aggrCat ) {
|
|
|
|
if ( aggrCat.name === targetCatName ) {
|
|
|
|
output.push( aggrCat );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
} );
|
|
|
|
|
|
|
|
grunt.file.write( targetFile, JSON.stringify( output, null, '\t' ) + '\n' );
|
|
|
|
grunt.log.ok( 'File "' + targetFile + '" written.' );
|
|
|
|
} );
|
|
|
|
};
|