Module: lib/index

Modules loader, featuring filesystem overlay, configuration support, init/dispose management and helpers.

Methods


<static> config(name)

Load a config file, considering environment variables.
Parameters:
Name Type Description
name string Relative pathname.

<static> configPath(name)

Return full path for a config file, based on environment.
Parameters:
Name Type Description
name string Full name (e.g. 'dir/name')

<static> dispose(cb)

Dispose all initiated modules, that have a dispose function.
Parameters:
Name Type Description
cb function Callback

<static> init( [mods], cb)

Initialize one or more modules. If [mods] is empty, execute bootstrap (first time) or init previous loaded modules.
Parameters:
Name Type Argument Description
mods string | Object <optional>
Module name or dictionary name list.
Properties
Name Type Argument Description
config Object <optional>
Optional init configuration.
cb function Callback with initialized modules dictionary.
Properties
Name Type Description
$initError string Undefined or error information.
Example
mbot.init({
     'util/db': { config: {...} }
})

<static> load(file [, cfg])

Load module(s). Encapsulate 'require', use filesystem overlay and save init/dispose callback. Usage:
(a) file name (optional init config): return one module object;
(b) directory name (e.g. 'bot_modules'): use 'loader' subkey information in config/index.{env}.json, and return a modules dictionary. Wildcard "*" include subdirectories, while "." load only current directory.
Parameters:
Name Type Argument Description
file string Relative pathname.
cfg Object <optional>
Optional Configuration

<static> logger( [name])

Use/Create a shared logger, with automatic dispose.
If file 'config/name.{env}.json' exists, use 'logger' configuration key.
Parameters:
Name Type Argument Description
name string <optional>
Logger name (default: 'index')
Example
var log = mbot.logger('dir/name');

<static> path(file)

Return full path for a file, within a filesystem overlay between application (precedence) and framework files.
Parameters:
Name Type Description
file string Relative pathname.