Wrap build options/platforms in reusable function.

This commit is contained in:
2022-12-08 13:25:32 +02:00
parent 7024c2bfcb
commit f611185a47
2 changed files with 23 additions and 23 deletions
+2 -23
View File
@@ -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([
{
+21
View File
@@ -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)
}
}