mirror of
https://github.com/Kir-Antipov/mc-publish.git
synced 2024-12-29 10:04:49 -05:00
Made a reader for Forge metadata
This commit is contained in:
parent
0696b03d05
commit
0da00d434a
2 changed files with 57 additions and 0 deletions
16
src/loaders/forge/forge-metadata-reader.ts
Normal file
16
src/loaders/forge/forge-metadata-reader.ts
Normal file
|
@ -0,0 +1,16 @@
|
|||
import { parse as parseToml } from "toml";
|
||||
import { ZippedTextLoaderMetadataReader } from "@/loaders/zipped-loader-metadata-reader";
|
||||
import { MODS_TOML, RawForgeMetadata } from "./raw-forge-metadata";
|
||||
import { ForgeMetadata } from "./forge-metadata";
|
||||
|
||||
/**
|
||||
* A metadata reader that is able to read Forge mod metadata from a zipped file.
|
||||
*/
|
||||
export class ForgeMetadataReader extends ZippedTextLoaderMetadataReader<ForgeMetadata, RawForgeMetadata> {
|
||||
/**
|
||||
* Constructs a new {@link ForgeMetadataReader} instance.
|
||||
*/
|
||||
constructor() {
|
||||
super(MODS_TOML, ForgeMetadata.from, parseToml);
|
||||
}
|
||||
}
|
41
tests/unit/loaders/forge/forge-metadata-reader.spec.ts
Normal file
41
tests/unit/loaders/forge/forge-metadata-reader.spec.ts
Normal file
|
@ -0,0 +1,41 @@
|
|||
import { zipFile } from "@/../tests/utils/zip-utils";
|
||||
import mockFs from "mock-fs";
|
||||
import { ForgeMetadata } from "@/loaders/forge/forge-metadata";
|
||||
import { ForgeMetadataReader } from "@/loaders/forge/forge-metadata-reader";
|
||||
|
||||
beforeEach(async () => {
|
||||
mockFs({
|
||||
"forge.mod.jar": await zipFile([__dirname, "../../../content/forge/mods.toml"], "META-INF/mods.toml"),
|
||||
"text.txt": "",
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
mockFs.restore();
|
||||
});
|
||||
|
||||
describe("ForgeMetadataReader", () => {
|
||||
test("successfully reads mods.toml", async () => {
|
||||
const reader = new ForgeMetadataReader();
|
||||
|
||||
const metadata = await reader.readMetadataFile("forge.mod.jar");
|
||||
|
||||
expect(metadata).toBeInstanceOf(ForgeMetadata);
|
||||
});
|
||||
|
||||
test("returns undefined if file is not a Forge mod", async () => {
|
||||
const reader = new ForgeMetadataReader();
|
||||
|
||||
const metadata = await reader.readMetadataFile("text.txt");
|
||||
|
||||
expect(metadata).toBeUndefined();
|
||||
});
|
||||
|
||||
test("returns undefined if file does not exist", async () => {
|
||||
const reader = new ForgeMetadataReader();
|
||||
|
||||
const metadata = await reader.readMetadataFile("text.json");
|
||||
|
||||
expect(metadata).toBeUndefined();
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue