|
|
|
@ -1,3 +1,5 @@
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
var uglifyjs = require('uglify-js'),
|
|
|
|
|
less = require('less'),
|
|
|
|
|
async = require('async'),
|
|
|
|
@ -9,10 +11,21 @@ var uglifyjs = require('uglify-js'),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* Javascript */
|
|
|
|
|
Minifier.js.minify = function (scripts, callback) {
|
|
|
|
|
Minifier.js.minify = function (scripts, minify, callback) {
|
|
|
|
|
var options = {};
|
|
|
|
|
|
|
|
|
|
if (!minify) {
|
|
|
|
|
options.outSourceMap = 'nodebb.min.js.map';
|
|
|
|
|
options.mangle = false;
|
|
|
|
|
options.compress = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
var minified = uglifyjs.minify(scripts);
|
|
|
|
|
callback(minified.code);
|
|
|
|
|
var minified = uglifyjs.minify(scripts, options);
|
|
|
|
|
callback({
|
|
|
|
|
js: minified.code,
|
|
|
|
|
map: minified.map
|
|
|
|
|
});
|
|
|
|
|
} catch(err) {
|
|
|
|
|
process.send({
|
|
|
|
|
action: 'error',
|
|
|
|
@ -21,22 +34,22 @@ Minifier.js.minify = function (scripts, callback) {
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Minifier.js.concatenate = function(scripts, callback) {
|
|
|
|
|
async.map(scripts, function(path, next) {
|
|
|
|
|
fs.readFile(path, { encoding: 'utf-8' }, next);
|
|
|
|
|
}, function(err, contents) {
|
|
|
|
|
if (err) {
|
|
|
|
|
process.send({
|
|
|
|
|
action: 'error',
|
|
|
|
|
error: err
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
callback(contents.reduce(function(output, src) {
|
|
|
|
|
return output.length ? output + ';\n' + src : src;
|
|
|
|
|
}, ''));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
// Minifier.js.concatenate = function(scripts, callback) {
|
|
|
|
|
// async.map(scripts, function(path, next) {
|
|
|
|
|
// fs.readFile(path, { encoding: 'utf-8' }, next);
|
|
|
|
|
// }, function(err, contents) {
|
|
|
|
|
// if (err) {
|
|
|
|
|
// process.send({
|
|
|
|
|
// action: 'error',
|
|
|
|
|
// error: err
|
|
|
|
|
// });
|
|
|
|
|
// } else {
|
|
|
|
|
// callback(contents.reduce(function(output, src) {
|
|
|
|
|
// return output.length ? output + ';\n' + src : src;
|
|
|
|
|
// }, ''));
|
|
|
|
|
// }
|
|
|
|
|
// });
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
process.on('message', function(payload) {
|
|
|
|
|
var executeCallback = function(data) {
|
|
|
|
@ -47,12 +60,8 @@ process.on('message', function(payload) {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
switch(payload.action) {
|
|
|
|
|
case 'js.minify':
|
|
|
|
|
Minifier.js.minify(payload.scripts, executeCallback);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'js.concatenate':
|
|
|
|
|
Minifier.js.concatenate(payload.scripts, executeCallback);
|
|
|
|
|
case 'js':
|
|
|
|
|
Minifier.js.minify(payload.scripts, payload.minify, executeCallback);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|