Implemented JS minification (with uglify.js)

dependabot/npm_and_yarn/BuildServer/eslint-7.2.0
Inga 🏳‍🌈 8 years ago
parent 1c81e12fd8
commit 97bb6f3a33
  1. 3
      BuildServer/lib/tasks/packform.js
  2. 22
      BuildServer/lib/tasks/uglifyjs.js
  3. 36
      BuildServer/lib/tasks/uglifyjsall.js
  4. 1
      BuildServer/package.json

@ -4,6 +4,9 @@ const sequential = require('./sequential');
module.exports = (params, processor) => sequential({ module.exports = (params, processor) => sequential({
tasks: [ tasks: [
{
type: "uglifyjsall"
},
{ {
type: "zip", type: "zip",
params: { params: {

@ -0,0 +1,22 @@
"use strict";
const fs = require('fs');
const path = require('path');
const UglifyJS = require("uglify-js");
module.exports = (params, processor) => ({
process: () => {
const filePath = path.normalize(processor.context.exported + "/" + params.filename);
const result = UglifyJS.minify(filePath);
fs.writeFile(filePath, result.code, (err) => {
if (err) {
processor.onError("Unable to write uglified script for " + params.filename + ": " + err);
} else {
processor.onInfo("Saved uglified script for " + params.filename + "; uglified length: " + result.code.length);
}
processor.done();
});
}
});

@ -0,0 +1,36 @@
"use strict";
const glob = require('glob');
module.exports = (params, processor) => ({
process: () => {
if (processor.context.uglifyjsallDone) {
processor.onWarn("dotnetnunitall task is executed more than once; this is probably a bug in your mbs.json");
}
processor.context.uglifyjsallDone = true;
glob("**/*.js", {
dot: true,
cwd: processor.context.exported
}, (err, files) => {
if (err) {
processor.onError(err);
return processor.done();
}
return processor.processTask({
type: params.preventParallelTests ? "sequential" : "parallel",
params: {
tasks: files.map((file) => ({
name: file,
type: "uglifyjs",
params: {
filename: file
}
}))
}
}, processor.done.bind(processor));
});
}
});

@ -23,6 +23,7 @@
"recursive-tree-copy": "0.0.1", "recursive-tree-copy": "0.0.1",
"serve-favicon": "^2.3.2", "serve-favicon": "^2.3.2",
"serve-static": "^1.11.1", "serve-static": "^1.11.1",
"uglify-js": "^2.7.5",
"underscore": "^1.8.3" "underscore": "^1.8.3"
} }
} }

Loading…
Cancel
Save