From 59eb2bc7e77b9a4ddcb0a44a2fc8f372321d48aa Mon Sep 17 00:00:00 2001 From: Kir_Antipov Date: Fri, 24 Sep 2021 14:53:46 +0300 Subject: [PATCH] Made base class for publishers --- src/publishing/publisher-target.ts | 17 +++++++++++++++++ src/publishing/publisher.ts | 20 ++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 src/publishing/publisher-target.ts create mode 100644 src/publishing/publisher.ts diff --git a/src/publishing/publisher-target.ts b/src/publishing/publisher-target.ts new file mode 100644 index 0000000..ed43d0f --- /dev/null +++ b/src/publishing/publisher-target.ts @@ -0,0 +1,17 @@ +enum PublisherTarget { + GitHub, + Modrinth, + CurseForge, +} + +namespace PublisherTarget { + export function getValues(): PublisherTarget[] { + return Object.values(PublisherTarget).filter(x => !isNaN(+x)); + } + + export function toString(target: PublisherTarget): string { + return PublisherTarget[target] || target.toString(); + } +} + +export default PublisherTarget; diff --git a/src/publishing/publisher.ts b/src/publishing/publisher.ts new file mode 100644 index 0000000..2826fa9 --- /dev/null +++ b/src/publishing/publisher.ts @@ -0,0 +1,20 @@ +import Logger from "../utils/logger"; +import { getEmptyLogger } from "../utils/logger-utils"; +import PublisherTarget from "./publisher-target"; + +export default abstract class Publisher { + protected readonly options: TOptions; + protected readonly logger: Logger; + + public constructor(options: TOptions, logger?: Logger) { + if (!options || typeof options !== "object") { + throw new Error(`Expected options to be an object, got ${options ? typeof options : options}`); + } + this.options = options; + this.logger = logger || getEmptyLogger(); + } + + public abstract get target(): PublisherTarget; + + public abstract publish(): Promise; +}