Add getModulePaths to module_util, call it from events.registerModules
This commit is contained in:
parent
06e84eee94
commit
b383950314
|
@ -23,25 +23,28 @@ var self = module.exports = {
|
|||
eventEmitter.removeListener(eventName, listener);
|
||||
},
|
||||
registerModules: function() {
|
||||
var mods = fs.readdirSync(Config.config.paths.mods);
|
||||
const moduleUtil = require('./module_util.js');
|
||||
|
||||
mods.forEach(function(item) {
|
||||
var modPath = Config.config.paths.mods+item;
|
||||
if (item.substr(item.length-3) != '.js') {
|
||||
modPath += path.sep+item+'.js';
|
||||
}
|
||||
if (fs.existsSync(modPath)) {
|
||||
var module = require(modPath);
|
||||
|
||||
if (module.registerEvents !== undefined) {
|
||||
logger.log.debug(modPath+" calling registerEvents function");
|
||||
module.registerEvents();
|
||||
} else {
|
||||
logger.log.debug(modPath+" has no registerEvents function");
|
||||
moduleUtil.getModulePaths().forEach(function(modulePath) {
|
||||
var mods = fs.readdirSync(modulePath);
|
||||
mods.forEach(function(item) {
|
||||
var modPath = modulePath+item;
|
||||
if (item.substr(item.length-3) != '.js') {
|
||||
modPath += path.sep+item+'.js';
|
||||
}
|
||||
} else {
|
||||
logger.log.debug(modPath+" - file not found");
|
||||
}
|
||||
if (fs.existsSync(modPath)) {
|
||||
var module = require(modPath);
|
||||
|
||||
if (module.registerEvents !== undefined) {
|
||||
logger.log.debug(modPath+" calling registerEvents function");
|
||||
module.registerEvents();
|
||||
} else {
|
||||
logger.log.debug(modPath+" has no registerEvents function");
|
||||
}
|
||||
} else {
|
||||
logger.log.debug(modPath+" - file not found");
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ const async = require('async');
|
|||
exports.loadModuleEx = loadModuleEx;
|
||||
exports.loadModule = loadModule;
|
||||
exports.loadModulesForCategory = loadModulesForCategory;
|
||||
exports.getModulePaths = getModulePaths;
|
||||
|
||||
function loadModuleEx(options, cb) {
|
||||
assert(_.isObject(options));
|
||||
|
@ -25,7 +26,7 @@ function loadModuleEx(options, cb) {
|
|||
|
||||
if(_.isObject(modConfig) && false === modConfig.enabled) {
|
||||
const err = new Error(`Module "${options.name}" is disabled`);
|
||||
err.code = 'EENIGMODDISABLED';
|
||||
err.code = 'EENIGMODDISABLED';
|
||||
return cb(err);
|
||||
}
|
||||
|
||||
|
@ -36,7 +37,7 @@ function loadModuleEx(options, cb) {
|
|||
//
|
||||
let mod;
|
||||
let modPath = paths.join(options.path, `${options.name}.js`); // general case first
|
||||
try {
|
||||
try {
|
||||
mod = require(modPath);
|
||||
} catch(e) {
|
||||
if('MODULE_NOT_FOUND' === e.code) {
|
||||
|
@ -48,7 +49,7 @@ function loadModuleEx(options, cb) {
|
|||
}
|
||||
} else {
|
||||
return cb(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!_.isObject(mod.moduleInfo)) {
|
||||
|
@ -75,7 +76,7 @@ function loadModule(name, category, cb) {
|
|||
}
|
||||
|
||||
function loadModulesForCategory(category, iterator, complete) {
|
||||
|
||||
|
||||
fs.readdir(Config.paths[category], (err, files) => {
|
||||
if(err) {
|
||||
return iterator(err);
|
||||
|
@ -97,3 +98,9 @@ function loadModulesForCategory(category, iterator, complete) {
|
|||
});
|
||||
});
|
||||
}
|
||||
|
||||
function getModulePaths() {
|
||||
return [
|
||||
Config.paths.mods
|
||||
];
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue