import path from "path"; import {mkdir, copyFile} from "fs/promises"; import {capitalize, createFiles, getBlockName, getConfigs, readJSONFile} from "../../helpers.js"; 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}) 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`)); 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, [{ from: `templates/Template_Component.php`, to: `${data.blockClassModel}_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) }); }