Compare commits
3 Commits
e742d839e1
...
cfd4a900e0
Author | SHA1 | Date | |
---|---|---|---|
cfd4a900e0 | |||
ee9841a1d2 | |||
6fddd8039f |
|
@ -9,8 +9,9 @@ build-packs
|
||||||
### Arguments
|
### Arguments
|
||||||
* `-i` or `--indir` - The input directory. Defaults to the current working directory.
|
* `-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.
|
* `-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.
|
* `-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
|
### Info File
|
||||||
An `info.json` file should be present in the input directory. This file should contain the following fields:
|
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.
|
* `url` - The URL to the pack's repository.
|
||||||
* `versions` - A two dimensional array of mc version to pack format. (`[[mcVersion, packFormat]]`)
|
* `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"]]`)
|
* `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"}`)
|
||||||
|
|
41
index.ts
41
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 {
|
||||||
|
data?: string;
|
||||||
|
}
|
||||||
|
|
||||||
interface Info {
|
interface Info {
|
||||||
description: string;
|
description: string;
|
||||||
|
@ -23,10 +26,11 @@ 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>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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,
|
args: Bun.argv,
|
||||||
options: {
|
options: {
|
||||||
indir: {
|
indir: {
|
||||||
|
@ -34,10 +38,10 @@ const { values: { indir: inDir, common: commonDir, revision: rev, outdir: outDir
|
||||||
short: "i",
|
short: "i",
|
||||||
default: cwd()
|
default: cwd()
|
||||||
},
|
},
|
||||||
common: {
|
data: {
|
||||||
type: "string",
|
type: "string",
|
||||||
short: "c",
|
short: "d",
|
||||||
default: "common"
|
default: "data"
|
||||||
},
|
},
|
||||||
revision: {
|
revision: {
|
||||||
type: "string",
|
type: "string",
|
||||||
|
@ -47,7 +51,11 @@ const { values: { indir: inDir, common: commonDir, revision: rev, outdir: outDir
|
||||||
type: "string",
|
type: "string",
|
||||||
short: "o",
|
short: "o",
|
||||||
default: "dist"
|
default: "dist"
|
||||||
}
|
},
|
||||||
|
info: {
|
||||||
|
type: "string",
|
||||||
|
default: "info.json"
|
||||||
|
},
|
||||||
},
|
},
|
||||||
strict: true,
|
strict: true,
|
||||||
allowPositionals: true
|
allowPositionals: true
|
||||||
|
@ -66,11 +74,11 @@ if (!await directoryExists(dir)) {
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const info = await Bun.file(`${dir}/info.json`).json() as Info;
|
const info = await Bun.file(infoPath ?? "info.json").json() as Info;
|
||||||
const common = resolve(dir, commonDir!);
|
const data = resolve(dir, dataDir!);
|
||||||
const dist = resolve(dir, outDir!);
|
const dist = resolve(dir, outDir!);
|
||||||
if (!await directoryExists(common)) {
|
if (!await directoryExists(data)) {
|
||||||
console.log(`Specified common directory "${commonDir}" (${common}) does not exist.`);
|
console.log(`Specified data directory "${dataDir}" (${data}) does not exist.`);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,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 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);
|
console.log("Building %s (pf: %d)", mcVersion, packFormat);
|
||||||
const mcmeta = {
|
const mcmeta = {
|
||||||
pack: {
|
pack: {
|
||||||
|
@ -107,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(`${dataDir}/pack.png`, `${tempDir}/${mcVersion}/pack.png`);
|
||||||
await cp(`${common}/assets`, `${tempDir}/${mcVersion}/assets`, { recursive: true });
|
await cp(`${dataDir}/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