You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.5 KiB
47 lines
1.5 KiB
import path from "path";
|
|
import {mkdir, copyFile} from "fs/promises";
|
|
import {createFiles, getBlockName, getConfigs, readJSONFile} from "../../helpers.js";
|
|
import {capitalize} from "lodash-es";
|
|
import {fileURLToPath} from 'url';
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
const __dirname = path.dirname(__filename);
|
|
|
|
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`));
|
|
|
|
Object.assign(data, getBlockName(data.name));
|
|
|
|
// let data = await readJSONFile(path.join(projectPath, `block.json`));
|
|
const title = capitalize(data.name);
|
|
const owner = capitalize(data.project);
|
|
|
|
data = Object.assign(data, {
|
|
title,
|
|
blockClassModel: title.replace(/ /ig, '_'),
|
|
blockFilename: title.toLowerCase().replace(/ /ig, '-'),
|
|
blockClassName: title.toLowerCase().replace(/ /ig, '_'),
|
|
owner,
|
|
ownerClass: owner.replace(/ /ig, '_'),
|
|
ownerFilename: owner.toLowerCase().replace(/ /ig, '-'),
|
|
templateFormat: 'php',
|
|
include_acf_block: false,
|
|
include_native_gutenberg_block: false,
|
|
include_script: true,
|
|
include_elementor_widget: false,
|
|
});
|
|
|
|
await createFiles(data, [{
|
|
to: `${data.blockClassModel}_Component.php`,
|
|
from: `templates/Template_Component.php`
|
|
}], {
|
|
pathDist: distPath,
|
|
generatorsPath: path.join(__dirname)
|
|
});
|
|
}
|
|
|