aboutsummaryrefslogtreecommitdiff
path: root/inf/build_payload.js
blob: 73a23441a2198683ddedb3121f6bd0ba54e28a16 (plain)
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
#!/usr/bin/env node

const fs = require("fs")
const uglify = require("uglify-js")
const path = require("path")
const zlib = require("zlib");

let payload_descriptor = fs.readFileSync(path.resolve(process.argv[2])).toString().split("\n");

if (payload_descriptor.includes("")) payload_descriptor.pop();

let full_payload = "";

for (file in payload_descriptor) {
    let fn = payload_descriptor[file];
    let fc = fs.readFileSync(fn, "utf8");

    full_payload += fc + "\n";
}

let minified = uglify.minify(
    full_payload,
    {
        mangle: {
            toplevel: true,
            properties: {keep_quoted: true}
        },
    }
).code;

let compressed = zlib.brotliCompressSync(minified);

console.error(`crc32: ${zlib.crc32(compressed)}`)

fs.writeFileSync(process.argv[3], compressed);
fs.writeFileSync(process.argv[4], minified);