-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-bundle.js
More file actions
33 lines (28 loc) · 1.11 KB
/
Copy pathbuild-bundle.js
File metadata and controls
33 lines (28 loc) · 1.11 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
import { readFileSync, writeFileSync } from "node:fs";
import { resolve } from "node:path";
const root = resolve(import.meta.dirname);
const sources = [
"js/indexer-shared.js",
"js/database-utils.js",
"js/localization.js",
"js/app.js"
];
const banner = `/* IntentionsDatabase bundle: generated by build-bundle.js */\n(() => {\n"use strict";\n`;
const footer = `\n})();\n`;
function transformModule(code) {
return code
.replace(/^\s*import\s+\{[^}]*\}\s+from\s+["'][^"']+["'];?\s*$/gm, "")
.replace(/^\s*import\s+[^;]+;\s*$/gm, "")
.replace(/\bexport\s+function\s+/g, "function ")
.replace(/\bexport\s+const\s+/g, "const ")
.replace(/\bexport\s+class\s+/g, "class ")
.replace(/\bexport\s+\{[\s\S]*?\};?\s*$/gm, "")
.trim();
}
const parts = sources.map(relativePath => {
const absolutePath = resolve(root, relativePath);
const content = readFileSync(absolutePath, "utf8");
return `\n/* ${relativePath} */\n${transformModule(content)}\n`;
});
writeFileSync(resolve(root, "app.bundle.js"), `${banner}${parts.join("\n")}${footer}`, "utf8");
console.log("Built IntentionsDatabase/app.bundle.js");