bearmetalpacker/server/util/packVersion.ts
Emma 3d9b877661 good font
tag create workflow
2024-10-19 21:18:35 -06:00

33 lines
870 B
TypeScript

import type { BearMetalStore } from "@bearmetal/store";
export function getPackVersion(store: BearMetalStore) {
const packMeta = Deno.readTextFileSync(
store.get("packlocation") + "/pack.mcmeta",
);
const packMetaJson = JSON.parse(packMeta);
return packMetaJson.pack.pack_format as number;
}
export async function getDirName(version: number, path: string) {
const { default: versionData } = await import(
"../../pack_versions/" + version + ".json",
{
with: { type: "json" },
}
);
const singular = makeSingular(path);
const plural = makePlural(path);
return versionData && versionData.schema.data["<namespace>"][singular] ||
versionData.schema.data["<namespace>"][plural];
}
function makeSingular(word: string) {
return word.replace(/s$/, "");
}
function makePlural(word: string) {
return makeSingular(word) + "s";
}