-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.ts
More file actions
105 lines (87 loc) · 3.95 KB
/
Copy pathbuild.ts
File metadata and controls
105 lines (87 loc) · 3.95 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import { readFileSync, writeFileSync, mkdirSync, existsSync } from "fs";
import { join } from "path";
const SRC_DIR = join(import.meta.dir, "src");
const DIST_DIR = join(import.meta.dir, "dist");
const OUTPUT = join(DIST_DIR, "universal-game-dumper.lua");
const MODULE_ORDER: { name: string; path: string }[] = [
{ name: "config", path: join(SRC_DIR, "config.lua") },
{ name: "utils", path: join(SRC_DIR, "utils.lua") },
{ name: "modules.structure", path: join(SRC_DIR, "modules", "structure.lua") },
{ name: "modules.remotes", path: join(SRC_DIR, "modules", "remotes.lua") },
{ name: "modules.scripts", path: join(SRC_DIR, "modules", "scripts.lua") },
{ name: "modules.data", path: join(SRC_DIR, "modules", "data.lua") },
{ name: "modules.assets", path: join(SRC_DIR, "modules", "assets.lua") },
{ name: "modules.analysis", path: join(SRC_DIR, "modules", "analysis.lua") },
{ name: "modules.reporter", path: join(SRC_DIR, "modules", "reporter.lua") },
{ name: "main", path: join(SRC_DIR, "main.lua") },
];
const REQUIRE_PATTERNS: { pattern: RegExp; moduleName: string }[] = [
{ pattern: /require\(script\.Parent\.config\)/g, moduleName: "config" },
{ pattern: /require\(script\.Parent\.utils\)/g, moduleName: "utils" },
{ pattern: /require\(script\.Parent\.modules\.structure\)/g, moduleName: "modules.structure" },
{ pattern: /require\(script\.Parent\.modules\.remotes\)/g, moduleName: "modules.remotes" },
{ pattern: /require\(script\.Parent\.modules\.scripts\)/g, moduleName: "modules.scripts" },
{ pattern: /require\(script\.Parent\.modules\.data\)/g, moduleName: "modules.data" },
{ pattern: /require\(script\.Parent\.modules\.assets\)/g, moduleName: "modules.assets" },
{ pattern: /require\(script\.Parent\.modules\.analysis\)/g, moduleName: "modules.analysis" },
{ pattern: /require\(script\.Parent\.modules\.reporter\)/g, moduleName: "modules.reporter" },
];
function toIdentifier(name: string): string {
return name.replace(/\./g, "_");
}
function wrapModule(name: string, source: string): string {
const id = toIdentifier(name);
const lines = [
`local function __module_${id}()`,
source
.split("\n")
.map((line) => ` ${line}`)
.join("\n"),
`end`,
``,
];
return lines.join("\n");
}
function patchMain(source: string): string {
let patched = source;
for (const { pattern, moduleName } of REQUIRE_PATTERNS) {
const id = toIdentifier(moduleName);
patched = patched.replace(pattern, `__module_${id}()`);
}
return patched;
}
function build(): void {
if (!existsSync(DIST_DIR)) {
mkdirSync(DIST_DIR, { recursive: true });
}
const chunks: string[] = [];
const timestamp = new Date().toISOString().replace("T", " ").slice(0, 19);
chunks.push(`-- universal-game-dumper (bundled)`);
chunks.push(`-- built: ${timestamp}`);
chunks.push(`-- do not edit this file directly — edit src/ and rebuild`);
chunks.push(``);
const modules = MODULE_ORDER.filter((m) => m.name !== "main");
const mainEntry = MODULE_ORDER.find((m) => m.name === "main")!;
let totalLines = 0;
for (const mod of modules) {
if (!existsSync(mod.path)) {
console.error(`[build] missing: ${mod.path}`);
process.exit(1);
}
const source = readFileSync(mod.path, "utf-8");
const wrapped = wrapModule(mod.name, source);
chunks.push(wrapped);
totalLines += source.split("\n").length;
}
const mainSource = readFileSync(mainEntry.path, "utf-8");
const patchedMain = patchMain(mainSource);
chunks.push(patchedMain);
totalLines += mainSource.split("\n").length;
const output = chunks.join("\n");
writeFileSync(OUTPUT, output, "utf-8");
const outputSize = Buffer.byteLength(output, "utf-8");
const kb = (outputSize / 1024).toFixed(1);
console.log(`[build] bundled ${modules.length + 1} files, ${totalLines} lines -> ${kb} KB`);
console.log(`[build] output: dist/universal-game-dumper.lua`);
}
build();