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.
 
 
 
 

74 lines
2.2 KiB

#!/usr/bin/env node
import {exec} from 'child_process';
import config from 'config';
import Generator from "yeoman-generator";
import yeoman from 'yeoman-environment';
import {buildHubspot} from "./platforms/hubspot/hubspot-adapter.js";
import {getConfigs} from "./helpers.js";
import {buildWordPress} from "./platforms/wordpress/wordpress-adapter.js";
import path from "path";
const {modulesPath, projectPath} = getConfigs();
const blockName = config.has('blockName') ? config.get('blockName') : 'development';
class buildGenerator extends Generator {
async prompting() {
this.data = await this.prompt([
{
type: "list",
name: "platform",
message: "Choose Platform",
choices: ['WordPress', 'WordPress Block', 'Hubspot', 'Hubspot Email', 'JavaScript', 'PHP'],
default: 'WordPress'
}
])
}
writing() {
new Promise((resolve => {
if (['WordPress', 'PHP'].includes(this.data.platform)) {
const backPath = modulesPath ? modulesPath.split('/').map(() => '..').join('/') : '';
return new Promise((resolve, reject) => {
const phpGeneratorPath = path.join(modulesPath, 'platforms', 'php');
exec(`cd ${phpGeneratorPath} && composer install && php build.php '${blockName}' '${backPath}' '${projectPath}'`, function (error, stdout) {
if (error) {
console.log('Error:', error)
reject(error);
}
console.log(stdout);
resolve();
});
}).then(() => {
if (this.data.platform === 'WordPress') {
return buildWordPress();
}
if (this.data.platform === 'WordPress Block') {
return buildWordPress(true);
}
});
} else if (this.data.platform === 'Hubspot Email') {
buildHubspot(blockName)
.then(() => {
resolve();
});
} else if (this.data.platform === 'Hubspot') {
console.log('"Hubspot" Coming soon...');
resolve();
} else {
resolve();
}
}))
.then(() => {
console.log('--------------------\nDone!');
});
}
}
const build = new buildGenerator([], {env: yeoman.createEnv()}, {});
build.run().then(() => null);