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) { 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) { fs.readFile(path.join(__dirname, '../public/less/install.less'), function (err, style) {
if (err) { if (err) {
return winston.error('Unable to read LESS install file: ', err); return winston.error('Unable to read LESS install file: ', err);
@ -145,11 +140,6 @@ function compileLess(callback) {
} }
function compileJS(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 scriptPath = path.join(__dirname, '..');
var result = uglify.minify(scripts.map(function (script) { var result = uglify.minify(scripts.map(function (script) {
return path.join(scriptPath, 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.isCluster = ports.length > 1 ? true : false;
process.env.port = ports[index]; 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, { var worker = fork('app.js', args, {
silent: silent, silent: silent,
env: process.env env: process.env

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

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

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

Loading…
Cancel
Save