56 lines
2.0 KiB
JavaScript
56 lines
2.0 KiB
JavaScript
import { spawn } from "node:child_process";
|
|
import { existsSync } from "node:fs";
|
|
import { mkdir, copyFile, readFile } from "node:fs/promises";
|
|
import path from "node:path";
|
|
const windows = process.platform === "win32";
|
|
const command = windows ? "gradlew.bat" : "sh";
|
|
const targets = process.argv.slice(2);
|
|
if (!targets.some((target) => !target.startsWith("-")))
|
|
targets.unshift(
|
|
":plugin:build",
|
|
":fabric:build",
|
|
":fabric261:build",
|
|
":fabric262:build",
|
|
);
|
|
const version = (await readFile("minecraft/build.gradle", "utf8")).match(
|
|
/version = '([^']+)'/,
|
|
)?.[1];
|
|
if (!version) throw new Error("Minecraft tools release version is missing");
|
|
await new Promise((resolve, reject) => {
|
|
const child = spawn(command, windows ? targets : ["./gradlew", ...targets], {
|
|
cwd: "minecraft",
|
|
stdio: "inherit",
|
|
shell: windows,
|
|
windowsHide: true,
|
|
});
|
|
child.on("error", reject);
|
|
child.on("exit", (code) =>
|
|
code === 0 ? resolve() : reject(new Error(`Gradle exited ${code}`)),
|
|
);
|
|
});
|
|
for (const [name, kind, minecraftVersion] of [
|
|
["plugin", "plugin", "1.21.11"],
|
|
["fabric", "fabric", "1.21.11"],
|
|
["fabric261", "fabric", "26.1"],
|
|
["fabric262", "fabric", "26.2"],
|
|
]) {
|
|
const directory = `public/tools/${kind === "fabric" ? "mod" : "plugin"}`;
|
|
const file = `minegeo-${kind}-${minecraftVersion}.jar`;
|
|
const buildRoot = process.env.MINEGEO_JAVA_BUILD_ROOT
|
|
? path.join(process.env.MINEGEO_JAVA_BUILD_ROOT, name)
|
|
: `minecraft/${name}/build`;
|
|
const artifact = path.join(buildRoot, "libs", file);
|
|
if (existsSync(artifact)) {
|
|
await mkdir(directory, { recursive: true });
|
|
await copyFile(artifact, `${directory}/${file}`);
|
|
const releaseFile =
|
|
kind === "plugin"
|
|
? `minegeo-plugin-${version}.jar`
|
|
: `minegeo-fabric-${minecraftVersion}-${version}.jar`;
|
|
await copyFile(artifact, `${directory}/${releaseFile}`);
|
|
console.log(
|
|
`Updated ${directory}/${releaseFile} and its compatibility download.`,
|
|
);
|
|
}
|
|
}
|