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.
73 lines
2.2 KiB
73 lines
2.2 KiB
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} = getConfigs();
|
|
|
|
export async function buildWordPress(isBlock = false) {
|
|
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,
|
|
});
|
|
|
|
if (isBlock) {
|
|
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)
|
|
});
|
|
} else {
|
|
await createFiles(data, [{
|
|
from: `templates/Template_Basic_Component.php`,
|
|
to: `${data.blockClassModel}_Component.php`,
|
|
}], {
|
|
pathDist: distPath,
|
|
generatorsPath: path.join(__dirname)
|
|
});
|
|
}
|
|
}
|
|
|