From 8937a5c9430a6ace2cfcb69982ad4ea1a221e6d9 Mon Sep 17 00:00:00 2001 From: Kir_Antipov Date: Tue, 7 Dec 2021 21:49:28 +0300 Subject: [PATCH] Made base class for config-based metadata --- src/metadata/mod-config.ts | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/metadata/mod-config.ts diff --git a/src/metadata/mod-config.ts b/src/metadata/mod-config.ts new file mode 100644 index 0000000..9f385c3 --- /dev/null +++ b/src/metadata/mod-config.ts @@ -0,0 +1,30 @@ +import action from "../../package.json"; +import Dependency from "./dependency"; +import ModMetadata from "./mod-metadata"; +import PublisherTarget from "../publishing/publisher-target"; + +export default abstract class ModConfig> implements ModMetadata { + public abstract get id(): string; + public abstract get name(): string; + public abstract get version(): string; + public abstract get loaders(): string[]; + public abstract get dependencies(): Dependency[]; + + protected readonly config: TConfig; + + constructor(config: TConfig) { + this.config = config || {}; + } + + getProjectId(project: PublisherTarget): string | undefined { + const projectName = PublisherTarget.toString(project).toLowerCase(); + const custom = this.config["custom"]; + const projects = this.config["projects"]; + const projectId = ( + custom?.[action.name]?.[projectName]?.id ?? custom?.[action.name]?.[projectName] ?? + projects?.[projectName]?.id ?? projects?.[projectName] ?? + custom?.projects?.[projectName]?.id ?? custom?.projects?.[projectName] + ); + return projectId === undefined ? projectId : String(projectId); + } +}