mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 20:16:04 +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.branding = {};
|
||||||
Meta.css.defaultBranding = {};
|
Meta.css.defaultBranding = {};
|
||||||
|
|
||||||
Meta.css.minify = function() {
|
Meta.css.minify = function(callback) {
|
||||||
winston.info('[meta/css] Minifying LESS/CSS');
|
winston.info('[meta/css] Minifying LESS/CSS');
|
||||||
db.getObjectFields('config', ['theme:type', 'theme:id'], function(err, themeData) {
|
db.getObjectFields('config', ['theme:type', 'theme:id'], function(err, themeData) {
|
||||||
var themeId = (themeData['theme:id'] || 'nodebb-theme-vanilla'),
|
var themeId = (themeData['theme:id'] || 'nodebb-theme-vanilla'),
|
||||||
@@ -54,6 +54,9 @@ module.exports = function(Meta) {
|
|||||||
parser.parse(source, function(err, tree) {
|
parser.parse(source, function(err, tree) {
|
||||||
if (err) {
|
if (err) {
|
||||||
winston.error('[meta/css] Could not minify LESS/CSS: ' + err.message);
|
winston.error('[meta/css] Could not minify LESS/CSS: ' + err.message);
|
||||||
|
if (typeof callback === 'function') {
|
||||||
|
callback(err);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,6 +66,9 @@ module.exports = function(Meta) {
|
|||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
winston.error('[meta/css] Syntax Error: ' + err.message + ' - ' + path.basename(err.filename) + ' on line ' + err.line);
|
winston.error('[meta/css] Syntax Error: ' + err.message + ' - ' + path.basename(err.filename) + ' on line ' + err.line);
|
||||||
|
if (typeof callback === 'function') {
|
||||||
|
callback(err);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,6 +95,9 @@ module.exports = function(Meta) {
|
|||||||
|
|
||||||
winston.info('[meta/css] Done.');
|
winston.info('[meta/css] Done.');
|
||||||
emitter.emit('meta:css.compiled');
|
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', {
|
var minifier = Meta.js.minifierProc = fork('minifier.js', {
|
||||||
silent: true
|
silent: true
|
||||||
}),
|
}),
|
||||||
minifiedStream = minifier.stdio[1],
|
minifiedStream = minifier.stdio[1],
|
||||||
|
minifiedString = '',
|
||||||
mapStream = minifier.stdio[2],
|
mapStream = minifier.stdio[2],
|
||||||
|
mapString = '',
|
||||||
step = 0,
|
step = 0,
|
||||||
onComplete = function() {
|
onComplete = function() {
|
||||||
if (step === 0) {
|
if (step === 0) {
|
||||||
return step++;
|
return step++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Meta.js.cache = minifiedString;
|
||||||
|
Meta.js.map = mapString;
|
||||||
winston.info('[meta/js] Compilation complete');
|
winston.info('[meta/js] Compilation complete');
|
||||||
emitter.emit('meta:js.compiled');
|
emitter.emit('meta:js.compiled');
|
||||||
minifier.kill();
|
minifier.kill();
|
||||||
|
if (typeof callback === 'function') {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
minifiedStream.on('data', function(buffer) {
|
minifiedStream.on('data', function(buffer) {
|
||||||
Meta.js.cache += buffer.toString();
|
minifiedString += buffer.toString();
|
||||||
});
|
});
|
||||||
mapStream.on('data', function(buffer) {
|
mapStream.on('data', function(buffer) {
|
||||||
Meta.js.map += buffer.toString();
|
mapString += buffer.toString();
|
||||||
});
|
});
|
||||||
|
|
||||||
minifier.on('message', function(message) {
|
minifier.on('message', function(message) {
|
||||||
@@ -158,7 +165,11 @@ module.exports = function(Meta) {
|
|||||||
case 'error':
|
case 'error':
|
||||||
winston.error('[meta/js] Could not compile client-side scripts! ' + message.payload.message);
|
winston.error('[meta/js] Could not compile client-side scripts! ' + message.payload.message);
|
||||||
minifier.kill();
|
minifier.kill();
|
||||||
process.exit();
|
if (typeof callback === 'function') {
|
||||||
|
callback(err);
|
||||||
|
} else {
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -185,7 +196,6 @@ module.exports = function(Meta) {
|
|||||||
var jsPaths = scripts.map(function (jsPath) {
|
var jsPaths = scripts.map(function (jsPath) {
|
||||||
jsPath = path.normalize(jsPath);
|
jsPath = path.normalize(jsPath);
|
||||||
|
|
||||||
// if (jsPath.substring(0, 7) === 'plugins') {
|
|
||||||
var matches = _.map(plugins.staticDirs, function(realPath, mappedPath) {
|
var matches = _.map(plugins.staticDirs, function(realPath, mappedPath) {
|
||||||
if (jsPath.match(mappedPath)) {
|
if (jsPath.match(mappedPath)) {
|
||||||
return 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?');
|
winston.warn('[meta.scripts.get] Could not resolve mapped path: ' + jsPath + '. Are you sure it is defined by a plugin?');
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
// } else {
|
|
||||||
// return path.join(__dirname, '../..', jsPath);
|
|
||||||
// }
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Meta.js.scripts.plugin = jsPaths.filter(Boolean);
|
Meta.js.scripts.plugin = jsPaths.filter(Boolean);
|
||||||
|
|||||||
@@ -129,15 +129,18 @@ var fs = require('fs'),
|
|||||||
} else {
|
} else {
|
||||||
var router = express.Router();
|
var router = express.Router();
|
||||||
router.hotswapId = 'plugins';
|
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
|
// 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('action:app.load', router, middleware, controllers);
|
||||||
|
|
||||||
Plugins.fireHook('static:app.load', router, middleware, controllers, function() {
|
Plugins.fireHook('static:app.load', router, middleware, controllers, function() {
|
||||||
hotswap.replace('plugins', router);
|
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
|
// Reload meta data
|
||||||
Plugins.reload(function() {
|
Plugins.reload(function() {
|
||||||
|
|
||||||
if(!active) {
|
if(!active) {
|
||||||
Plugins.fireHook('action:plugin.activate', id);
|
Plugins.fireHook('action:plugin.activate', id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,8 +8,7 @@ var _ = require('underscore'),
|
|||||||
async = require('async'),
|
async = require('async'),
|
||||||
winston = require('winston'),
|
winston = require('winston'),
|
||||||
|
|
||||||
plugins = require('../plugins'),
|
plugins = require('../plugins');
|
||||||
pluginRoutes = [];
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = function(app, middleware, controllers) {
|
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() {
|
emitter.all(['templates:compiled', 'meta:js.compiled', 'meta:css.compiled'], function() {
|
||||||
winston.info('NodeBB Ready');
|
winston.info('NodeBB Ready');
|
||||||
emitter.emit('nodebb:ready');
|
emitter.emit('nodebb:ready');
|
||||||
|
emitter.removeAllListeners('templates:compiled').removeAllListeners('meta:js.compiled').removeAllListeners('meta:css.compiled');
|
||||||
});
|
});
|
||||||
|
|
||||||
emitter.on('templates:compiled', function() {
|
emitter.on('templates:compiled', function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user