From 0530a4b597bd1d6f46547bc5755a66a9bf72b689 Mon Sep 17 00:00:00 2001 From: Kir_Antipov Date: Tue, 7 Dec 2021 21:50:15 +0300 Subject: [PATCH] Made base class for dependencies described in configs --- src/metadata/mod-config-dependency.ts | 39 +++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/metadata/mod-config-dependency.ts diff --git a/src/metadata/mod-config-dependency.ts b/src/metadata/mod-config-dependency.ts new file mode 100644 index 0000000..a957a70 --- /dev/null +++ b/src/metadata/mod-config-dependency.ts @@ -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 & 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 + ); + } +}