123 lines
3.4 KiB
TypeScript
123 lines
3.4 KiB
TypeScript
import { test } from "vitest";
|
|
import {
|
|
Instance,
|
|
offlineAuth,
|
|
RuntimeManager,
|
|
getJavaComponent,
|
|
importModrinthModpack,
|
|
} from "../dist/index.js";
|
|
import path from "path";
|
|
import fs from "fs/promises";
|
|
|
|
const gameRoot = path.join(import.meta.dirname, "temp");
|
|
await fs.rm(path.join(gameRoot, "instances", "modrinth_update"), {
|
|
recursive: true,
|
|
force: true,
|
|
}); // remove instance dir each start to ensure that first launch works (else files from update will be used to start original)
|
|
|
|
test(
|
|
"update modrinth modpack",
|
|
{ timeout: 0, tags: ["modrinth"] },
|
|
async () => {
|
|
{
|
|
const modpack = await importModrinthModpack(
|
|
"https://cdn.modrinth.com/data/1KVo5zza/versions/JnvfUoIW/Fabulously.Optimized-v13.2.1.mrpack",
|
|
);
|
|
|
|
const javaManager = new RuntimeManager(path.join(gameRoot, "java"));
|
|
javaManager.on("progress", console.log);
|
|
const java = await javaManager.use(
|
|
await getJavaComponent(modpack.version),
|
|
);
|
|
|
|
const instance = new Instance({
|
|
auth: offlineAuth("player"),
|
|
paths: {
|
|
root: gameRoot,
|
|
instance: path.join(gameRoot, "instances", "modrinth_update"),
|
|
},
|
|
javaExecutable: java,
|
|
ram: { max: "4G", min: "4G" },
|
|
modrinth: modpack,
|
|
});
|
|
|
|
instance.on("progress", console.log);
|
|
instance.on("log", (step, msg) => {
|
|
console.log(`[${step}] ${msg}`);
|
|
});
|
|
|
|
await instance.install();
|
|
const p = await instance.launch();
|
|
|
|
p.stdout.on("data", (d: Buffer) => {
|
|
console.log(d.toString());
|
|
});
|
|
|
|
p.stderr.on("data", (d: Buffer) => {
|
|
console.log(d.toString());
|
|
});
|
|
|
|
await new Promise<void>((res) => {
|
|
p.on("error", (d: Buffer) => {
|
|
console.log(d.toString());
|
|
res();
|
|
});
|
|
p.on("close", () => {
|
|
console.log("closed");
|
|
res();
|
|
});
|
|
});
|
|
}
|
|
|
|
/*
|
|
to test that everything works i try to fully replace fabulously optimized by a completly different modpack
|
|
but it is intended to be used only to update from one modpack to its update
|
|
*/
|
|
const modpack = await importModrinthModpack(
|
|
"https://cdn.modrinth.com/data/l9m9tuPN/versions/M8j2mfGj/Zombie%20Invade%20100%20Days%202.3.mrpack",
|
|
"https://cdn.modrinth.com/data/1KVo5zza/versions/JnvfUoIW/Fabulously.Optimized-v13.2.1.mrpack",
|
|
);
|
|
const javaManager = new RuntimeManager(path.join(gameRoot, "java"));
|
|
javaManager.on("progress", console.log);
|
|
const java = await javaManager.use(await getJavaComponent(modpack.version));
|
|
|
|
const instance = new Instance({
|
|
auth: offlineAuth("player"),
|
|
paths: {
|
|
root: gameRoot,
|
|
instance: path.join(gameRoot, "instances", "modrinth_update"),
|
|
},
|
|
javaExecutable: java,
|
|
ram: { max: "4G", min: "4G" },
|
|
modrinth: modpack,
|
|
});
|
|
|
|
instance.on("progress", console.log);
|
|
instance.on("log", (step, msg) => {
|
|
console.log(`[${step}] ${msg}`);
|
|
});
|
|
|
|
await instance.install();
|
|
|
|
const p = await instance.launch();
|
|
|
|
p.stdout.on("data", (d: Buffer) => {
|
|
console.log(d.toString());
|
|
});
|
|
|
|
p.stderr.on("data", (d: Buffer) => {
|
|
console.log(d.toString());
|
|
});
|
|
|
|
await new Promise<void>((res) => {
|
|
p.on("error", (d: Buffer) => {
|
|
console.log(d.toString());
|
|
res();
|
|
});
|
|
p.on("close", () => {
|
|
console.log("closed");
|
|
res();
|
|
});
|
|
});
|
|
},
|
|
);
|