Exclude YeoMan from the project.
Make the npm-install process faster.
This commit is contained in:
@@ -1,74 +1,91 @@
|
||||
#!/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 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";
|
||||
import path from "path";
|
||||
|
||||
const {modulesPath, projectPath} = getConfigs();
|
||||
const {isDev, modulesPath, projectPath, developmentBlockName} = getConfigs();
|
||||
const blockName = isDev ? developmentBlockName : 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);
|
||||
|
||||
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);
|
||||
}
|
||||
])
|
||||
}
|
||||
|
||||
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!');
|
||||
});
|
||||
}
|
||||
} 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);
|
||||
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'
|
||||
}
|
||||
]);
|
||||
}
|
||||
|
||||
+1
-2
@@ -3,6 +3,7 @@ import config from 'config';
|
||||
import {fileURLToPath} from 'url';
|
||||
import memFs from 'mem-fs';
|
||||
import editor from 'mem-fs-editor';
|
||||
import fsExtra from "fs-extra";
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
@@ -19,8 +20,6 @@ export function getConfigs() {
|
||||
};
|
||||
}
|
||||
|
||||
import fsExtra from "fs-extra";
|
||||
|
||||
export async function readJSONFile(jsonFile) {
|
||||
let data = {};
|
||||
|
||||
|
||||
Generated
+41
-5667
File diff suppressed because it is too large
Load Diff
+2
-3
@@ -37,10 +37,9 @@
|
||||
"node-fetch": "^3.2.10",
|
||||
"open": "^8.4.0",
|
||||
"plugin-error": "^2.0.0",
|
||||
"prompts": "^2.4.2",
|
||||
"sanitize-html": "^2.7.1",
|
||||
"sass": "^1.50.1",
|
||||
"yeoman-environment": "^3.10.0",
|
||||
"yeoman-generator": "^5.6.1"
|
||||
"sass": "^1.50.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/preset-react": "^7.18.6",
|
||||
|
||||
Reference in New Issue
Block a user