lib/load_files.js
function loadFiles(directories, files)
{
  // sort extensions to provide deterministic order of loading
  var _instance  = this
    , extensions = resolveExts.call(this)
    , layers     = []
    ;

  // treat all inputs as list of directories
  directories = (typeOf(directories) == 'array') ? directories : [directories];

  files.forEach(function(filename)
  {
    var layer = {file: filename, exts: []};

    extensions.forEach(function(ext)
    {
      var layerExt = {ext: ext, dirs: []};

      directories.forEach(function(dir)
      {
        var cfg, file = path.resolve(dir, filename + '.' + ext);

        if (fs.existsSync(file))
        {
          cfg = loadContent.call(_instance, file, _instance.parsers[ext]);

          // check if any hooks needed to be applied
          cfg = applyHooks.call(_instance, cfg, filename);
        }

        if (cfg)
        {
          layerExt.dirs.push({
            dir   : dir,
            config: cfg
          });
        }
      });

      // populate with non-empty layers only
      if (layerExt.dirs.length)
      {
        layer.exts.push(layerExt);
      }
    });

    // populate with non-empty layers only
    if (layer.exts.length)
    {
      layers.push(layer);
    }

  });

  return layers;
}
function loadFiles(directories, files)
{
  // sort extensions to provide deterministic order of loading
  var _instance  = this
    , extensions = resolveExts.call(this)
    , layers     = []
    ;

  // treat all inputs as list of directories
  directories = (typeOf(directories) == 'array') ? directories : [directories];

  files.forEach(function(filename)
  {
    var layer = {file: filename, exts: []};

    extensions.forEach(function(ext)
    {
      var layerExt = {ext: ext, dirs: []};

      directories.forEach(function(dir)
      {
        var cfg, file = path.resolve(dir, filename + '.' + ext);

        if (fs.existsSync(file))
        {
          cfg = loadContent.call(_instance, file, _instance.parsers[ext]);

          // check if any hooks needed to be applied
          cfg = applyHooks.call(_instance, cfg, filename);
        }

        if (cfg)
        {
          layerExt.dirs.push({
            dir   : dir,
            config: cfg
          });
        }
      });

      // populate with non-empty layers only
      if (layerExt.dirs.length)
      {
        layer.exts.push(layerExt);
      }
    });

    // populate with non-empty layers only
    if (layer.exts.length)
    {
      layers.push(layer);
    }

  });

  return layers;
}
function loadFiles ( directories , files ) { // sort extensions to provide deterministic order of loading var _instance = this , extensions = resolveExts . call ( this ) , layers = [ ] ; // treat all inputs as list of directories directories = ( typeOf ( directories ) == 'array' ) ? directories : [ directories ] ; files . forEach ( function ( filename ) { var layer = { file : filename , exts : [ ] } ; extensions . forEach ( function ( ext ) { var layerExt = { ext : ext , dirs : [ ] } ; directories . forEach ( function ( dir ) { var cfg , file = path . resolve ( dir , filename + '.' + ext ) ; if ( fs . existsSync ( file ) ) { cfg = loadContent . call ( _instance , file , _instance . parsers [ ext ] ) ; // check if any hooks needed to be applied cfg = applyHooks . call ( _instance , cfg , filename ) ; } if ( cfg ) { layerExt . dirs . push ( { dir : dir , config : cfg } ) ; } } ) ; // populate with non-empty layers only if ( layerExt . dirs . length ) { layer . exts . push ( layerExt ) ; } } ) ; // populate with non-empty layers only if ( layer . exts . length ) { layers . push ( layer ) ; } } ) ; return layers ; }
Loads and parses config from available files

@param   {array|string} directories - directories to search in
@param   {array} files - list of files to search for
@returns {array} - list of loaded configs in order of provided files
Loads and parses config from available files