mirror of
https://github.com/NuSkooler/enigma-bbs.git
synced 2025-06-06 20:55:30 +02:00
+ Concept of PluginModule and inherited classes such as ServerModule, MenuModule, ...
* Client now tracks current menu module. Auto detach events, etc.
This commit is contained in:
parent
d3e35d286a
commit
f7462bbbdd
11 changed files with 226 additions and 60 deletions
|
@ -1,85 +0,0 @@
|
|||
/* jslint node: true */
|
||||
'use strict';
|
||||
|
||||
var fs = require('fs');
|
||||
var paths = require('path');
|
||||
var conf = require('./config.js');
|
||||
var miscUtil = require('./misc_util.js');
|
||||
var logger = require('./logger.js');
|
||||
|
||||
// exports
|
||||
exports.loadModule = loadModule;
|
||||
exports.loadModulesForCategory = loadModulesForCategory;
|
||||
|
||||
exports.goto = goto;
|
||||
|
||||
function loadModule(name, category, cb) {
|
||||
var config = conf.config;
|
||||
var path = config.paths[category];
|
||||
|
||||
if(!path) {
|
||||
cb(new Error('not sure where to look for "' + name + '" of category "' + category + '"'));
|
||||
return;
|
||||
}
|
||||
|
||||
// update conf to point at this module's section, if any
|
||||
config = config[category] ? config[category][name] : null;
|
||||
|
||||
if(config && false === config.enabled) {
|
||||
cb(new Error('module "' + name + '" is disabled'));
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
var mod = require(paths.join(path, name + '.js'));
|
||||
|
||||
if(!mod.moduleInfo) {
|
||||
cb(new Error('module is missing \'moduleInfo\' section'));
|
||||
return;
|
||||
}
|
||||
|
||||
mod.runtime = {
|
||||
config : config
|
||||
};
|
||||
|
||||
cb(null, mod);
|
||||
} catch(e) {
|
||||
cb(e);
|
||||
}
|
||||
};
|
||||
|
||||
function loadModulesForCategory(category, cb) {
|
||||
var path = conf.config.paths[category];
|
||||
|
||||
fs.readdir(path, function onFiles(err, files) {
|
||||
if(err) {
|
||||
cb(err);
|
||||
return;
|
||||
}
|
||||
|
||||
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);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
function goto(name, client, cb) {
|
||||
// Assign a default missing module handler callback if none was provided
|
||||
cb = miscUtil.valueWithDefault(cb, client.defaultHandlerMissingMod());
|
||||
|
||||
loadModule(name, 'mods', function onMod(err, mod) {
|
||||
if(err) {
|
||||
cb(err);
|
||||
} else {
|
||||
try {
|
||||
logger.log.debug({ moduleName : name }, 'Goto module');
|
||||
mod.entryPoint(client);
|
||||
} catch (e) {
|
||||
cb(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue