-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbundle.js
More file actions
123 lines (108 loc) · 4.66 KB
/
Copy pathbundle.js
File metadata and controls
123 lines (108 loc) · 4.66 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import { bundle } from "luabundle";
import * as fs from "fs";
import * as path from "path";
const bundleCiOnly = process.env.BUNDLE_CI === "1";
const bundleOutputPath = process.env.BUNDLE_OUTPUT_PATH;
const targetDir = bundleOutputPath
? path.dirname(path.resolve(bundleOutputPath))
: path.join(process.env.LOCALAPPDATA || "", "lua");
const targetPath = bundleOutputPath
? path.resolve(bundleOutputPath)
: path.join(targetDir, "Cheater_Detection.lua");
const prototypeRootMainPath = path.join(
process.env.LOCALAPPDATA || targetDir,
"lua",
"Main.lua"
);
function fileInfo(filePath) {
const stat = fs.statSync(filePath);
return `${filePath} (size=${stat.size}, mtime=${stat.mtime.toISOString()})`;
}
function bundleLua(entryPath) {
return bundle(entryPath, {
metadata: false,
expressionHandler: (module, expression) => {
const loc = expression.loc && expression.loc.start;
console.warn(
`WARNING: Non-literal require found in '${module.name}' at ${loc ? `${loc.line}:${loc.column}` : "unknown"}`
);
},
});
}
function writeLuaTarget(targetFilePath, content, label) {
fs.mkdirSync(path.dirname(targetFilePath), { recursive: true });
fs.writeFileSync(targetFilePath, content, "utf8");
console.log(`[BundleAndDeploy] DEPLOYED ${label}: ${fileInfo(targetFilePath)}`);
}
function copyLuaTarget(sourcePath, targetFilePath, label) {
fs.mkdirSync(path.dirname(targetFilePath), { recursive: true });
fs.copyFileSync(sourcePath, targetFilePath);
console.log(`[BundleAndDeploy] DEPLOYED ${label}: ${fileInfo(targetFilePath)}`);
}
function stripBomFromDir(dir) {
const entries = fs.readdirSync(dir, { withFileTypes: true });
for (const entry of entries) {
const fullPath = path.join(dir, entry.name);
if (entry.isDirectory()) {
stripBomFromDir(fullPath);
} else if (entry.isFile() && entry.name.endsWith(".lua")) {
const content = fs.readFileSync(fullPath, "utf8");
if (content.charCodeAt(0) === 0xfeff) {
fs.writeFileSync(fullPath, content.slice(1), "utf8");
console.log(`[BundleAndDeploy] Stripped BOM: ${fullPath}`);
}
}
}
}
function main() {
try {
stripBomFromDir("./Cheater_Detection");
// Bundle main Cheater_Detection
const bundledLua = bundleLua("./Cheater_Detection/Main.lua");
writeLuaTarget(targetPath, bundledLua, "main");
const embedKeyCount = (bundledLua.match(/\["7656119/g) || []).length;
if (embedKeyCount < 30000) {
console.error(
`[BundleAndDeploy] NOT DEPLOYED: bundle only contains ${embedKeyCount} embedded SteamIDs (expected ~34000). unified_embedded may be missing from the bundle.`
);
process.exitCode = 1;
return;
}
console.log(`[BundleAndDeploy] Embedded SteamIDs in bundle: ${embedKeyCount}`);
const prototypeEntryPath = "./Prototypes/Main.lua";
if (!bundleCiOnly && fs.existsSync(prototypeEntryPath)) {
const bundledPrototypeMain = bundleLua(prototypeEntryPath);
writeLuaTarget(prototypeRootMainPath, bundledPrototypeMain, "prototype entrypoint");
console.log(`[BundleAndDeploy] LOAD THIS FILE IN LMABOX: ${prototypeRootMainPath}`);
console.log("[BundleAndDeploy] NOTE: Run On Save writes to the Output panel, not the integrated terminal.");
} else {
console.log("[BundleAndDeploy] SKIP prototype entrypoint: Prototypes/Main.lua not found");
}
const simplePrototypeEntryPath = "./Prototypes/LocalBridgeSimple/Main.lua";
if (!bundleCiOnly && fs.existsSync(simplePrototypeEntryPath)) {
const bundledSimplePrototype = bundleLua(simplePrototypeEntryPath);
const simpleTargetPath = path.join(targetDir, "LocalBridgeSimple", "Main.lua");
writeLuaTarget(simpleTargetPath, bundledSimplePrototype, "prototype package");
}
// Copy all .lua files in Prototypes folder (they use global libs, no bundling needed)
const prototypesDir = "./Prototypes";
if (!bundleCiOnly && fs.existsSync(prototypesDir)) {
const prototypeFiles = fs
.readdirSync(prototypesDir)
.filter((file) => file.endsWith(".lua") && file !== "Main.lua");
for (const file of prototypeFiles) {
const sourcePath = path.join(prototypesDir, file);
const prototypeTargetPath = path.join(targetDir, file);
copyLuaTarget(sourcePath, prototypeTargetPath, `prototype ${file}`);
}
} else {
console.log("[BundleAndDeploy] SKIP prototypes: Prototypes directory not found");
}
process.exitCode = 0;
} catch (err) {
console.error(`[BundleAndDeploy] NOT DEPLOYED: ${err instanceof Error ? err.message : String(err)}`);
if (err instanceof Error && err.stack) console.error(err.stack);
process.exitCode = 1;
}
}
main();