Compare commits

...

3 Commits

2 changed files with 33 additions and 12 deletions

View File

@ -9,8 +9,9 @@ build-packs
### Arguments
* `-i` or `--indir` - The input directory. Defaults to the current working directory.
* `-o` or `--outdir` - The directory to output the compiled packs to. Defaults to dist.
* `-c` or `--common` - The common directory containing shared files. Defailts to common.
* `-d` or `--data` - The data directory containing the data files. Defailts to data.
* `-r` or `--revision` - The revision/version. Defaults to `git rev-parse --short HEAD` if .git exists, else required.
* `-i` or `--info` - The info file. Defaults to info.json.
### Info File
An `info.json` file should be present in the input directory. This file should contain the following fields:
@ -19,3 +20,4 @@ An `info.json` file should be present in the input directory. This file should c
* `url` - The URL to the pack's repository.
* `versions` - A two dimensional array of mc version to pack format. (`[[mcVersion, packFormat]]`)
* `exports` - The exports to be made from the zip files produced for each version. A two dimensional array of mcVersion or "all". (`[["all"],["1.20", "1.20.2"]]`)
* `overrides` - A dictionary map of version to data directory, superseding the common directory. (`{"1.20": "data"}`)

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 {
data?: string;
}
interface Info {
description: string;
@ -23,10 +26,11 @@ interface Info {
name: string;
url: string;
versions: Array<[mcVersion: string, packFormat: number]>;
overrides?: Record<string, Override>;
}
const { values: { indir: inDir, common: commonDir, revision: rev, outdir: outDir } } = parseArgs({
const { values: { indir: inDir, data: dataDir, revision: rev, outdir: outDir, info: infoPath } } = parseArgs({
args: Bun.argv,
options: {
indir: {
@ -34,10 +38,10 @@ const { values: { indir: inDir, common: commonDir, revision: rev, outdir: outDir
short: "i",
default: cwd()
},
common: {
data: {
type: "string",
short: "c",
default: "common"
short: "d",
default: "data"
},
revision: {
type: "string",
@ -47,7 +51,11 @@ const { values: { indir: inDir, common: commonDir, revision: rev, outdir: outDir
type: "string",
short: "o",
default: "dist"
}
},
info: {
type: "string",
default: "info.json"
},
},
strict: true,
allowPositionals: true
@ -66,11 +74,11 @@ if (!await directoryExists(dir)) {
process.exit(1);
}
const info = await Bun.file(`${dir}/info.json`).json() as Info;
const common = resolve(dir, commonDir!);
const info = await Bun.file(infoPath ?? "info.json").json() as Info;
const data = resolve(dir, dataDir!);
const dist = resolve(dir, outDir!);
if (!await directoryExists(common)) {
console.log(`Specified common directory "${commonDir}" (${common}) does not exist.`);
if (!await directoryExists(data)) {
console.log(`Specified data directory "${dataDir}" (${data}) does not exist.`);
process.exit(1);
}
@ -92,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 dataDir = data;
if (info.overrides) {
const override = info.overrides[mcVersion];
if (override?.data) {
dataDir = resolve(dir, override.data);
if (!await directoryExists(dataDir)) {
console.log(`[Override:${mcVersion}] Specified data directory "${override.data}" (${dataDir}) does not exist.`);
process.exit(1);
}
}
}
console.log("Building %s (pf: %d)", mcVersion, packFormat);
const mcmeta = {
pack: {
@ -107,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(`${dataDir}/pack.png`, `${tempDir}/${mcVersion}/pack.png`);
await cp(`${dataDir}/assets`, `${tempDir}/${mcVersion}/assets`, { recursive: true });
const zip = new AdmZip();
await zip.addLocalFolderPromise(`${tempDir}/${mcVersion}`, {});
await zip.writeZipPromise(`${dist}/${info.name.replaceAll(" ", "")}-${mcVersion}.zip`);