|
|
@ -1,24 +1,29 @@
|
|
|
|
"use strict";
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
|
|
var uglifyjs = require('uglify-js'),
|
|
|
|
var uglifyjs = require('uglify-js');
|
|
|
|
less = require('less'),
|
|
|
|
var async = require('async');
|
|
|
|
async = require('async'),
|
|
|
|
var fs = require('fs');
|
|
|
|
fs = require('fs'),
|
|
|
|
var file = require('./src/file');
|
|
|
|
file = require('./src/file'),
|
|
|
|
|
|
|
|
crypto = require('crypto'),
|
|
|
|
|
|
|
|
utils = require('./public/src/utils'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Minifier = {
|
|
|
|
var Minifier = {
|
|
|
|
js: {}
|
|
|
|
js: {}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* Javascript */
|
|
|
|
/* Javascript */
|
|
|
|
Minifier.js.minify = function (scripts, minify, callback) {
|
|
|
|
Minifier.js.minify = function (scripts, minify, callback) {
|
|
|
|
|
|
|
|
|
|
|
|
scripts = scripts.filter(function(file) {
|
|
|
|
scripts = scripts.filter(function(file) {
|
|
|
|
return file && file.endsWith('.js');
|
|
|
|
return file && file.endsWith('.js');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
async.filter(scripts, file.exists, function(scripts) {
|
|
|
|
async.filter(scripts, function(script, next) {
|
|
|
|
|
|
|
|
file.exists(script, function(exists) {
|
|
|
|
|
|
|
|
if (!exists) {
|
|
|
|
|
|
|
|
console.warn('[minifier] file not found, ' + script);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
next(exists);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}, function(scripts) {
|
|
|
|
if (minify) {
|
|
|
|
if (minify) {
|
|
|
|
minifyScripts(scripts, callback);
|
|
|
|
minifyScripts(scripts, callback);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -54,7 +59,7 @@ function minifyScripts(scripts, callback) {
|
|
|
|
} catch(err) {
|
|
|
|
} catch(err) {
|
|
|
|
process.send({
|
|
|
|
process.send({
|
|
|
|
type: 'error',
|
|
|
|
type: 'error',
|
|
|
|
payload: err.message
|
|
|
|
message: err.message
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -64,7 +69,7 @@ function concatenateScripts(scripts, callback) {
|
|
|
|
if (err) {
|
|
|
|
if (err) {
|
|
|
|
process.send({
|
|
|
|
process.send({
|
|
|
|
type: 'error',
|
|
|
|
type: 'error',
|
|
|
|
payload: err
|
|
|
|
message: err.message
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|