/usr/lib/nodejs/mithril/bundler/minify.js is in node-mithril 1.1.6-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | "use strict"
var http = require("https")
var querystring = require("querystring")
var fs = require("fs")
module.exports = function(input, output, options, done) {
function minify(input, output) {
var code = fs.readFileSync(input, "utf8")
var data = {
output_format: "json",
output_info: ["compiled_code", "warnings", "errors", "statistics"],
compilation_level: options.advanced ? "ADVANCED_OPTIMIZATIONS" : "SIMPLE_OPTIMIZATIONS",
warning_level: "default",
output_file_name: "default.js",
js_code: code,
}
var body = querystring.stringify(data)
var response = ""
var req = http.request({
method: "POST",
hostname: "closure-compiler.appspot.com",
path: "/compile",
headers: {
"Content-Type": "application/x-www-form-urlencoded;charset=utf-8",
"Content-Length": body.length
}
}, function(res) {
res.on("data", function(chunk) {
response += chunk.toString()
})
res.on("end", function() {
try {
var results = JSON.parse(response)
} catch(e) {
console.error(response);
throw e;
}
if (results.errors) {
for (var i = 0; i < results.errors.length; i++) console.log(results.errors[i])
}
else {
fs.writeFileSync(output, results.compiledCode, "utf8")
console.log("done")
if(typeof done === "function") done(results.statistics)
}
})
})
req.write(body)
req.end()
console.log("minifying...")
}
function run() {
minify(input, output)
}
run()
if (options && options.watch) fs.watchFile(input, run)
}
|