From f611185a4744003a327ace619246d353fc6e2857 Mon Sep 17 00:00:00 2001 From: Roman Axelrod Date: Thu, 8 Dec 2022 13:25:32 +0200 Subject: [PATCH] Wrap build options/platforms in reusable function. --- build.js | 25 ++----------------------- helpers.js | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/build.js b/build.js index c870182..b656dbf 100755 --- a/build.js +++ b/build.js @@ -3,10 +3,7 @@ import config from 'config'; import prompts from "prompts"; -import {buildHubspotEmail} from "./platforms/hubspot/hubspot-email-adapter.js"; -import {getConfigs} from "./helpers.js"; -import {buildWordPress} from "./platforms/wordpress/wordpress-adapter.js"; -import {buildHubspotPage} from "./platforms/hubspot/hubspot-page-adapter.js"; +import {buildExportFiles, getConfigs} from "./helpers.js"; const {isDev, developmentBlockName} = getConfigs(); const blockName = !isDev && config.has('blockName') ? config.get('blockName') : developmentBlockName; @@ -39,7 +36,7 @@ export const PLATFORM_OPTIONS = [{ const data = await getExportData(); const selectedPlatform = PLATFORM_OPTIONS[data['platform']]; -await buildExportFiles(selectedPlatform); +await buildExportFiles(blockName, selectedPlatform); console.log('--------------------\nDone!'); @@ -47,24 +44,6 @@ console.log('--------------------\nDone!'); // Functions // -export async function buildExportFiles(platform) { - if (platform.name.startsWith('wordpress')) { - if (platform.name === 'wordpress-blocks') { - await buildWordPress(blockName, {block: true}); - } else if (platform.name === 'wordpress-elementor') { - await buildWordPress(blockName, {elementor: true}); - } else if (platform.name === 'wordpress-component-manager') { - await buildWordPress(blockName, {componentManager: true}); - } else { - await buildWordPress(blockName); - } - } else if (platform.name === 'hubspot-email') { - await buildHubspotEmail(blockName) - } else if (platform.name === 'hubspot') { - await buildHubspotPage(blockName) - } -} - function getExportData() { return prompts([ { diff --git a/helpers.js b/helpers.js index 0ff2275..6c7016e 100644 --- a/helpers.js +++ b/helpers.js @@ -5,6 +5,9 @@ import memFs from 'mem-fs'; import editor from 'mem-fs-editor'; import fsExtra from "fs-extra"; import archiver from "archiver"; +import {buildWordPress} from "./platforms/wordpress/wordpress-adapter.js"; +import {buildHubspotEmail} from "./platforms/hubspot/hubspot-email-adapter.js"; +import {buildHubspotPage} from "./platforms/hubspot/hubspot-page-adapter.js"; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); @@ -152,3 +155,21 @@ export async function zipProject(srcDir, outputFileName = 'dist.zip') { // 'close', 'end' or 'finish' may be fired right after calling this method so register to them beforehand await archive.finalize(); } + +export async function buildExportFiles(blockName, platform) { + if (platform.name.startsWith('wordpress')) { + if (platform.name === 'wordpress-acf-block') { + await buildWordPress(blockName, {block: true}); + } else if (platform.name === 'wordpress-elementor') { + await buildWordPress(blockName, {elementor: true}); + } else if (platform.name === 'wordpress-component-manager') { + await buildWordPress(blockName, {componentManager: true}); + } else { + await buildWordPress(blockName); + } + } else if (platform.name === 'hubspot-email') { + await buildHubspotEmail(blockName) + } else if (platform.name === 'hubspot') { + await buildHubspotPage(blockName) + } +}