You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
91 lines
2.3 KiB
91 lines
2.3 KiB
#!/usr/bin/env node
|
|
// For development purposes - run `npm run build-platform`.
|
|
|
|
import config from 'config';
|
|
import path from "path";
|
|
import prompts from "prompts";
|
|
import {exec} from 'child_process';
|
|
import {buildHubspot} from "./platforms/hubspot/hubspot-adapter.js";
|
|
import {getConfigs} from "./helpers.js";
|
|
import {buildWordPress} from "./platforms/wordpress/wordpress-adapter.js";
|
|
|
|
const {isDev, modulesPath, projectPath, developmentBlockName} = getConfigs();
|
|
const blockName = isDev ? developmentBlockName : config.has('blockName') ? config.get('blockName') : developmentBlockName;
|
|
|
|
export const PLATFORM_OPTIONS = [{
|
|
name: 'wordpress',
|
|
title: 'WordPress'
|
|
}, {
|
|
name: 'wordpress-blocks',
|
|
title: 'WordPress Block'
|
|
}, {
|
|
name: 'hubspot',
|
|
title: 'Hubspot'
|
|
}, {
|
|
name: 'hubspot-email',
|
|
title: 'Hubspot Email'
|
|
}, {
|
|
name: 'javascript',
|
|
title: 'JavaScript'
|
|
}, {
|
|
name: 'php',
|
|
title: 'PHP'
|
|
}];
|
|
|
|
const data = await getExportData();
|
|
const selectedPlatform = PLATFORM_OPTIONS[data['platform']];
|
|
await buildExportFiles(selectedPlatform);
|
|
|
|
console.log('--------------------\nDone!');
|
|
|
|
//
|
|
// Functions
|
|
//
|
|
|
|
export async function buildExportFiles(platform) {
|
|
if (['wordpress', 'php'].includes(platform.name)) {
|
|
const backPath = modulesPath ? modulesPath.split('/').map(() => '..').join('/') : '';
|
|
|
|
const phpGeneratorPath = path.join(modulesPath, 'platforms', 'php');
|
|
await execCommand(`cd ${phpGeneratorPath} && composer install && php build.php '${blockName}' '${backPath}' '${projectPath}'`);
|
|
if (platform.name === 'wordpress') {
|
|
await buildWordPress();
|
|
} else {
|
|
if (platform.name === 'wordpress-blocks') {
|
|
await buildWordPress(true);
|
|
}
|
|
}
|
|
} else if (platform.name === 'hubspot-email') {
|
|
await buildHubspot(blockName)
|
|
} else if (platform.name === 'hubspot') {
|
|
console.log('"Hubspot" Coming soon...');
|
|
}
|
|
}
|
|
|
|
export function execCommand(cmd = '') {
|
|
return new Promise((resolve, reject) => {
|
|
|
|
exec(cmd, function (error, stdout) {
|
|
if (error) {
|
|
console.log('Error:', error)
|
|
reject(error);
|
|
}
|
|
|
|
console.log(stdout);
|
|
resolve();
|
|
});
|
|
|
|
});
|
|
}
|
|
|
|
function getExportData() {
|
|
return prompts([
|
|
{
|
|
type: "select",
|
|
name: "platform",
|
|
message: "Choose Platform",
|
|
choices: PLATFORM_OPTIONS.map(item => item.title),
|
|
default: 'WordPress'
|
|
}
|
|
]);
|
|
}
|
|
|