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.
* `-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.
* `-v` or `--version` - Only compile this version.
### Info File
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,
options: {
indir: {
@ -56,6 +56,10 @@ const { values: { indir: inDir, data: dataDir, revision: rev, outdir: outDir, in
type: "string",
default: "info.json"
},
version: {
type: "string",
short: "v"
}
},
strict: true,
allowPositionals: true
@ -100,6 +104,10 @@ const tempDir = await mkdtemp(`${tmpdir()}/${info.name.toLowerCase().replaceAll(
console.log("Temporary Directory:", tempDir);
let totalSize = 0;
async function createVersion(mcVersion: string, packFormat: number) {
if (onlyVersion && mcVersion !== onlyVersion) {
return;
}
let dataDir = data;
if (info.overrides) {
const override = info.overrides[mcVersion];
@ -147,18 +155,21 @@ for (const [mcVersion, packFormat] of info.versions) {
await rm(tempDir, { recursive: true, force: true });
console.log("Total size: %s", prettyBytes(totalSize));
for (const ex of info.exports) {
const name = (ex[0] === "all" ? info.name : `${info.name}-${ex.join("-")}`).replaceAll(" ", "");
console.log("Exporting %s", name);
const zip = new AdmZip();
const versions = ex[0] === "all" ? info.versions.map(([mcVersion]) => mcVersion) : ex;
for (const version of versions) {
zip.addLocalFile(`${dist}/${info.name.replaceAll(" ", "")}-${version}.zip`);
if (onlyVersion) {
console.log("Skipping exports due to version filter");
} else {
for (const ex of info.exports) {
const name = (ex[0] === "all" ? info.name : `${info.name}-${ex.join("-")}`).replaceAll(" ", "");
console.log("Exporting %s", name);
const zip = new AdmZip();
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");