mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 03:55:55 +01:00
added callbacks to css and js reloading, issue #2010
This commit is contained in:
@@ -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();
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -527,7 +530,6 @@ var fs = require('fs'),
|
||||
|
||||
// Reload meta data
|
||||
Plugins.reload(function() {
|
||||
|
||||
if(!active) {
|
||||
Plugins.fireHook('action:plugin.activate', id);
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user