forked from Redrrx/browser-js-dumper
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.js
More file actions
53 lines (46 loc) · 1.38 KB
/
build.js
File metadata and controls
53 lines (46 loc) · 1.38 KB
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
#!/usr/bin/env node
"use strict";
const fs = require("fs");
const path = require("path");
const SRC_ORDER = [
"src/utils.js",
"src/state.js",
"src/walker.js",
"src/constants/canvas.js",
"src/constants/date.js",
"src/constants/fonts.js",
"src/constants/math.js",
"src/constants/media-queries.js",
"src/constants/permissions.js",
"src/constants/webgl.js",
"src/constants/integrity.js",
"src/constants/css.js",
"src/constants/wasm-features.js",
"src/constants/drm.js",
"src/constants/gpu-fp.js",
"src/activators.js",
"src/integrity.js",
"src/scanner.js",
"src/cache.js",
"src/renderer.js",
"src/sidebar.js",
"src/ui.js",
];
const bundle = SRC_ORDER.map((f) => {
const src = fs.readFileSync(path.join(__dirname, f), "utf8");
const bar = "─".repeat(71);
return `// ${bar}\n// ${f}\n// ${bar}\n\n${src}`;
}).join("\n");
const script = `<script>\n(function () {\n'use strict';\n\n${bundle}\n\n})();\n</script>`;
let template = fs.readFileSync(path.join(__dirname, "index.html"), "utf8");
if (!template.includes("<!-- BUILD:JS -->")) {
template = template.replace(
/<script>[\s\S]*?<\/script>/,
"<!-- BUILD:JS -->",
);
}
const out = template.replace("<!-- BUILD:JS -->", script);
fs.writeFileSync(path.join(__dirname, "index.html"), out);
console.log(
`Built index.html (${(out.length / 1024).toFixed(1)} KB) [${SRC_ORDER.length} modules]`,
);