FileLoader

FileLoader

Load files from directory to target object.

Constructor

new FileLoader(options)

Parameters:
Name Type Description
options Object

options

Properties
Name Type Description
directory String | Array

directories to be loaded

target Object

attach the target object from loaded files

match String

match the files when load, support glob, default to all js files

ignore String

ignore the files when load, support glob

initializer function

custom file exports, receive two parameters, first is the inject object(if not js file, will be content buffer), second is an options object that contain path

call Boolean

determine whether invoke when exports is function

override Boolean

determine whether override the property when get the same name

inject Object

an object that be the argument when invoke the function

filter function

a function that filter the exports which can be loaded

caseStyle String | function

set property's case when converting a filepath to property list.

Since:
  • 1.0.0
Source:

Methods

load() → {Object}

attach items to target object. Mapping the directory to properties. app/controller/group/repository.js => target.group.repository

Since:
  • 1.0.0
Source:

parse() → {Array}

Parse files from given directories, then return an items list, each item contains properties and exports.

For example, parse app/controller/group/repository.js

module.exports = app => {
  return class RepositoryController extends app.Controller {};
}

It returns a item

{
  properties: [ 'group', 'repository' ],
  exports: app => { ... },
}

Properties is an array that contains the directory of a filepath.

Exports depends on type, if exports is a function, it will be called. if initializer is specified, it will be called with exports for customizing.

Since:
  • 1.0.0
Source: