Browse Source
Reviewed-on: https://git.devdevdev.life/AXE-WEB/block-dev-tool/pulls/2test-gpt-generated
10 changed files with 1055 additions and 5601 deletions
@ -1,74 +1,70 @@ |
|||
#!/usr/bin/env node
|
|||
// For development purposes - run `npm run build-platform`.
|
|||
|
|||
import {exec} from 'child_process'; |
|||
import config from 'config'; |
|||
import Generator from "yeoman-generator"; |
|||
import yeoman from 'yeoman-environment'; |
|||
import prompts from "prompts"; |
|||
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 {isDev, developmentBlockName} = getConfigs(); |
|||
const blockName = !isDev && config.has('blockName') ? config.get('blockName') : developmentBlockName; |
|||
|
|||
const blockName = config.has('blockName') ? config.get('blockName') : 'development'; |
|||
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' |
|||
}]; |
|||
|
|||
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' |
|||
} |
|||
]) |
|||
} |
|||
const data = await getExportData(); |
|||
const selectedPlatform = PLATFORM_OPTIONS[data['platform']]; |
|||
await buildExportFiles(selectedPlatform); |
|||
|
|||
writing() { |
|||
new Promise((resolve => { |
|||
if (['WordPress', 'PHP'].includes(this.data.platform)) { |
|||
const backPath = modulesPath ? modulesPath.split('/').map(() => '..').join('/') : ''; |
|||
console.log('--------------------\nDone!'); |
|||
|
|||
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); |
|||
} |
|||
//
|
|||
// Functions
|
|||
//
|
|||
|
|||
console.log(stdout); |
|||
resolve(); |
|||
}); |
|||
}).then(() => { |
|||
if (this.data.platform === 'WordPress') { |
|||
return buildWordPress(); |
|||
} |
|||
|
|||
if (this.data.platform === 'WordPress Block') { |
|||
return buildWordPress(true); |
|||
} |
|||
}); |
|||
export async function buildExportFiles(platform) { |
|||
if (['wordpress', 'php'].includes(platform.name)) { |
|||
|
|||
} else if (this.data.platform === 'Hubspot Email') { |
|||
buildHubspot(blockName) |
|||
.then(() => { |
|||
resolve(); |
|||
}); |
|||
} else if (this.data.platform === 'Hubspot') { |
|||
console.log('"Hubspot" Coming soon...'); |
|||
resolve(); |
|||
if (platform.name === 'wordpress') { |
|||
await buildWordPress(blockName); |
|||
} else { |
|||
resolve(); |
|||
if (platform.name === 'wordpress-blocks') { |
|||
await buildWordPress(blockName, true); |
|||
} |
|||
} |
|||
})) |
|||
.then(() => { |
|||
console.log('--------------------\nDone!'); |
|||
}); |
|||
} else if (platform.name === 'hubspot-email') { |
|||
await buildHubspot(blockName) |
|||
} else if (platform.name === 'hubspot') { |
|||
console.log('"Hubspot" Coming soon...'); |
|||
} |
|||
} |
|||
|
|||
const build = new buildGenerator([], {env: yeoman.createEnv()}, {}); |
|||
build.run().then(() => null); |
|||
function getExportData() { |
|||
return prompts([ |
|||
{ |
|||
type: "select", |
|||
name: "platform", |
|||
message: "Choose Platform", |
|||
choices: PLATFORM_OPTIONS.map(item => item.title), |
|||
default: 'WordPress' |
|||
} |
|||
]); |
|||
} |
|||
|
|||
File diff suppressed because it is too large
Loading…
Reference in new issue