src/loader.js
function(folder, options) {
  options = _.extend({
    matchFiles: /.+/ig,
    keepExtensions: false,
  }, options);

  return new Promise(function(resolve, reject) {
    var files = {};

    var walker = walk(folder, {
      followSymlinks: false
    });

    walker.on('file', function(file, stat) {
      var dirname = path.dirname(file),
        filename = path.join(path.relative(folder, dirname), path.basename(file));

      if (!filename.match(options.matchFiles)) {
        return;
      }

      // strip extension from filename?
      if (!options.keepExtensions) {
        var extname = path.extname(filename),
          filename = filename.substr(0, filename.length - extname.length);
      }
      
      files[filename] = file;
    });  

    walker.on('end', function() {
      resolve(files);
    });  
  });
}
function(folder, options) {
  options = _.extend({
    matchFiles: /.+/ig,
    keepExtensions: false,
  }, options);

  return new Promise(function(resolve, reject) {
    var files = {};

    var walker = walk(folder, {
      followSymlinks: false
    });

    walker.on('file', function(file, stat) {
      var dirname = path.dirname(file),
        filename = path.join(path.relative(folder, dirname), path.basename(file));

      if (!filename.match(options.matchFiles)) {
        return;
      }

      // strip extension from filename?
      if (!options.keepExtensions) {
        var extname = path.extname(filename),
          filename = filename.substr(0, filename.length - extname.length);
      }
      
      files[filename] = file;
    });  

    walker.on('end', function() {
      resolve(files);
    });  
  });
}
function ( folder , options ) { options = _ . extend ( { matchFiles : / .+ / ig , keepExtensions : false , } , options ) ; return new Promise ( function ( resolve , reject ) { var files = { } ; var walker = walk ( folder , { followSymlinks : false } ) ; walker . on ( 'file' , function ( file , stat ) { var dirname = path . dirname ( file ) , filename = path . join ( path . relative ( folder , dirname ) , path . basename ( file ) ) ; if ( ! filename . match ( options . matchFiles ) ) { return ; } // strip extension from filename? if ( ! options . keepExtensions ) { var extname = path . extname ( filename ) , filename = filename . substr ( 0 , filename . length - extname . length ) ; } files [ filename ] = file ; } ) ; walker . on ( 'end' , function ( ) { resolve ( files ) ; } ) ; } ) ; }
Walk given folder and its subfolders and return all files.

@param {String} folder Root folder.
@param {Object} [options] Additional options.
@param {String} [options.matchFiles] Filter files by this regex.
@param {String} [options.keepExtensions] If enabled then file names will keep their extensions.

@return {Promise}
@private
Walk given folder and its subfolders and return all files .