-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-bundle.js
More file actions
44 lines (39 loc) · 1.39 KB
/
Copy pathbuild-bundle.js
File metadata and controls
44 lines (39 loc) · 1.39 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
import { readFileSync, writeFileSync } from "node:fs";
import { resolve } from "node:path";
const root = resolve(import.meta.dirname);
const sources = [
"js/constants.js",
"js/data/catalog-data.js",
"js/catalogs.js",
"js/data/ui-strings.js",
"js/i18n.js",
"js/utils.js",
"js/draft.js",
"js/storage.js",
"js/validation.js",
"js/exporters.js",
"js/importers.js",
"js/app.js",
"main.js"
];
const banner = `/* IntentionEditor 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(/^\s*export\s+\{[^}]*\}\s+from\s+["'][^"']+["'];?\s*$/gm, "")
.replace(/\bexport\s+function\s+/g, "function ")
.replace(/\bexport\s+const\s+/g, "const ")
.replace(/\bexport\s+let\s+/g, "let ")
.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 IntentionEditor/app.bundle.js");