lib/config.js
function _flatten(groups, groupName, alreadySeen)
{
  alreadySeen = alreadySeen || [];

  var ret = {};

  // Intialize each key to empty so we don't have to check if they exist later
  HANDLER_KEYS.forEach(function(key) {
    ret[key] = [];
  });

  var thisGroup = groups[groupName];
  if ( !thisGroup )
    throw new Error('Unknown group: ' + groupName);

  // If this group includes other groups, add them first
  if ( thisGroup.include )
  {
    thisGroup.include.forEach(function(subGroupName) {
      if ( alreadySeen.indexOf(subGroupName) >= 0 )
      {
        // Circular dependency and this group has already been included elsewhere
        return;
      }
      else
      {
        alreadySeen.push(subGroupName);
      }

      var subGroup = _flatten(groups, subGroupName, alreadySeen);
      if ( !subGroup )
        throw new Error('Unknown subgroup:' +subGroupName);

      HANDLER_KEYS.forEach(function(key) {
        if ( subGroup[key] )
        {
          _mergeArrayInPlace(ret[key], subGroup[key]);
        }
      });
    });
  }

  // Then add the individual files for this group at the end
  HANDLER_KEYS.forEach(function(key) {
    if ( thisGroup[key] )
    {
      _mergeArrayInPlace( ret[key], thisGroup[key] );
    }
  });

  return ret;
}
function _flatten(groups, groupName, alreadySeen)
{
  alreadySeen = alreadySeen || [];

  var ret = {};

  // Intialize each key to empty so we don't have to check if they exist later
  HANDLER_KEYS.forEach(function(key) {
    ret[key] = [];
  });

  var thisGroup = groups[groupName];
  if ( !thisGroup )
    throw new Error('Unknown group: ' + groupName);

  // If this group includes other groups, add them first
  if ( thisGroup.include )
  {
    thisGroup.include.forEach(function(subGroupName) {
      if ( alreadySeen.indexOf(subGroupName) >= 0 )
      {
        // Circular dependency and this group has already been included elsewhere
        return;
      }
      else
      {
        alreadySeen.push(subGroupName);
      }

      var subGroup = _flatten(groups, subGroupName, alreadySeen);
      if ( !subGroup )
        throw new Error('Unknown subgroup:' +subGroupName);

      HANDLER_KEYS.forEach(function(key) {
        if ( subGroup[key] )
        {
          _mergeArrayInPlace(ret[key], subGroup[key]);
        }
      });
    });
  }

  // Then add the individual files for this group at the end
  HANDLER_KEYS.forEach(function(key) {
    if ( thisGroup[key] )
    {
      _mergeArrayInPlace( ret[key], thisGroup[key] );
    }
  });

  return ret;
}
function _flatten ( groups , groupName , alreadySeen ) { alreadySeen = alreadySeen || [ ] ; var ret = { } ; // Intialize each key to empty so we don't have to check if they exist later HANDLER_KEYS . forEach ( function ( key ) { ret [ key ] = [ ] ; } ) ; var thisGroup = groups [ groupName ] ; if ( ! thisGroup ) throw new Error ( 'Unknown group: ' + groupName ) ; // If this group includes other groups, add them first if ( thisGroup . include ) { thisGroup . include . forEach ( function ( subGroupName ) { if ( alreadySeen . indexOf ( subGroupName ) >= 0 ) { // Circular dependency and this group has already been included elsewhere return ; } else { alreadySeen . push ( subGroupName ) ; } var subGroup = _flatten ( groups , subGroupName , alreadySeen ) ; if ( ! subGroup ) throw new Error ( 'Unknown subgroup:' + subGroupName ) ; HANDLER_KEYS . forEach ( function ( key ) { if ( subGroup [ key ] ) { _mergeArrayInPlace ( ret [ key ] , subGroup [ key ] ) ; } } ) ; } ) ; } // Then add the individual files for this group at the end HANDLER_KEYS . forEach ( function ( key ) { if ( thisGroup [ key ] ) { _mergeArrayInPlace ( ret [ key ] , thisGroup [ key ] ) ; } } ) ; return ret ; }
Flatten a single group into a list of files required for it
Flatten a single group into a list of files required for it