Chained all known ModMetadataReaders

This commit is contained in:
Kir_Antipov 2021-12-07 21:42:49 +03:00
parent 0844ce3a92
commit 4151c36500

View file

@ -1,7 +1,22 @@
import ModLoaderType from "./mod-loader-type";
import ModMetadata from "./mod-metadata"; import ModMetadata from "./mod-metadata";
import ModMetadataReaderFactory from "./mod-metadata-reader-factory";
interface ModMetadataReader { interface ModMetadataReader {
readMetadata(modPath: string): Promise<ModMetadata | null>; readMetadata(modPath: string): Promise<ModMetadata | null>;
} }
namespace ModMetadataReader {
export async function readMetadata(modPath: string): Promise<ModMetadata | null> {
const factory = new ModMetadataReaderFactory();
for (const loaderType of ModLoaderType.getValues()) {
const metadata = await factory.create(loaderType).readMetadata(modPath).catch(_ => null);
if (metadata) {
return metadata;
}
}
return null;
}
}
export default ModMetadataReader; export default ModMetadataReader;