Node.js based forum software built for the modern web
added new --from-file flag that will load js/css from the precompiled file instead of recompiling it on startup
Julian Lam1a90de7dd621
diff --git a/minifier.js b/minifier.jsindex c233aeff14..3336709780 100644--- a/minifier.js+++ b/minifier.js@@ -14,7 +14,10 @@ var uglifyjs = require('uglify-js'),/* Javascript */Minifier.js.minify = function (scripts, relativePath, minify, callback) {var options = {- compress: false+ compress: false,+ sourceMapURL: '/nodebb.min.js.map',+ outSourceMap: 'nodebb.min.js.map',+ sourceRoot: relativePath};scripts = scripts.filter(function(file) {@@ -22,9 +25,6 @@ Minifier.js.minify = function (scripts, relativePath, minify, callback) {});if (!minify) {- options.sourceMapURL = '/nodebb.min.js.map';- options.outSourceMap = 'nodebb.min.js.map';- options.sourceRoot = relativePath;options.mangle = false;options.prefix = 1;}diff --git a/src/meta.js b/src/meta.jsindex bafaaf3477..799fc1bb50 100644--- a/src/meta.js+++ b/src/meta.js@@ -33,6 +33,7 @@ var async = require('async'),};Meta.reload = function(callback) {+ console.log('reloading');async.series([async.apply(plugins.clearRequireCache),async.apply(plugins.reload),@@ -40,6 +41,7 @@ var async = require('async'),async.parallel([async.apply(Meta.js.minify, false),async.apply(Meta.css.minify),+ async.apply(Meta.sounds.init),async.apply(Meta.templates.compile),async.apply(auth.reloadRoutes),function(next) {@@ -49,6 +51,7 @@ var async = require('async'),], next);}], function(err) {+ console.log('yaaa I am here', err);if (!err) {emitter.emit('nodebb:ready');}diff --git a/src/meta/css.js b/src/meta/css.jsindex b462240031..8a20108143 100644--- a/src/meta/css.js+++ b/src/meta/css.js@@ -99,6 +99,30 @@ module.exports = function(Meta) {});};+ Meta.css.getFromFile = function(callback) {+ var cachePath = path.join(__dirname, '../../public/stylesheet.css'),+ acpCachePath = path.join(__dirname, '../../public/admin.css');+ fs.exists(cachePath, function(exists) {+ if (exists) {+ if (!cluster.isWorker || process.env.cluster_setup === 'true') {+ winston.info('[meta/css] (Experimental) Reading stylesheets from file');+ async.map([cachePath, acpCachePath], fs.readFile, function(err, files) {+ Meta.css.cache = files[0];+ Meta.css.acpCache = files[1];++ emitter.emit('meta:css.compiled');+ callback();+ });+ } else {+ callback();+ }+ } else {+ winston.warn('[meta/css] (Experimental) No stylesheets found on disk, re-minifying');+ Meta.css.minify.apply(Meta.css, arguments);+ }+ });+ };+function minify(source, paths, destination, callback) {var parser = new (less.Parser)({paths: pathsdiff --git a/src/meta/js.js b/src/meta/js.jsindex aac6edc86c..f586a362e4 100644--- a/src/meta/js.js+++ b/src/meta/js.js@@ -208,6 +208,30 @@ module.exports = function(Meta) {});};+ Meta.js.getFromFile = function(minify, callback) {+ var scriptPath = path.join(__dirname, '../../public/nodebb.min.js'),+ mapPath = path.join(__dirname, '../../public/nodebb.min.js.map');+ fs.exists(scriptPath, function(exists) {+ if (exists) {+ if (!cluster.isWorker || process.env.cluster_setup === 'true') {+ winston.info('[meta/js] (Experimental) Reading client-side scripts from file');+ async.map([scriptPath, mapPath], fs.readFile, function(err, files) {+ Meta.js.cache = files[0];+ Meta.js.map = files[1];++ emitter.emit('meta:js.compiled');+ callback();+ });+ } else {+ callback();+ }+ } else {+ winston.warn('[meta/js] (Experimental) No script file found on disk, re-minifying');+ Meta.js.minify.apply(Meta.js, arguments);+ }+ });+ };+function getPluginScripts(callback) {plugins.fireHook('filter:scripts.get', [], function(err, scripts) {if (err) {diff --git a/src/meta/sounds.js b/src/meta/sounds.jsindex 3d41504d4f..9d1eb3e9be 100644--- a/src/meta/sounds.js+++ b/src/meta/sounds.js@@ -7,6 +7,7 @@ var path = require('path'),rimraf = require('rimraf'),mkdirp = require('mkdirp'),async = require('async'),+ cluster = require('cluster'),plugins = require('../plugins'),db = require('../database');@@ -15,41 +16,51 @@ module.exports = function(Meta) {Meta.sounds = {};- Meta.sounds.init = function() {- var soundsPath = path.join(__dirname, '../../public/sounds');+ Meta.sounds.init = function(callback) {+ if (cluster.isWorker && process.env.cluster_setup === 'true') {+ var soundsPath = path.join(__dirname, '../../public/sounds');- plugins.fireHook('filter:sounds.get', [], function(err, filePaths) {- if (err) {- winston.error('Could not initialise sound files:' + err.message);- return;- }-- // Clear the sounds directory- async.series([- function(next) {- rimraf(soundsPath, next);- },- function(next) {- mkdirp(soundsPath, next);- }- ], function(err) {+ plugins.fireHook('filter:sounds.get', [], function(err, filePaths) {if (err) {winston.error('Could not initialise sound files:' + err.message);return;}- // Link paths- async.each(filePaths, function(filePath, next) {- fs[process.platform !== 'win32' ? 'symlink' : 'link'](filePath, path.join(soundsPath, path.basename(filePath)), 'file', next);- }, function(err) {- if (!err) {- winston.info('[sounds] Sounds OK');- } else {- winston.error('[sounds] Could not initialise sounds: ' + err.message);+ // Clear the sounds directory+ async.series([+ function(next) {+ rimraf(soundsPath, next);+ },+ function(next) {+ mkdirp(soundsPath, next);+ }+ ], function(err) {+ if (err) {+ winston.error('Could not initialise sound files:' + err.message);+ return;}++ // Link paths+ async.each(filePaths, function(filePath, next) {+ fs[process.platform !== 'win32' ? 'symlink' : 'link'](filePath, path.join(soundsPath, path.basename(filePath)), 'file', next);+ }, function(err) {+ if (!err) {+ winston.info('[sounds] Sounds OK');+ } else {+ winston.error('[sounds] Could not initialise sounds: ' + err.message);+ }++ if (typeof callback === 'function') {+ callback();+ }+ });});});- });+ } else {+ if (typeof callback === 'function') {+ callback();+ }+ }};Meta.sounds.getFiles = function(callback) {diff --git a/src/meta/templates.js b/src/meta/templates.jsindex 761ce809ac..2d93dfda60 100644--- a/src/meta/templates.js+++ b/src/meta/templates.js@@ -88,7 +88,7 @@ Templates.compile = function(callback) {if (paths[partial] && relativePath !== partial) {file = file.replace(regex, fs.readFileSync(paths[partial]).toString());} else {- winston.warn('[themes] Partial not loaded: ' + matches[1]);+ winston.warn('[meta/templates] Partial not loaded: ' + matches[1]);file = file.replace(regex, "");}}@@ -101,10 +101,10 @@ Templates.compile = function(callback) {fs.writeFile(path.join(viewsPath, relativePath), file, next);}, function(err) {if (err) {- winston.error('[themes] ' + err.stack);+ winston.error('[meta/templates] ' + err.stack);} else {compileIndex(viewsPath, function() {- winston.info('[themes] Successfully compiled templates.');+ winston.info('[meta/templates] Successfully compiled templates.');emitter.emit('templates:compiled');if (callback) {callback();diff --git a/src/webserver.js b/src/webserver.jsindex 518d0b9d14..95d32237cf 100644--- a/src/webserver.js+++ b/src/webserver.js@@ -46,12 +46,11 @@ if(nconf.get('ssl')) {// Preparation dependent on pluginsplugins.ready(function() {- meta.js.minify(app.enabled('minification'));- meta.css.minify();-- if (cluster.isWorker && process.env.cluster_setup === 'true') {- meta.sounds.init();- }+ async.parallel([+ async.apply(!nconf.get('from-file') ? meta.js.minify : meta.js.getFromFile, app.enabled('minification')),+ async.apply(!nconf.get('from-file') ? meta.css.minify : meta.css.getFromFile),+ async.apply(meta.sounds.init)+ ]);});async.parallel({