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
|
#!/usr/bin/env node
|
||||
|
// For development purposes - run `npm run build-platform`.
|
||||
|
|
||||
import {exec} from 'child_process'; |
|
||||
import config from 'config'; |
import config from 'config'; |
||||
import Generator from "yeoman-generator"; |
import prompts from "prompts"; |
||||
import yeoman from 'yeoman-environment'; |
|
||||
import {buildHubspot} from "./platforms/hubspot/hubspot-adapter.js"; |
import {buildHubspot} from "./platforms/hubspot/hubspot-adapter.js"; |
||||
import {getConfigs} from "./helpers.js"; |
import {getConfigs} from "./helpers.js"; |
||||
import {buildWordPress} from "./platforms/wordpress/wordpress-adapter.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 { |
const data = await getExportData(); |
||||
async prompting() { |
const selectedPlatform = PLATFORM_OPTIONS[data['platform']]; |
||||
this.data = await this.prompt([ |
await buildExportFiles(selectedPlatform); |
||||
{ |
|
||||
type: "list", |
|
||||
name: "platform", |
|
||||
message: "Choose Platform", |
|
||||
choices: ['WordPress', 'WordPress Block', 'Hubspot', 'Hubspot Email', 'JavaScript', 'PHP'], |
|
||||
default: 'WordPress' |
|
||||
} |
|
||||
]) |
|
||||
} |
|
||||
|
|
||||
writing() { |
console.log('--------------------\nDone!'); |
||||
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'); |
// Functions
|
||||
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); |
export async function buildExportFiles(platform) { |
||||
resolve(); |
if (['wordpress', 'php'].includes(platform.name)) { |
||||
}); |
|
||||
}).then(() => { |
|
||||
if (this.data.platform === 'WordPress') { |
|
||||
return buildWordPress(); |
|
||||
} |
|
||||
|
|
||||
if (this.data.platform === 'WordPress Block') { |
if (platform.name === 'wordpress') { |
||||
return buildWordPress(true); |
await buildWordPress(blockName); |
||||
} |
} else { |
||||
}); |
if (platform.name === 'wordpress-blocks') { |
||||
|
await buildWordPress(blockName, 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(() => { |
} else if (platform.name === 'hubspot-email') { |
||||
console.log('--------------------\nDone!'); |
await buildHubspot(blockName) |
||||
}); |
} else if (platform.name === 'hubspot') { |
||||
|
console.log('"Hubspot" Coming soon...'); |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
const build = new buildGenerator([], {env: yeoman.createEnv()}, {}); |
function getExportData() { |
||||
build.run().then(() => null); |
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