more progress on #5211

v1.18.x
Julian Lam 8 years ago
parent 9bf0f6c5cd
commit 299fcb99f1

@ -124,11 +124,6 @@ function launch(req, res) {
}
function compileLess(callback) {
if ((nconf.get('from-file') || '').indexOf('less') !== -1) {
winston.info('LESS compilation skipped');
return callback(false);
}
fs.readFile(path.join(__dirname, '../public/less/install.less'), function (err, style) {
if (err) {
return winston.error('Unable to read LESS install file: ', err);
@ -145,11 +140,6 @@ function compileLess(callback) {
}
function compileJS(callback) {
if ((nconf.get('from-file') || '').indexOf('js') !== -1) {
winston.info('Client-side JS compilation skipped');
return callback(false);
}
var scriptPath = path.join(__dirname, '..');
var result = uglify.minify(scripts.map(function (script) {
return path.join(scriptPath, script);

@ -173,11 +173,6 @@ function forkWorker(index, isPrimary, isRestart) {
process.env.isCluster = ports.length > 1 ? true : false;
process.env.port = ports[index];
// If primary node restarts, there's no need to mark it primary any longer (isPrimary used on startup only)
if (isPrimary && isRestart) {
args.push('--from-file', 'js,clientLess,acpLess,tpl');
}
var worker = fork('app.js', args, {
silent: silent,
env: process.env

@ -81,25 +81,9 @@ module.exports = function (Meta) {
acpSource += '\n@import (inline) "..' + path.sep + 'public/vendor/colorpicker/colorpicker.css";\n';
acpSource += '\n@import (inline) "..' + path.sep + 'public/vendor/jquery/css/smoothness/jquery-ui.css";';
var fromFile = nconf.get('from-file') || '';
async.series([
function (next) {
if (fromFile.match('clientLess')) {
winston.info('[minifier] Compiling front-end LESS files skipped');
return Meta.css.getFromFile(path.join(__dirname, '../../public/stylesheet.css'), 'cache', next);
}
minify(source, paths, 'cache', next);
},
function (next) {
if (fromFile.match('acpLess')) {
winston.info('[minifier] Compiling ACP LESS files skipped');
return Meta.css.getFromFile(path.join(__dirname, '../../public/admin.css'), 'acpCache', next);
}
minify(acpSource, paths, 'acpCache', next);
}
async.apply(minify, source, paths, 'cache'),
async.apply(minify, acpSource, paths, 'acpCache')
], function (err, minified) {
if (err) {
return callback(err);
@ -109,8 +93,8 @@ module.exports = function (Meta) {
if (process.send) {
process.send({
action: 'css-propagate',
cache: fromFile.match('clientLess') ? Meta.css.cache : minified[0],
acpCache: fromFile.match('acpLess') ? Meta.css.acpCache : minified[1]
cache: minified[0],
acpCache: minified[1]
});
}
@ -122,6 +106,30 @@ module.exports = function (Meta) {
});
};
Meta.css.getFromFile = function(callback) {
async.series([
async.apply(Meta.css.loadFile, path.join(__dirname, '../../public/stylesheet.css'), 'cache'),
async.apply(Meta.css.loadFile, path.join(__dirname, '../../public/admin.css'), 'acpCache')
], function (err, minified) {
if (err) {
return callback(err);
}
// Propagate to other workers
if (process.send) {
process.send({
action: 'css-propagate',
cache: Meta.css.cache,
acpCache: Meta.css.acpCache
});
}
emitter.emit('meta:css.compiled');
callback();
});
};
function getStyleSource(files, prefix, extension, callback) {
var pluginDirectories = [],
source = '';
@ -166,7 +174,7 @@ module.exports = function (Meta) {
});
};
Meta.css.getFromFile = function (filePath, filename, callback) {
Meta.css.loadFile = function (filePath, filename, callback) {
winston.verbose('[meta/css] Reading stylesheet ' + filePath.split('/').pop() + ' from file');
fs.readFile(filePath, function (err, file) {

@ -17,14 +17,9 @@ var searchIndex = {};
Templates.compile = function (callback) {
callback = callback || function () {};
var fromFile = nconf.get('from-file') || '';
if (nconf.get('isPrimary') === 'false' || fromFile.match('tpl')) {
if (fromFile.match('tpl')) {
emitter.emit('templates:compiled');
winston.info('[minifier] Compiling templates skipped');
}
if (nconf.get('isPrimary') === 'false') {
emitter.emit('templates:compiled');
return callback();
}

@ -84,16 +84,8 @@ module.exports.listen = function (callback) {
function initializeNodeBB(callback) {
winston.info('initializing NodeBB ...');
var skipJS;
var fromFile = nconf.get('from-file') || '';
var middleware = require('./middleware');
if (fromFile.match('js')) {
winston.info('[minifier] Minifying client-side JS skipped');
skipJS = true;
}
async.waterfall([
async.apply(meta.themes.setupPaths),
function (next) {
@ -116,10 +108,13 @@ function initializeNodeBB(callback) {
},
function (next) {
async.series([
async.apply(meta.templates.compile),
async.apply(!skipJS ? meta.js.minify : meta.js.getFromFile, 'nodebb.min.js'),
async.apply(!skipJS ? meta.js.minify : meta.js.getFromFile, 'acp.min.js'),
async.apply(meta.css.minify),
async.apply(function(next) {
emitter.emit('templates:compiled');
setImmediate(next);
}),
async.apply(meta.js.getFromFile, 'nodebb.min.js'),
async.apply(meta.js.getFromFile, 'acp.min.js'),
async.apply(meta.css.getFromFile),
async.apply(meta.sounds.init),
async.apply(languages.init),
async.apply(meta.blacklist.load)

Loading…
Cancel
Save