2018-05-23 21:36:29 +02:00
|
|
|
/**
|
|
|
|
* @author n1474335 [n1474335@gmail.com]
|
|
|
|
* @copyright Crown Copyright 2016
|
|
|
|
* @license Apache-2.0
|
|
|
|
*/
|
|
|
|
|
2019-11-01 07:18:54 +01:00
|
|
|
import OperationError from "../errors/OperationError.mjs";
|
2019-07-09 13:23:59 +02:00
|
|
|
import Operation from "../Operation.mjs";
|
2019-11-01 07:18:54 +01:00
|
|
|
import Terser from "terser";
|
2018-05-23 21:36:29 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* JavaScript Minify operation
|
|
|
|
*/
|
|
|
|
class JavaScriptMinify extends Operation {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* JavaScriptMinify constructor
|
|
|
|
*/
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
|
|
|
|
this.name = "JavaScript Minify";
|
|
|
|
this.module = "Code";
|
|
|
|
this.description = "Compresses JavaScript code.";
|
|
|
|
this.inputType = "string";
|
|
|
|
this.outputType = "string";
|
|
|
|
this.args = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string} input
|
|
|
|
* @param {Object[]} args
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
run(input, args) {
|
2019-11-01 07:18:54 +01:00
|
|
|
const result = Terser.minify(input);
|
|
|
|
if (result.error) {
|
|
|
|
throw new OperationError(`Error minifying JavaScript. (${result.error})`);
|
|
|
|
}
|
|
|
|
return result.code;
|
2018-05-23 21:36:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
export default JavaScriptMinify;
|