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 namestring Relative pathname. -
<static> configPath(name)
-
Return full path for a config file, based on environment.
Parameters:
Name Type Description namestring Full name (e.g. 'dir/name') -
<static> dispose(cb)
-
Dispose all initiated modules, that have a dispose function.
Parameters:
Name Type Description cbfunction 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 modsstring | Object <optional>
Module name or dictionary name list. Properties
Name Type Argument Description configObject <optional>
Optional init configuration. cbfunction Callback with initialized modules dictionary. Properties
Name Type Description $initErrorstring 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 filestring Relative pathname. cfgObject <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 namestring <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 filestring Relative pathname.