Rename common to data
This commit is contained in:
parent
ee9841a1d2
commit
cfd4a900e0
@ -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"}`)
|
||||||
|
30
index.ts
30
index.ts
@ -17,7 +17,7 @@ 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 {
|
interface Override {
|
||||||
common?: string;
|
data?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Info {
|
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,
|
args: Bun.argv,
|
||||||
options: {
|
options: {
|
||||||
indir: {
|
indir: {
|
||||||
@ -38,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",
|
||||||
@ -75,10 +75,10 @@ if (!await directoryExists(dir)) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const info = await Bun.file(infoPath ?? "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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,13 +100,13 @@ 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;
|
let dataDir = data;
|
||||||
if (info.overrides) {
|
if (info.overrides) {
|
||||||
const override = info.overrides[mcVersion];
|
const override = info.overrides[mcVersion];
|
||||||
if (override?.common) {
|
if (override?.data) {
|
||||||
commonDir = resolve(dir, override.common);
|
dataDir = resolve(dir, override.data);
|
||||||
if (!await directoryExists(commonDir)) {
|
if (!await directoryExists(dataDir)) {
|
||||||
console.log(`[Override:${mcVersion}] Specified common directory "${override.common}" (${commonDir}) does not exist.`);
|
console.log(`[Override:${mcVersion}] Specified data directory "${override.data}" (${dataDir}) does not exist.`);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -126,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(`${commonDir}/pack.png`, `${tempDir}/${mcVersion}/pack.png`);
|
await copyFile(`${dataDir}/pack.png`, `${tempDir}/${mcVersion}/pack.png`);
|
||||||
await cp(`${commonDir}/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