mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 11:35:55 +01:00
skipping minification if the minFile is already up-to-date - issue #322
This commit is contained in:
42
app.js
42
app.js
@@ -24,6 +24,7 @@
|
||||
nconf.argv().env();
|
||||
|
||||
var fs = require('fs'),
|
||||
async = require('async'),
|
||||
winston = require('winston'),
|
||||
pkg = require('./package.json'),
|
||||
path = require('path'),
|
||||
@@ -85,17 +86,44 @@
|
||||
'/src/jquery.form.js',
|
||||
'/src/utils.js'
|
||||
],
|
||||
minified;
|
||||
minified, mtime;
|
||||
toMinify = toMinify.map(function (jsPath) {
|
||||
return path.join(__dirname + '/public', jsPath);
|
||||
});
|
||||
minified = uglifyjs.minify(toMinify);
|
||||
fs.writeFile(path.join(__dirname, '/public/src', 'nodebb.min.js'), minified.code, function (err) {
|
||||
if (!err) {
|
||||
winston.info('Minified client-side libraries');
|
||||
async.parallel({
|
||||
mtime: function (next) {
|
||||
async.map(toMinify, fs.stat, function (err, stats) {
|
||||
async.reduce(stats, 0, function (memo, item, callback) {
|
||||
mtime = +new Date(item.mtime);
|
||||
callback(null, mtime > memo ? mtime : memo);
|
||||
}, next);
|
||||
});
|
||||
},
|
||||
minFile: function (next) {
|
||||
var minFile = path.join(__dirname, 'public/src/nodebb.min.js');
|
||||
if (!fs.existsSync(minFile)) {
|
||||
winston.warn('No minified client-side library found');
|
||||
return next(null, 0);
|
||||
}
|
||||
|
||||
fs.stat(minFile, function (err, stat) {
|
||||
next(err, +new Date(stat.mtime));
|
||||
});
|
||||
}
|
||||
}, function (err, results) {
|
||||
if (results.minFile > results.mtime) {
|
||||
winston.info('No changes to client-side libraries -- skipping minification');
|
||||
} else {
|
||||
winston.error('Problem minifying client-side libraries, exiting.');
|
||||
process.exit();
|
||||
winston.info('Minifying client-side libraries');
|
||||
minified = uglifyjs.minify(toMinify);
|
||||
fs.writeFile(path.join(__dirname, '/public/src', 'nodebb.min.js'), minified.code, function (err) {
|
||||
if (!err) {
|
||||
winston.info('Minified client-side libraries');
|
||||
} else {
|
||||
winston.error('Problem minifying client-side libraries, exiting.');
|
||||
process.exit();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user