From c32e6aaabb1da60edeeeb5531ae47f7481fed720 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Tue, 13 Dec 2016 15:43:20 +0300 Subject: [PATCH] use build module instead of forking --- app.js | 14 +++++++------- build.js | 8 +++++++- public/src/admin/appearance/themes.js | 5 +++-- src/meta/css.js | 17 +++++------------ src/socket.io/admin.js | 11 ++++------- 5 files changed, 26 insertions(+), 29 deletions(-) diff --git a/app.js b/app.js index 85abee4ab2..265df71850 100644 --- a/app.js +++ b/app.js @@ -75,7 +75,7 @@ if (nconf.get('setup') || nconf.get('install')) { } else if (nconf.get('reset')) { async.waterfall([ async.apply(require('./src/reset').reset), - async.apply(require('./build').build, true) + async.apply(require('./build').buildAll) ], function (err) { process.exit(err ? 1 : 0); }); @@ -180,12 +180,12 @@ function start() { }); async.waterfall([ - async.apply(db.init), + async.apply(db.init), function (next) { var meta = require('./src/meta'); async.parallel([ async.apply(db.checkCompatibility), - async.apply(meta.configs.init), + async.apply(meta.configs.init), function (next) { if (nconf.get('dep-check') === undefined || nconf.get('dep-check') !== false) { meta.dependencies.check(next); @@ -195,8 +195,8 @@ function start() { } }, function (next) { - require('./src/upgrade').check(next); - } + require('./src/upgrade').check(next); + } ], function (err) { next(err); }); @@ -257,7 +257,7 @@ function setup() { async.series([ async.apply(install.setup), async.apply(loadConfig), - async.apply(build.build, true) + async.apply(build.buildAll) ], function (err, data) { // Disregard build step data data = data[0]; @@ -302,7 +302,7 @@ function upgrade() { async.apply(db.init), async.apply(meta.configs.init), async.apply(upgrade.upgrade), - async.apply(build.build, true) + async.apply(build.buildAll) ], function (err) { if (err) { winston.error(err.stack); diff --git a/build.js b/build.js index 4ae2d34c77..a5174d2c70 100644 --- a/build.js +++ b/build.js @@ -5,13 +5,19 @@ var winston = require('winston'); var buildStart; +var valid = ['js', 'clientCSS', 'acpCSS', 'tpl']; + +exports.buildAll = function (callback) { + exports.build(valid.join(','), callback); +}; + exports.build = function build(targets, callback) { buildStart = Date.now(); var db = require('./src/database'); var meta = require('./src/meta'); var plugins = require('./src/plugins'); - var valid = ['js', 'clientCSS', 'acpCSS', 'tpl']; + targets = (targets === true ? valid : targets.split(',').filter(function (target) { return valid.indexOf(target) !== -1; diff --git a/public/src/admin/appearance/themes.js b/public/src/admin/appearance/themes.js index 0c71baa4c4..10daae4430 100644 --- a/public/src/admin/appearance/themes.js +++ b/public/src/admin/appearance/themes.js @@ -3,7 +3,7 @@ define('admin/appearance/themes', ['translator'], function (translator) { var Themes = {}; - + Themes.init = function () { $('#installed_themes').on('click', function (e) { var target = $(e.target), @@ -23,6 +23,7 @@ define('admin/appearance/themes', ['translator'], function (translator) { if (err) { return app.alertError(err.message); } + config['theme:id'] = themeId; highlightSelectedTheme(themeId); app.alert({ @@ -38,7 +39,7 @@ define('admin/appearance/themes', ['translator'], function (translator) { }); } }); - + translator.translate('[[admin/appearance/themes:revert-confirm]]', function (revert) { $('#revert_theme').on('click', function () { bootbox.confirm(revert, function (confirm) { diff --git a/src/meta/css.js b/src/meta/css.js index b9bc1787b6..0d63e09d6d 100644 --- a/src/meta/css.js +++ b/src/meta/css.js @@ -153,15 +153,13 @@ module.exports = function (Meta) { }; function minify(source, paths, destination, callback) { + callback = callback || function () {}; less.render(source, { paths: paths }, function (err, lessOutput) { if (err) { winston.error('[meta/css] Could not minify LESS/CSS: ' + err.message); - if (typeof callback === 'function') { - callback(err); - } - return; + return callback(err); } postcss([ autoprefixer, clean() ]).process(lessOutput.css).then(function (result) { @@ -171,19 +169,14 @@ module.exports = function (Meta) { Meta.css[destination] = result.css; // Save the compiled CSS in public/ so things like nginx can serve it - if (nconf.get('isPrimary') === 'true' && (nconf.get('local-assets') === undefined || nconf.get('local-assets') !== false)) { + if (nconf.get('local-assets') === undefined || nconf.get('local-assets') !== false) { return Meta.css.commitToFile(destination, function () { - if (typeof callback === 'function') { - callback(null, result.css); - } + callback(null, result.css); }); } - if (typeof callback === 'function') { - callback(null, result.css); - } + callback(null, result.css); }); - }); } diff --git a/src/socket.io/admin.js b/src/socket.io/admin.js index 141d567f11..f1b4e402c1 100644 --- a/src/socket.io/admin.js +++ b/src/socket.io/admin.js @@ -62,14 +62,11 @@ SocketAdmin.reload = function (socket, data, callback) { }; SocketAdmin.restart = function (socket, data, callback) { - // Rebuild assets and reload NodeBB - var child_process = require('child_process'); - var build_worker = child_process.fork('app.js', ['--build'], { - cwd: path.join(__dirname, '../../'), - stdio: 'pipe' - }); + require('../../build').buildAll(function (err) { + if (err) { + return callback(err) + } - build_worker.on('exit', function () { events.log({ type: 'build', uid: socket.uid,