mirror of
https://github.com/NuSkooler/enigma-bbs.git
synced 2025-06-06 04:37:12 +02:00
ENiGMA 1/2 WILL USE SPACES FROM THIS POINT ON VS TABS
* Really just to make GitHub formatting happy. Arg.
This commit is contained in:
parent
5ddf04c882
commit
e9787cee3e
135 changed files with 27397 additions and 27397 deletions
|
@ -18,93 +18,93 @@ exports.loadModulesForCategory = loadModulesForCategory;
|
|||
exports.getModulePaths = getModulePaths;
|
||||
|
||||
function loadModuleEx(options, cb) {
|
||||
assert(_.isObject(options));
|
||||
assert(_.isString(options.name));
|
||||
assert(_.isString(options.path));
|
||||
assert(_.isObject(options));
|
||||
assert(_.isString(options.name));
|
||||
assert(_.isString(options.path));
|
||||
|
||||
const 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) {
|
||||
const err = new Error(`Module "${options.name}" is disabled`);
|
||||
err.code = 'EENIGMODDISABLED';
|
||||
return cb(err);
|
||||
}
|
||||
if(_.isObject(modConfig) && false === modConfig.enabled) {
|
||||
const err = new Error(`Module "${options.name}" is disabled`);
|
||||
err.code = 'EENIGMODDISABLED';
|
||||
return cb(err);
|
||||
}
|
||||
|
||||
//
|
||||
// Modules are allowed to live in /path/to/<moduleName>/<moduleName>.js or
|
||||
// simply in /path/to/<moduleName>.js. This allows for more advanced modules
|
||||
// to have their own containing folder, package.json & dependencies, etc.
|
||||
//
|
||||
let mod;
|
||||
let modPath = paths.join(options.path, `${options.name}.js`); // general case first
|
||||
try {
|
||||
mod = require(modPath);
|
||||
} catch(e) {
|
||||
if('MODULE_NOT_FOUND' === e.code) {
|
||||
modPath = paths.join(options.path, options.name, `${options.name}.js`);
|
||||
try {
|
||||
mod = require(modPath);
|
||||
} catch(e) {
|
||||
return cb(e);
|
||||
}
|
||||
} else {
|
||||
return cb(e);
|
||||
}
|
||||
}
|
||||
//
|
||||
// Modules are allowed to live in /path/to/<moduleName>/<moduleName>.js or
|
||||
// simply in /path/to/<moduleName>.js. This allows for more advanced modules
|
||||
// to have their own containing folder, package.json & dependencies, etc.
|
||||
//
|
||||
let mod;
|
||||
let modPath = paths.join(options.path, `${options.name}.js`); // general case first
|
||||
try {
|
||||
mod = require(modPath);
|
||||
} catch(e) {
|
||||
if('MODULE_NOT_FOUND' === e.code) {
|
||||
modPath = paths.join(options.path, options.name, `${options.name}.js`);
|
||||
try {
|
||||
mod = require(modPath);
|
||||
} catch(e) {
|
||||
return cb(e);
|
||||
}
|
||||
} else {
|
||||
return cb(e);
|
||||
}
|
||||
}
|
||||
|
||||
if(!_.isObject(mod.moduleInfo)) {
|
||||
return cb(new Error('Module is missing "moduleInfo" section'));
|
||||
}
|
||||
if(!_.isObject(mod.moduleInfo)) {
|
||||
return cb(new Error('Module is missing "moduleInfo" section'));
|
||||
}
|
||||
|
||||
if(!_.isFunction(mod.getModule)) {
|
||||
return cb(new Error('Invalid or missing "getModule" method for module!'));
|
||||
}
|
||||
if(!_.isFunction(mod.getModule)) {
|
||||
return cb(new Error('Invalid or missing "getModule" method for module!'));
|
||||
}
|
||||
|
||||
return cb(null, mod);
|
||||
return cb(null, mod);
|
||||
}
|
||||
|
||||
function loadModule(name, category, cb) {
|
||||
const path = Config().paths[category];
|
||||
const path = Config().paths[category];
|
||||
|
||||
if(!_.isString(path)) {
|
||||
return cb(new Error(`Not sure where to look for "${name}" of category "${category}"`));
|
||||
}
|
||||
if(!_.isString(path)) {
|
||||
return cb(new Error(`Not sure where to look for "${name}" of category "${category}"`));
|
||||
}
|
||||
|
||||
loadModuleEx( { name : name, path : path, category : category }, function loaded(err, mod) {
|
||||
return cb(err, mod);
|
||||
});
|
||||
loadModuleEx( { name : name, path : path, category : category }, function loaded(err, mod) {
|
||||
return cb(err, mod);
|
||||
});
|
||||
}
|
||||
|
||||
function loadModulesForCategory(category, iterator, complete) {
|
||||
|
||||
fs.readdir(Config().paths[category], (err, files) => {
|
||||
if(err) {
|
||||
return iterator(err);
|
||||
}
|
||||
fs.readdir(Config().paths[category], (err, files) => {
|
||||
if(err) {
|
||||
return iterator(err);
|
||||
}
|
||||
|
||||
const jsModules = files.filter(file => {
|
||||
return '.js' === paths.extname(file);
|
||||
});
|
||||
const jsModules = files.filter(file => {
|
||||
return '.js' === paths.extname(file);
|
||||
});
|
||||
|
||||
async.each(jsModules, (file, next) => {
|
||||
loadModule(paths.basename(file, '.js'), category, (err, mod) => {
|
||||
iterator(err, mod);
|
||||
return next();
|
||||
});
|
||||
}, err => {
|
||||
if(complete) {
|
||||
return complete(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
async.each(jsModules, (file, next) => {
|
||||
loadModule(paths.basename(file, '.js'), category, (err, mod) => {
|
||||
iterator(err, mod);
|
||||
return next();
|
||||
});
|
||||
}, err => {
|
||||
if(complete) {
|
||||
return complete(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function getModulePaths() {
|
||||
const config = Config();
|
||||
return [
|
||||
config.paths.mods,
|
||||
config.paths.loginServers,
|
||||
config.paths.contentServers,
|
||||
config.paths.scannerTossers,
|
||||
];
|
||||
const config = Config();
|
||||
return [
|
||||
config.paths.mods,
|
||||
config.paths.loginServers,
|
||||
config.paths.contentServers,
|
||||
config.paths.scannerTossers,
|
||||
];
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue