build-wp-block #1
@@ -7,8 +7,9 @@ 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 {isDev, modulesPath, projectPath, developmentBlockName} = getConfigs();
|
||||
const {modulesPath, projectPath} = getConfigs();
|
||||
|
||||
const blockName = config.has('blockName') ? config.get('blockName') : 'development';
|
||||
|
||||
@@ -28,10 +29,16 @@ class buildGenerator extends Generator {
|
||||
writing() {
|
||||
new Promise((resolve => {
|
||||
if (['WordPress', 'PHP'].includes(this.data.platform)) {
|
||||
const backPath = modulesPath ? modulesPath.substr(-1).split('/').map(() => '..').join('/') : '';
|
||||
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);
|
||||
}
|
||||
|
||||
return new Promise((resolve) => {
|
||||
exec(`cd ${modulesPath}platforms/php && composer install && php build.php '${blockName}' '${backPath}' '${projectPath}'`, function (error, stdout) {
|
||||
console.log(stdout);
|
||||
resolve();
|
||||
});
|
||||
@@ -59,6 +66,5 @@ class buildGenerator extends Generator {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const build = new buildGenerator([], {env: yeoman.createEnv()}, {});
|
||||
build.run().then(() => null);
|
||||
|
||||
+15
@@ -92,3 +92,18 @@ export async function createFiles(data, files = [], {pathDist, generatorsPath})
|
||||
|
||||
return filesystem.commit(); // Promise
|
||||
}
|
||||
|
||||
export function capitalize(str) {
|
||||
if (typeof str !== 'string') {
|
||||
return '';
|
||||
}
|
||||
|
||||
return str
|
||||
.toLowerCase()
|
||||
.split(/[ -_]/g)
|
||||
.filter((word) => !!word)
|
||||
.map((word) => {
|
||||
return word.charAt(0).toUpperCase() + word.slice(1);
|
||||
})
|
||||
.join(' ');
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace AXEWEB_Blocks\Blocks\<%= ownerClass %>\<%= blockClassModel %>\Helpers;
|
||||
|
||||
class <%= blockClassModel %>_API {
|
||||
|
||||
static function prepare_args( $args = [] ) {
|
||||
|
||||
// $args = array_merge( [], $args );
|
||||
|
||||
return $args;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace AXEWEB_Blocks\Blocks\<%= ownerClass %>\<%= blockClassModel %>\Helpers;
|
||||
|
||||
/**
|
||||
* Component's default args.
|
||||
*/
|
||||
|
||||
class <%= blockClassModel %>_Defaults {
|
||||
public static function default_args(): array {
|
||||
return [
|
||||
'title' => '<%= title %>',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
import path from "path";
|
||||
import {mkdir, copyFile} from "fs/promises";
|
||||
import {createFiles, getBlockName, getConfigs, readJSONFile} from "../../helpers.js";
|
||||
import {capitalize} from "lodash-es";
|
||||
import {capitalize, createFiles, getBlockName, getConfigs, readJSONFile} from "../../helpers.js";
|
||||
import {fileURLToPath} from 'url';
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
@@ -12,10 +11,11 @@ const {projectPath, modulesPath} = getConfigs();
|
||||
export async function buildWordPress(blockName) {
|
||||
const distPath = path.join(projectPath, 'exports', 'wordpress');
|
||||
await mkdir(distPath, {recursive: true})
|
||||
await copyFile(`${projectPath}/block.json`, `${distPath}/block.json`)
|
||||
|
||||
let data = await readJSONFile(path.join(projectPath, `block.json`));
|
||||
const jsonFilePath = path.join(projectPath, 'block.json');
|
||||
await copyFile(jsonFilePath, `${distPath}/block.json`)
|
||||
|
||||
let data = await readJSONFile(jsonFilePath);
|
||||
Object.assign(data, getBlockName(data.name));
|
||||
|
||||
// let data = await readJSONFile(path.join(projectPath, `block.json`));
|
||||
@@ -38,8 +38,24 @@ export async function buildWordPress(blockName) {
|
||||
});
|
||||
|
||||
await createFiles(data, [{
|
||||
from: `templates/Template_Component.php`,
|
||||
to: `${data.blockClassModel}_Component.php`,
|
||||
from: `templates/Template_Component.php`
|
||||
}], {
|
||||
pathDist: distPath,
|
||||
generatorsPath: path.join(__dirname)
|
||||
});
|
||||
|
||||
await createFiles(data, [{
|
||||
from: `templates/helpers/Template_API.php`,
|
||||
to: `helpers/${data.blockClassModel}_API.php`,
|
||||
}], {
|
||||
pathDist: distPath,
|
||||
generatorsPath: path.join(__dirname)
|
||||
});
|
||||
|
||||
await createFiles(data, [{
|
||||
from: `templates/helpers/Template_Defaults.php`,
|
||||
to: `helpers/${data.blockClassModel}_Defaults.php`,
|
||||
}], {
|
||||
pathDist: distPath,
|
||||
generatorsPath: path.join(__dirname)
|
||||
|
||||
Reference in New Issue
Block a user