function read(filepath, options) {
  if ('string' !== is(filepath)) return fabricator(filepath, options);
  if (options.source) filepath = path.resolve(options.source, filepath);

  //
  // Check if the provided string is a JS file or when recursion is not allowed.
  //
  if (js(filepath) || options.recursive === false) return [
    init(filepath, path.basename(filepath, '.js'), options)
  ];

  //
  // Read the directory, only process files.
  //
  if (!fs.existsSync(filepath)) return false;
  return fs.readdirSync(filepath).map(function locate(file) {
    file = path.resolve(filepath, file);

    var stat = fs.statSync(file);

    if (stat.isDirectory() && fs.existsSync(path.join(file, 'index.js'))) {
      //
      // Use the directory name instead of `index` for name as it probably has
      // more meaning then just `index` as a name.
      //
      return init(path.join(file, 'index.js'), path.basename(file, '.js'), options);
    }

    //
    // Only allow JS files, init determines if it is a constructible instance.
    //
    if (!stat.isFile() || !js(file)) return;

    return init(file, path.basename(file, '.js'), options);
  });
}
function read(filepath, options) {
  if ('string' !== is(filepath)) return fabricator(filepath, options);
  if (options.source) filepath = path.resolve(options.source, filepath);

  //
  // Check if the provided string is a JS file or when recursion is not allowed.
  //
  if (js(filepath) || options.recursive === false) return [
    init(filepath, path.basename(filepath, '.js'), options)
  ];

  //
  // Read the directory, only process files.
  //
  if (!fs.existsSync(filepath)) return false;
  return fs.readdirSync(filepath).map(function locate(file) {
    file = path.resolve(filepath, file);

    var stat = fs.statSync(file);

    if (stat.isDirectory() && fs.existsSync(path.join(file, 'index.js'))) {
      //
      // Use the directory name instead of `index` for name as it probably has
      // more meaning then just `index` as a name.
      //
      return init(path.join(file, 'index.js'), path.basename(file, '.js'), options);
    }

    //
    // Only allow JS files, init determines if it is a constructible instance.
    //
    if (!stat.isFile() || !js(file)) return;

    return init(file, path.basename(file, '.js'), options);
  });
}
function read ( filepath , options ) { if ( 'string' !== is ( filepath ) ) return fabricator ( filepath , options ) ; if ( options . source ) filepath = path . resolve ( options . source , filepath ) ; // // Check if the provided string is a JS file or when recursion is not allowed. // if ( js ( filepath ) || options . recursive === false ) return [ init ( filepath , path . basename ( filepath , '.js' ) , options ) ] ; // // Read the directory, only process files. // if ( ! fs . existsSync ( filepath ) ) return false ; return fs . readdirSync ( filepath ) . map ( function locate ( file ) { file = path . resolve ( filepath , file ) ; var stat = fs . statSync ( file ) ; if ( stat . isDirectory ( ) && fs . existsSync ( path . join ( file , 'index.js' ) ) ) { // // Use the directory name instead of `index` for name as it probably has // more meaning then just `index` as a name. // return init ( path . join ( file , 'index.js' ) , path . basename ( file , '.js' ) , options ) ; } // // Only allow JS files, init determines if it is a constructible instance. // if ( ! stat . isFile ( ) || ! js ( file ) ) return ; return init ( file , path . basename ( file , '.js' ) , options ) ; } ) ; }
Read directory and initialize JavaScript files.

@param {String} filepath Full directory path.
@param {Object} options Additional configuration.
@return {Array} collection of constructor
@api private
Read directory and initialize JavaScript files .