Rename common to data
This commit is contained in:
parent
ee9841a1d2
commit
cfd4a900e0
|
@ -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"}`)
|
||||
|
|
30
index.ts
30
index.ts
|
@ -17,7 +17,7 @@ import { tmpdir } from "node:os";
|
|||
import { cwd } from "node:process";
|
||||
import { resolve } from "node:path";
|
||||
interface Override {
|
||||
common?: string;
|
||||
data?: string;
|
||||
}
|
||||
|
||||
interface Info {
|
||||
|
@ -30,7 +30,7 @@ interface Info {
|
|||
}
|
||||
|
||||
|
||||
const { values: { indir: inDir, common: commonDir, revision: rev, outdir: outDir, info: infoPath } } = parseArgs({
|
||||
const { values: { indir: inDir, data: dataDir, revision: rev, outdir: outDir, info: infoPath } } = parseArgs({
|
||||
args: Bun.argv,
|
||||
options: {
|
||||
indir: {
|
||||
|
@ -38,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",
|
||||
|
@ -75,10 +75,10 @@ if (!await directoryExists(dir)) {
|
|||
}
|
||||
|
||||
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!);
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -100,13 +100,13 @@ 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;
|
||||
let dataDir = data;
|
||||
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.`);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -126,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(`${commonDir}/pack.png`, `${tempDir}/${mcVersion}/pack.png`);
|
||||
await cp(`${commonDir}/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`);
|
||||
|
|
Loading…
Reference in New Issue
Block a user