mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 11:35:55 +01:00
committing of compiled js and css to file on startup
This commit is contained in:
6
.gitignore
vendored
6
.gitignore
vendored
@@ -26,3 +26,9 @@ pidfile
|
|||||||
# templates
|
# templates
|
||||||
/public/templates
|
/public/templates
|
||||||
/public/sounds
|
/public/sounds
|
||||||
|
|
||||||
|
# compiled files
|
||||||
|
/public/stylesheet.css
|
||||||
|
/public/admin.css
|
||||||
|
/public/nodebb.min.js
|
||||||
|
/public/nodebb.min.js.map
|
||||||
|
|||||||
@@ -63,10 +63,21 @@ module.exports = function(Meta) {
|
|||||||
minify(acpSource, paths, 'acpCache', next);
|
minify(acpSource, paths, 'acpCache', next);
|
||||||
}
|
}
|
||||||
], callback);
|
], callback);
|
||||||
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Meta.css.commitToFile = function(filename) {
|
||||||
|
winston.info('[meta/css] Committing stylesheet (' + filename + ') to disk');
|
||||||
|
fs.writeFile(path.join(__dirname, '../../public/' + (filename === 'acpCache' ? 'admin' : 'stylesheet') + '.css'), Meta.css[filename], function(err) {
|
||||||
|
if (!err) {
|
||||||
|
winston.info('[meta/css] Stylesheet (' + filename + ') committed to disk.');
|
||||||
|
} else {
|
||||||
|
winston.error('[meta/css] ' + err.message);
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function minify(source, paths, destination, callback) {
|
function minify(source, paths, destination, callback) {
|
||||||
var parser = new (less.Parser)({
|
var parser = new (less.Parser)({
|
||||||
paths: paths
|
paths: paths
|
||||||
@@ -104,6 +115,10 @@ module.exports = function(Meta) {
|
|||||||
|
|
||||||
winston.info('[meta/css] Done.');
|
winston.info('[meta/css] Done.');
|
||||||
emitter.emit('meta:css.compiled');
|
emitter.emit('meta:css.compiled');
|
||||||
|
|
||||||
|
// Save the compiled CSS in public/ so things like nginx can serve it
|
||||||
|
Meta.css.commitToFile(destination);
|
||||||
|
|
||||||
if (typeof callback === 'function') {
|
if (typeof callback === 'function') {
|
||||||
callback();
|
callback();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ var winston = require('winston'),
|
|||||||
os = require('os'),
|
os = require('os'),
|
||||||
nconf = require('nconf'),
|
nconf = require('nconf'),
|
||||||
cluster = require('cluster'),
|
cluster = require('cluster'),
|
||||||
|
fs = require('fs'),
|
||||||
|
|
||||||
plugins = require('../plugins'),
|
plugins = require('../plugins'),
|
||||||
emitter = require('../emitter'),
|
emitter = require('../emitter'),
|
||||||
@@ -148,6 +149,9 @@ module.exports = function(Meta) {
|
|||||||
cache: minifiedString,
|
cache: minifiedString,
|
||||||
map: mapString
|
map: mapString
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Save the minfile in public/ so things like nginx can serve it
|
||||||
|
Meta.js.commitToFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof callback === 'function') {
|
if (typeof callback === 'function') {
|
||||||
@@ -209,6 +213,21 @@ module.exports = function(Meta) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Meta.js.commitToFile = function() {
|
||||||
|
winston.info('[meta/js] Committing minfile to disk');
|
||||||
|
async.parallel([
|
||||||
|
async.apply(fs.writeFile, path.join(__dirname, '../../public/nodebb.min.js'), Meta.js.cache),
|
||||||
|
async.apply(fs.writeFile, path.join(__dirname, '../../public/nodebb.min.js.map'), Meta.js.map)
|
||||||
|
], function (err) {
|
||||||
|
if (!err) {
|
||||||
|
winston.info('[meta/js] Client-side minfile and mapping committed to disk.');
|
||||||
|
} else {
|
||||||
|
winston.error('[meta/js] ' + err.message);
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
function getPluginScripts(callback) {
|
function getPluginScripts(callback) {
|
||||||
plugins.fireHook('filter:scripts.get', [], function(err, scripts) {
|
plugins.fireHook('filter:scripts.get', [], function(err, scripts) {
|
||||||
if (err) callback(err, []);
|
if (err) callback(err, []);
|
||||||
|
|||||||
Reference in New Issue
Block a user