Allow overriding common directory for singular versions
This commit is contained in:
parent
6fddd8039f
commit
ee9841a1d2
21
index.ts
21
index.ts
|
@ -16,6 +16,9 @@ import type { PathLike } from "node:fs";
|
||||||
import { tmpdir } from "node:os";
|
import { tmpdir } from "node:os";
|
||||||
import { cwd } from "node:process";
|
import { cwd } from "node:process";
|
||||||
import { resolve } from "node:path";
|
import { resolve } from "node:path";
|
||||||
|
interface Override {
|
||||||
|
common?: string;
|
||||||
|
}
|
||||||
|
|
||||||
interface Info {
|
interface Info {
|
||||||
description: string;
|
description: string;
|
||||||
|
@ -23,6 +26,7 @@ interface Info {
|
||||||
name: string;
|
name: string;
|
||||||
url: string;
|
url: string;
|
||||||
versions: Array<[mcVersion: string, packFormat: number]>;
|
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: {
|
info: {
|
||||||
type: "string",
|
type: "string",
|
||||||
default: "info.json"
|
default: "info.json"
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
strict: true,
|
strict: true,
|
||||||
allowPositionals: true
|
allowPositionals: true
|
||||||
|
@ -96,6 +100,17 @@ const tempDir = await mkdtemp(`${tmpdir()}/${info.name.toLowerCase().replaceAll(
|
||||||
console.log("Temporary Directory:", tempDir);
|
console.log("Temporary Directory:", tempDir);
|
||||||
let totalSize = 0;
|
let totalSize = 0;
|
||||||
async function createVersion(mcVersion: string, packFormat: number) {
|
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);
|
console.log("Building %s (pf: %d)", mcVersion, packFormat);
|
||||||
const mcmeta = {
|
const mcmeta = {
|
||||||
pack: {
|
pack: {
|
||||||
|
@ -111,8 +126,8 @@ async function createVersion(mcVersion: string, packFormat: number) {
|
||||||
|
|
||||||
await mkdir(`${tempDir}/${mcVersion}`);
|
await mkdir(`${tempDir}/${mcVersion}`);
|
||||||
await writeFile(`${tempDir}/${mcVersion}/pack.mcmeta`, JSON.stringify(mcmeta, null, 4));
|
await writeFile(`${tempDir}/${mcVersion}/pack.mcmeta`, JSON.stringify(mcmeta, null, 4));
|
||||||
await copyFile(`${common}/pack.png`, `${tempDir}/${mcVersion}/pack.png`);
|
await copyFile(`${commonDir}/pack.png`, `${tempDir}/${mcVersion}/pack.png`);
|
||||||
await cp(`${common}/assets`, `${tempDir}/${mcVersion}/assets`, { recursive: true });
|
await cp(`${commonDir}/assets`, `${tempDir}/${mcVersion}/assets`, { recursive: true });
|
||||||
const zip = new AdmZip();
|
const zip = new AdmZip();
|
||||||
await zip.addLocalFolderPromise(`${tempDir}/${mcVersion}`, {});
|
await zip.addLocalFolderPromise(`${tempDir}/${mcVersion}`, {});
|
||||||
await zip.writeZipPromise(`${dist}/${info.name.replaceAll(" ", "")}-${mcVersion}.zip`);
|
await zip.writeZipPromise(`${dist}/${info.name.replaceAll(" ", "")}-${mcVersion}.zip`);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user