Add more template files to WordPress generator.
This commit is contained in:
@@ -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