Allow compiling singular version

This commit is contained in:
Donovan Daniels 2024-05-30 14:21:33 -05:00
parent 7121f46fe6
commit 848a1ae3d6
Signed by: Donovan_DMC
GPG Key ID: 907D29CBFD6157BA
2 changed files with 24 additions and 12 deletions

View File

@ -12,6 +12,7 @@ build-packs
* `-d` or `--data` - The data directory containing the data files. Defailts to data. * `-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. * `-i` or `--info` - The info file. Defaults to info.json.
* `-v` or `--version` - Only compile this version.
### 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:

View File

@ -30,7 +30,7 @@ interface Info {
} }
const { values: { indir: inDir, data: dataDir, revision: rev, outdir: outDir, info: infoPath } } = parseArgs({ const { values: { indir: inDir, data: dataDir, revision: rev, outdir: outDir, info: infoPath, version: onlyVersion } } = parseArgs({
args: Bun.argv, args: Bun.argv,
options: { options: {
indir: { indir: {
@ -56,6 +56,10 @@ const { values: { indir: inDir, data: dataDir, revision: rev, outdir: outDir, in
type: "string", type: "string",
default: "info.json" default: "info.json"
}, },
version: {
type: "string",
short: "v"
}
}, },
strict: true, strict: true,
allowPositionals: true allowPositionals: true
@ -100,6 +104,10 @@ 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) {
if (onlyVersion && mcVersion !== onlyVersion) {
return;
}
let dataDir = data; let dataDir = data;
if (info.overrides) { if (info.overrides) {
const override = info.overrides[mcVersion]; const override = info.overrides[mcVersion];
@ -147,18 +155,21 @@ for (const [mcVersion, packFormat] of info.versions) {
await rm(tempDir, { recursive: true, force: true }); await rm(tempDir, { recursive: true, force: true });
console.log("Total size: %s", prettyBytes(totalSize)); console.log("Total size: %s", prettyBytes(totalSize));
if (onlyVersion) {
for (const ex of info.exports) { console.log("Skipping exports due to version filter");
const name = (ex[0] === "all" ? info.name : `${info.name}-${ex.join("-")}`).replaceAll(" ", ""); } else {
console.log("Exporting %s", name); for (const ex of info.exports) {
const zip = new AdmZip(); const name = (ex[0] === "all" ? info.name : `${info.name}-${ex.join("-")}`).replaceAll(" ", "");
const versions = ex[0] === "all" ? info.versions.map(([mcVersion]) => mcVersion) : ex; console.log("Exporting %s", name);
for (const version of versions) { const zip = new AdmZip();
zip.addLocalFile(`${dist}/${info.name.replaceAll(" ", "")}-${version}.zip`); const versions = ex[0] === "all" ? info.versions.map(([mcVersion]) => mcVersion) : ex;
for (const version of versions) {
zip.addLocalFile(`${dist}/${info.name.replaceAll(" ", "")}-${version}.zip`);
}
await zip.writeZipPromise(`${dist}/${name}.zip`);
const { size } = await stat(`${dist}/${name}.zip`);
console.log("%s exported, size: %s", name, prettyBytes(size));
} }
await zip.writeZipPromise(`${dist}/${name}.zip`);
const { size } = await stat(`${dist}/${name}.zip`);
console.log("%s exported, size: %s", name, prettyBytes(size));
} }
console.log("Done"); console.log("Done");