Merge pull request #316 from JohnMaguire2013/reloading

fixing some bugs related to loading
This commit is contained in:
reality 2013-03-21 07:28:17 -07:00
commit e811c47a63
2 changed files with 13 additions and 6 deletions

View File

@ -173,8 +173,10 @@ var commands = function(dbot) {
var moduleName = event.params[1]; var moduleName = event.params[1];
if(_.include(moduleNames, moduleName)) { if(_.include(moduleNames, moduleName)) {
var moduleDir = '../' + moduleName + '/'; var moduleDir = '../' + moduleName + '/';
var cacheKey = require.resolve(moduleDir + moduleName); try {
delete require.cache[cacheKey]; var cacheKey = require.resolve(moduleDir + moduleName);
delete require.cache[cacheKey];
} catch(err) { }
dbot.config.moduleNames = _.without(dbot.config.moduleNames, moduleName); dbot.config.moduleNames = _.without(dbot.config.moduleNames, moduleName);
dbot.reloadModules(); dbot.reloadModules();

13
run.js
View File

@ -155,9 +155,16 @@ DBot.prototype.reloadModules = function() {
this.instance.removeListeners(); this.instance.removeListeners();
moduleNames.each(function(name) { moduleNames.each(function(name) {
this.status[name] = true;
var moduleDir = './modules/' + name + '/'; var moduleDir = './modules/' + name + '/';
var cacheKey = require.resolve(moduleDir + name); try {
delete require.cache[cacheKey]; var cacheKey = require.resolve(moduleDir + name);
delete require.cache[cacheKey];
} catch(err) {
this.status[name] = 'Error loading module: ' + err + ' ' + err.stack.split('\n')[2].trim();
return;
}
try { try {
var webKey = require.resolve(moduleDir + 'web'); var webKey = require.resolve(moduleDir + 'web');
@ -167,8 +174,6 @@ DBot.prototype.reloadModules = function() {
delete require.cache[webKey]; delete require.cache[webKey];
} }
this.status[name] = true;
try { try {
// Load the module config data // Load the module config data
var config = {}; var config = {};