From f73c20d76fb30097fad805c7b31ea9fab294e8e8 Mon Sep 17 00:00:00 2001 From: Kir_Antipov Date: Fri, 24 Sep 2021 17:36:38 +0300 Subject: [PATCH] Made factory for the different publishers --- src/publishing/publisher-factory.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/publishing/publisher-factory.ts diff --git a/src/publishing/publisher-factory.ts b/src/publishing/publisher-factory.ts new file mode 100644 index 0000000..edcbd19 --- /dev/null +++ b/src/publishing/publisher-factory.ts @@ -0,0 +1,24 @@ +import Publisher from "./publisher"; +import PublisherTarget from "./publisher-target"; +import GitHubPublisher from "./github-publisher"; +import ModrinthPublisher from "./modrinth-publisher"; +import CurseForgePublisher from "./curseforge-publisher"; +import Logger from "../utils/logger"; + +export default class PublisherFactory { + public create(target: PublisherTarget, options: Record, logger?: Logger): Publisher { + switch(target) { + case PublisherTarget.GitHub: + return new GitHubPublisher(options, logger); + + case PublisherTarget.Modrinth: + return new ModrinthPublisher(options, logger); + + case PublisherTarget.CurseForge: + return new CurseForgePublisher(options, logger); + + default: + throw new Error(`Unknown target "${PublisherTarget.toString(target)}"`); + } + } +}