-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.js
More file actions
97 lines (82 loc) · 2.85 KB
/
Copy pathbuild.js
File metadata and controls
97 lines (82 loc) · 2.85 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
const fs = require("fs");
const path = require("path");
const archiver = require("archiver");
const modName = process.env.MOD_NAME;
if (!modName) {
console.error("Error: MOD_NAME environment variable must be set.");
process.exit(1);
}
// paths
const modPath = path.resolve(__dirname, "mods", modName);
const modinfoPath = path.join(modPath, "modinfo.ini");
// Determine version: prefer env VERSION, fallback to mod's package.json version
let version = process.env.VERSION;
if (!version) {
const modPkgPath = path.join(modPath, "package.json");
try {
const modPkg = JSON.parse(fs.readFileSync(modPkgPath, "utf-8"));
version = modPkg.version;
} catch (e) {
// ignore, will validate below
}
}
if (!version) {
console.error(
"Error: VERSION environment variable not set and no version found in the mod's package.json."
);
process.exit(1);
}
console.log(`🚀 Building mod "${modName}" version ${version}`);
// dist under the mod folder: mods/<modName>/dist
const distRoot = path.resolve(modPath, "dist");
if (!fs.existsSync(distRoot)) {
fs.mkdirSync(distRoot, { recursive: true });
}
// --- 1) Update package.json version ---
const modPkgPath = path.join(modPath, "package.json");
if (fs.existsSync(modPkgPath)) {
const modPkg = JSON.parse(fs.readFileSync(modPkgPath, "utf-8"));
modPkg.version = version;
fs.writeFileSync(modPkgPath, JSON.stringify(modPkg, null, 2) + "\n", "utf-8");
console.log(`✔ Updated package.json to version ${version}`);
}
// --- 2) Update modinfo.ini ---
if (fs.existsSync(modinfoPath)) {
let modinfoContent = fs.readFileSync(modinfoPath, "utf-8");
modinfoContent = modinfoContent.replace(
/^version=.*$/m,
`version=${version}`
);
fs.writeFileSync(modinfoPath, modinfoContent, "utf-8");
console.log(`✔ Updated modinfo.ini to version ${version}`);
} else {
console.warn(`⚠ No modinfo.ini found for ${modName}, skipping update.`);
}
// --- 3) Create ZIP archive ---
const zipFile = path.join(distRoot, `${modName}-v${version}.zip`);
const output = fs.createWriteStream(zipFile);
const archive = archiver("zip", { zlib: { level: 9 } });
output.on("close", () => {
console.log(`✔ Created ZIP archive: ${zipFile} (${archive.pointer()} bytes)`);
});
archive.on("error", (err) => {
throw err;
});
archive.pipe(output);
// include modinfo.ini (if exists)
if (fs.existsSync(modinfoPath)) {
archive.file(modinfoPath, { name: "modinfo.ini" });
}
// include all Lua scripts in reframework/autorun
const autorunPath = path.join(modPath, "reframework", "autorun");
if (fs.existsSync(autorunPath)) {
const files = fs.readdirSync(autorunPath).filter((f) => f.endsWith(".lua"));
files.forEach((file) => {
archive.file(path.join(autorunPath, file), {
name: `reframework/autorun/${file}`,
});
});
} else {
console.warn(`⚠ No reframework/autorun folder found for ${modName}`);
}
archive.finalize();