Skip to content

Node.js based forum software built for the modern web

added callbacks to css and js reloading, issue #2010

Julian Lam0c4a78869894
diff --git a/src/meta/css.js b/src/meta/css.js
index f60e320703..737f203ee5 100644
--- a/src/meta/css.js
+++ b/src/meta/css.js
@@ -20,7 +20,7 @@ module.exports = function(Meta) {
Meta.css.branding = {};
Meta.css.defaultBranding = {};
- Meta.css.minify = function() {
+ Meta.css.minify = function(callback) {
winston.info('[meta/css] Minifying LESS/CSS');
db.getObjectFields('config', ['theme:type', 'theme:id'], function(err, themeData) {
var themeId = (themeData['theme:id'] || 'nodebb-theme-vanilla'),
@@ -54,6 +54,9 @@ module.exports = function(Meta) {
parser.parse(source, function(err, tree) {
if (err) {
winston.error('[meta/css] Could not minify LESS/CSS: ' + err.message);
+ if (typeof callback === 'function') {
+ callback(err);
+ }
return;
}
@@ -63,6 +66,9 @@ module.exports = function(Meta) {
});
} catch (err) {
winston.error('[meta/css] Syntax Error: ' + err.message + ' - ' + path.basename(err.filename) + ' on line ' + err.line);
+ if (typeof callback === 'function') {
+ callback(err);
+ }
return;
}
@@ -89,6 +95,9 @@ module.exports = function(Meta) {
winston.info('[meta/css] Done.');
emitter.emit('meta:css.compiled');
+ if (typeof callback === 'function') {
+ callback();
+ }
});
});
};
diff --git a/src/meta/js.js b/src/meta/js.js
index 0625738db9..14e3112f19 100644
--- a/src/meta/js.js
+++ b/src/meta/js.js
@@ -117,28 +117,35 @@ module.exports = function(Meta) {
});
};
- Meta.js.minify = function(minify) {
+ Meta.js.minify = function(minify, callback) {
var minifier = Meta.js.minifierProc = fork('minifier.js', {
silent: true
}),
minifiedStream = minifier.stdio[1],
+ minifiedString = '',
mapStream = minifier.stdio[2],
+ mapString = '',
step = 0,
onComplete = function() {
if (step === 0) {
return step++;
}
+ Meta.js.cache = minifiedString;
+ Meta.js.map = mapString;
winston.info('[meta/js] Compilation complete');
emitter.emit('meta:js.compiled');
minifier.kill();
+ if (typeof callback === 'function') {
+ callback();
+ }
};
minifiedStream.on('data', function(buffer) {
- Meta.js.cache += buffer.toString();
+ minifiedString += buffer.toString();
});
mapStream.on('data', function(buffer) {
- Meta.js.map += buffer.toString();
+ mapString += buffer.toString();
});
minifier.on('message', function(message) {
@@ -158,7 +165,11 @@ module.exports = function(Meta) {
case 'error':
winston.error('[meta/js] Could not compile client-side scripts! ' + message.payload.message);
minifier.kill();
- process.exit();
+ if (typeof callback === 'function') {
+ callback(err);
+ } else {
+ process.exit(0);
+ }
break;
}
});
@@ -185,7 +196,6 @@ module.exports = function(Meta) {
var jsPaths = scripts.map(function (jsPath) {
jsPath = path.normalize(jsPath);
- // if (jsPath.substring(0, 7) === 'plugins') {
var matches = _.map(plugins.staticDirs, function(realPath, mappedPath) {
if (jsPath.match(mappedPath)) {
return mappedPath;
@@ -203,9 +213,6 @@ module.exports = function(Meta) {
winston.warn('[meta.scripts.get] Could not resolve mapped path: ' + jsPath + '. Are you sure it is defined by a plugin?');
return null;
}
- // } else {
- // return path.join(__dirname, '../..', jsPath);
- // }
});
Meta.js.scripts.plugin = jsPaths.filter(Boolean);
diff --git a/src/plugins.js b/src/plugins.js
index b2578ed51e..427816c7bc 100644
--- a/src/plugins.js
+++ b/src/plugins.js
@@ -129,15 +129,18 @@ var fs = require('fs'),
} else {
var router = express.Router();
router.hotswapId = 'plugins';
+ router.render = function() {
+ app.render.apply(app, arguments);
+ };
// Deprecated as of v0.5.0, remove this hook call for NodeBB v0.6.0-1
Plugins.fireHook('action:app.load', router, middleware, controllers);
Plugins.fireHook('static:app.load', router, middleware, controllers, function() {
hotswap.replace('plugins', router);
+ winston.info('[plugins] All plugins reloaded and rerouted');
+ callback();
});
-
- callback();
}
};
@@ -527,7 +530,6 @@ var fs = require('fs'),
// Reload meta data
Plugins.reload(function() {
-
if(!active) {
Plugins.fireHook('action:plugin.activate', id);
}
diff --git a/src/routes/plugins.js b/src/routes/plugins.js
index fd195ca3f2..17efdb8c53 100644
--- a/src/routes/plugins.js
+++ b/src/routes/plugins.js
@@ -8,8 +8,7 @@ var _ = require('underscore'),
async = require('async'),
winston = require('winston'),
- plugins = require('../plugins'),
- pluginRoutes = [];
+ plugins = require('../plugins');
module.exports = function(app, middleware, controllers) {
diff --git a/src/webserver.js b/src/webserver.js
index f2595ddabc..5c6f571372 100644
--- a/src/webserver.js
+++ b/src/webserver.js
@@ -110,6 +110,7 @@ if(nconf.get('ssl')) {
emitter.all(['templates:compiled', 'meta:js.compiled', 'meta:css.compiled'], function() {
winston.info('NodeBB Ready');
emitter.emit('nodebb:ready');
+ emitter.removeAllListeners('templates:compiled').removeAllListeners('meta:js.compiled').removeAllListeners('meta:css.compiled');
});
emitter.on('templates:compiled', function() {