src/server/factory.js
function requireMethods(dir) {
  if (!dir) dir = getCallerDirname();

  var modules = {};

  fs
    .readdirSync(dir)
    .filter(function(filename) {
      return filename !== 'index.js';
    })
    .forEach(function(filename) {
      var filePath = path.join(dir, filename);
      var Stats = fs.lstatSync(filePath);
      var isLink = Stats.isSymbolicLink();
      var isDir = Stats.isDirectory();
      var isFile = Stats.isFile();
      var isJS = filename.indexOf('.js') > -1;

      if (!isLink && isDir) {
        modules[filename] = requireMethods(filePath);
      }

      else if (!isLink && isFile && isJS) {
        var entityName = filename.replace('.js', '');
        modules[entityName] = require(filePath);

        var hasES6Default = isObject(modules[entityName])
          && isFunction(modules[entityName].default);

        if (hasES6Default) {
          modules[entityName] = modules[entityName].default;
        }
      }
    });

  return modules;
}
function requireMethods(dir) {
  if (!dir) dir = getCallerDirname();

  var modules = {};

  fs
    .readdirSync(dir)
    .filter(function(filename) {
      return filename !== 'index.js';
    })
    .forEach(function(filename) {
      var filePath = path.join(dir, filename);
      var Stats = fs.lstatSync(filePath);
      var isLink = Stats.isSymbolicLink();
      var isDir = Stats.isDirectory();
      var isFile = Stats.isFile();
      var isJS = filename.indexOf('.js') > -1;

      if (!isLink && isDir) {
        modules[filename] = requireMethods(filePath);
      }

      else if (!isLink && isFile && isJS) {
        var entityName = filename.replace('.js', '');
        modules[entityName] = require(filePath);

        var hasES6Default = isObject(modules[entityName])
          && isFunction(modules[entityName].default);

        if (hasES6Default) {
          modules[entityName] = modules[entityName].default;
        }
      }
    });

  return modules;
}
function requireMethods ( dir ) { if ( ! dir ) dir = getCallerDirname ( ) ; var modules = { } ; fs . readdirSync ( dir ) . filter ( function ( filename ) { return filename !== 'index.js' ; } ) . forEach ( function ( filename ) { var filePath = path . join ( dir , filename ) ; var Stats = fs . lstatSync ( filePath ) ; var isLink = Stats . isSymbolicLink ( ) ; var isDir = Stats . isDirectory ( ) ; var isFile = Stats . isFile ( ) ; var isJS = filename . indexOf ( '.js' ) > - 1 ; if ( ! isLink && isDir ) { modules [ filename ] = requireMethods ( filePath ) ; } else if ( ! isLink && isFile && isJS ) { var entityName = filename . replace ( '.js' , '' ) ; modules [ entityName ] = require ( filePath ) ; var hasES6Default = isObject ( modules [ entityName ] ) && isFunction ( modules [ entityName ] . default ) ; if ( hasES6Default ) { modules [ entityName ] = modules [ entityName ] . default ; } } } ) ; return modules ; }
Recursively requires the modules in current dir.

@param  {String}  dir  The base directory to require entities from.
@return {Object}       An object with all the modules loaded.
Recursively requires the modules in current dir .