From 9101916d52b87dfabb5a51716b0cce302041c00d Mon Sep 17 00:00:00 2001 From: Kir_Antipov Date: Sat, 25 Sep 2021 09:37:10 +0300 Subject: [PATCH] Implemented action's entry point --- src/index.ts | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/index.ts diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..ad0fd88 --- /dev/null +++ b/src/index.ts @@ -0,0 +1,34 @@ +import PublisherFactory from "./publishing/publisher-factory"; +import PublisherTarget from "./publishing/publisher-target"; +import { getInputAsObject } from "./utils/input-utils"; +import { getDefaultLogger } from "./utils/logger-utils"; + +async function main() { + const commonOptions = getInputAsObject(); + const publisherFactory = new PublisherFactory(); + const logger = getDefaultLogger(); + const publishedTo = new Array(); + + for (const target of PublisherTarget.getValues()) { + const targetName = PublisherTarget.toString(target); + const publisherOptions = commonOptions[targetName.toLowerCase()]; + if (!publisherOptions) { + continue; + } + + const publisher = publisherFactory.create(target, { ...commonOptions, ...publisherOptions }, logger); + logger.info(`Publishing assets to ${targetName}...`); + const start = new Date(); + await publisher.publish(); + logger.info(`Successfully published assets to ${targetName} (in ${new Date().getTime() - start.getTime()}ms)`); + publishedTo.push(targetName); + } + + if (publishedTo.length) { + logger.info(`Your assets have been successfully published to: ${publishedTo.join(", ")}`); + } else { + logger.warn("You didn't specify any targets, your assets have not been published"); + } +} + +main().catch(error => getDefaultLogger().fatal(error instanceof Error ? error.message : `Something went horribly wrong: ${error}`));