Rehashing new clients #92
authorDarren <darren@darrenwhitlen.com>
Tue, 23 Oct 2012 23:27:59 +0000 (00:27 +0100)
committerDarren <darren@darrenwhitlen.com>
Tue, 23 Oct 2012 23:27:59 +0000 (00:27 +0100)
server/kiwi.js
server/rehash.js [new file with mode: 0644]
server/weblistener.js

index 9cc2a1758e34e8dd769fce24358963a378b01677..87e83d799b524b4aaf6626cbb92d3c67f3502472 100755 (executable)
@@ -1,7 +1,8 @@
 var fs          = require('fs'),
     _           = require('underscore'),
     WebListener = require('./weblistener.js'),
-    config      = require('./configuration.js');
+    config      = require('./configuration.js'),
+    rehash      = require('./rehash.js');
 
 
 
@@ -91,6 +92,15 @@ process.stdin.on('data', function (buffered) {
 
             break;
 
+
+        case 'rehash':
+            (function () {
+                rehash.rehashAll();
+                console.log('Rehashed');
+            })();
+
+            break;
+
         default:
             console.log('Unrecognised command: ' + data);
     }
diff --git a/server/rehash.js b/server/rehash.js
new file mode 100644 (file)
index 0000000..0823eda
--- /dev/null
@@ -0,0 +1,31 @@
+var util   = require('util'),\r
+    events = require('events'),\r
+    _      = require('underscore');\r
+\r
+\r
+\r
+function Rehash() {}\r
+util.inherits(Rehash, events.EventEmitter);\r
+\r
+Rehash.prototype.rehashAll = function () {\r
+    var files = [\r
+        './client.js',\r
+        './clientcommands.js',\r
+        //'./configuration.js',\r
+        './httphandler.js',\r
+        './irc/commands.js',\r
+        './irc/connection.js',\r
+        './weblistener.js'\r
+    ];\r
+    \r
+    _.each(files, function (file) {\r
+        delete require.cache[require.resolve(file)];\r
+        require(file);\r
+    });\r
+\r
+    this.emit('rehashed', [files]);\r
+};\r
+\r
+\r
+\r
+module.exports = new Rehash();
\ No newline at end of file
index 7b72a73ead465f47bc8b39d11297e7c6b9f899e6..b02454241e94ba7074e11852f7e83a5572199cb2 100644 (file)
@@ -8,8 +8,17 @@ var ws          = require('socket.io'),
     url         = require('url'),
     _           = require('underscore'),
     config      = require('./configuration.js'),
-    Client   = require('./client.js').Client,
+    Client      = require('./client.js').Client,
+    HttpHandler = require('./httphandler.js').HttpHandler,
+    rehash      = require('./rehash.js');
+
+
+
+rehash.on('rehashed', function (files) {
+    Client = require('./client.js').Client;
     HttpHandler = require('./httphandler.js').HttpHandler;
+});
+
 
 // Instance of HttpHandler
 var http_handler;