Support missing images folder.

This commit is contained in:
2023-08-13 23:50:52 +03:00
parent 840c002834
commit a1929fe33c
3 changed files with 24 additions and 5 deletions
+12 -5
View File
@@ -1,5 +1,5 @@
import path from "path";
import {mkdir, copyFile} from "fs/promises";
import fs, {mkdir, copyFile} from "fs/promises";
import {capitalize, createFiles, getBlockName, getConfigs, readJSONFile} from "../../helpers.js";
import {fileURLToPath} from 'url';
import {copy} from "fs-extra";
@@ -68,10 +68,17 @@ export async function buildWordPress(blockName, args = {}) {
path.join(distPath, 'templates', 'scripts', `${data.blockFilename}.min.js`),
);
await copy(
path.join(projectPath, 'src', 'images'),
path.join(distPath, 'templates', 'images'),
);
try {
const imagesPath = path.join(projectPath, 'src', 'images');
await fs.access(imagesPath);
await copy(
path.join(imagesPath),
path.join(distPath, 'templates', 'images'),
);
} catch (err) {
// Folder doesn't exist.
}
const phpDataObject = await execPHPFile(path.join(phpGeneratorPath, 'build.php'), 'jsonToPhp', {
json: await readJSONFile(path.join(projectPath, 'data', 'default.json'), "utf8"),