mirror of
https://github.com/Kir-Antipov/mc-publish.git
synced 2024-11-25 01:41:05 -05:00
Made base class for dependencies described in configs
This commit is contained in:
parent
8937a5c943
commit
0530a4b597
1 changed files with 39 additions and 0 deletions
39
src/metadata/mod-config-dependency.ts
Normal file
39
src/metadata/mod-config-dependency.ts
Normal file
|
@ -0,0 +1,39 @@
|
|||
import action from "../../package.json";
|
||||
import Dependency from "./dependency";
|
||||
import DependencyKind from "./dependency-kind";
|
||||
import PublisherTarget from "../publishing/publisher-target";
|
||||
|
||||
interface DependencyOptions {
|
||||
id: string;
|
||||
version?: string;
|
||||
kind?: DependencyKind;
|
||||
ignore?: boolean;
|
||||
}
|
||||
|
||||
export default class ModConfigDependency<TMetadata extends DependencyOptions = Record<string, unknown> & DependencyOptions> implements Dependency {
|
||||
public readonly id: string;
|
||||
public readonly version: string;
|
||||
public readonly kind: DependencyKind;
|
||||
public readonly ignore: boolean;
|
||||
protected readonly metadata: TMetadata;
|
||||
|
||||
constructor(metadata: TMetadata) {
|
||||
this.id = String(metadata.id ?? "");
|
||||
this.version = String(metadata.version ?? "*");
|
||||
this.kind = metadata.kind || DependencyKind.Depends;
|
||||
this.metadata = metadata;
|
||||
this.ignore = this.metadata["custom"]?.[action.name]?.ignore ?? this.metadata[action.name]?.ignore ?? this.metadata.ignore ?? false;
|
||||
}
|
||||
|
||||
getProjectSlug(project: PublisherTarget): string {
|
||||
const projectName = PublisherTarget.toString(project).toLowerCase();
|
||||
const custom = this.metadata["custom"];
|
||||
const projects = this.metadata["projects"];
|
||||
return String(
|
||||
custom?.[action.name]?.[projectName]?.slug ?? custom?.[action.name]?.[projectName] ??
|
||||
projects?.[projectName]?.slug ?? projects?.[projectName] ??
|
||||
custom?.projects?.[projectName]?.slug ?? custom?.projects?.[projectName] ??
|
||||
this.id
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue