Allow overriding common directory for singular versions

This commit is contained in:
Donovan Daniels 2024-05-30 14:09:46 -05:00
parent 6fddd8039f
commit ee9841a1d2
Signed by: Donovan_DMC
GPG Key ID: 907D29CBFD6157BA

View File

@ -16,6 +16,9 @@ import type { PathLike } from "node:fs";
import { tmpdir } from "node:os";
import { cwd } from "node:process";
import { resolve } from "node:path";
interface Override {
common?: string;
}
interface Info {
description: string;
@ -23,6 +26,7 @@ interface Info {
name: string;
url: string;
versions: Array<[mcVersion: string, packFormat: number]>;
overrides?: Record<string, Override>;
}
@ -51,7 +55,7 @@ const { values: { indir: inDir, common: commonDir, revision: rev, outdir: outDir
info: {
type: "string",
default: "info.json"
}
},
},
strict: true,
allowPositionals: true
@ -96,6 +100,17 @@ const tempDir = await mkdtemp(`${tmpdir()}/${info.name.toLowerCase().replaceAll(
console.log("Temporary Directory:", tempDir);
let totalSize = 0;
async function createVersion(mcVersion: string, packFormat: number) {
let commonDir = common;
if (info.overrides) {
const override = info.overrides[mcVersion];
if (override?.common) {
commonDir = resolve(dir, override.common);
if (!await directoryExists(commonDir)) {
console.log(`[Override:${mcVersion}] Specified common directory "${override.common}" (${commonDir}) does not exist.`);
process.exit(1);
}
}
}
console.log("Building %s (pf: %d)", mcVersion, packFormat);
const mcmeta = {
pack: {
@ -111,8 +126,8 @@ async function createVersion(mcVersion: string, packFormat: number) {
await mkdir(`${tempDir}/${mcVersion}`);
await writeFile(`${tempDir}/${mcVersion}/pack.mcmeta`, JSON.stringify(mcmeta, null, 4));
await copyFile(`${common}/pack.png`, `${tempDir}/${mcVersion}/pack.png`);
await cp(`${common}/assets`, `${tempDir}/${mcVersion}/assets`, { recursive: true });
await copyFile(`${commonDir}/pack.png`, `${tempDir}/${mcVersion}/pack.png`);
await cp(`${commonDir}/assets`, `${tempDir}/${mcVersion}/assets`, { recursive: true });
const zip = new AdmZip();
await zip.addLocalFolderPromise(`${tempDir}/${mcVersion}`, {});
await zip.writeZipPromise(`${dist}/${info.name.replaceAll(" ", "")}-${mcVersion}.zip`);