Made base class for config-based metadata

This commit is contained in:
Kir_Antipov 2021-12-07 21:49:28 +03:00
parent ef28fbd8f5
commit 8937a5c943

View file

@ -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<TConfig = Record<string, unknown>> 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 || <TConfig>{};
}
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);
}
}