mirror of
https://github.com/NuSkooler/enigma-bbs.git
synced 2025-06-10 14:44:40 +02:00
Major commit for new message network WIP
This commit is contained in:
parent
6750c05f07
commit
317af8419a
40 changed files with 1747 additions and 599 deletions
|
@ -14,38 +14,40 @@ exports.loadModuleEx = loadModuleEx;
|
|||
exports.loadModule = loadModule;
|
||||
exports.loadModulesForCategory = loadModulesForCategory;
|
||||
|
||||
|
||||
function loadModuleEx(options, cb) {
|
||||
assert(_.isObject(options));
|
||||
assert(_.isString(options.name));
|
||||
assert(_.isString(options.path));
|
||||
|
||||
var modConfig = _.isObject(Config[options.category]) ? Config[options.category][options.name] : null;
|
||||
const modConfig = _.isObject(Config[options.category]) ? Config[options.category][options.name] : null;
|
||||
|
||||
if(_.isObject(modConfig) && false === modConfig.enabled) {
|
||||
cb(new Error('Module "' + options.name + '" is disabled'));
|
||||
return;
|
||||
}
|
||||
|
||||
var mod;
|
||||
try {
|
||||
var mod = require(paths.join(options.path, options.name + '.js'));
|
||||
|
||||
if(!_.isObject(mod.moduleInfo)) {
|
||||
cb(new Error('Module is missing "moduleInfo" section'));
|
||||
return;
|
||||
}
|
||||
|
||||
if(!_.isFunction(mod.getModule)) {
|
||||
cb(new Error('Invalid or missing "getModule" method for module!'));
|
||||
return;
|
||||
}
|
||||
|
||||
// Safe configuration, if any, for convience to the module
|
||||
mod.runtime = { config : modConfig };
|
||||
|
||||
cb(null, mod);
|
||||
mod = require(paths.join(options.path, options.name + '.js'));
|
||||
} catch(e) {
|
||||
cb(e);
|
||||
}
|
||||
|
||||
if(!_.isObject(mod.moduleInfo)) {
|
||||
cb(new Error('Module is missing "moduleInfo" section'));
|
||||
return;
|
||||
}
|
||||
|
||||
if(!_.isFunction(mod.getModule)) {
|
||||
cb(new Error('Invalid or missing "getModule" method for module!'));
|
||||
return;
|
||||
}
|
||||
|
||||
// Ref configuration, if any, for convience to the module
|
||||
mod.runtime = { config : modConfig };
|
||||
|
||||
cb(null, mod);
|
||||
}
|
||||
|
||||
function loadModule(name, category, cb) {
|
||||
|
@ -61,7 +63,7 @@ function loadModule(name, category, cb) {
|
|||
});
|
||||
}
|
||||
|
||||
function loadModulesForCategory(category, cb) {
|
||||
function loadModulesForCategory(category, iterator) {
|
||||
var path = Config.paths[category];
|
||||
|
||||
fs.readdir(path, function onFiles(err, files) {
|
||||
|
@ -72,8 +74,7 @@ function loadModulesForCategory(category, cb) {
|
|||
|
||||
var filtered = files.filter(function onFilter(file) { return '.js' === paths.extname(file); });
|
||||
filtered.forEach(function onFile(file) {
|
||||
var modName = paths.basename(file, '.js');
|
||||
loadModule(paths.basename(file, '.js'), category, cb);
|
||||
loadModule(paths.basename(file, '.js'), category, iterator);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue