mirror of
https://github.com/Kir-Antipov/mc-publish.git
synced 2025-01-04 04:44:50 -05:00
Made base class for config-based metadata
This commit is contained in:
parent
ef28fbd8f5
commit
8937a5c943
1 changed files with 30 additions and 0 deletions
30
src/metadata/mod-config.ts
Normal file
30
src/metadata/mod-config.ts
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue