Support missing images folder.
This commit is contained in:
@@ -213,6 +213,14 @@ export async function uploadFile(filePath, uploadUrl, validator) {
|
||||
|
||||
export async function getImagesList(rootFolder, subFolder = '') {
|
||||
const imagesPath = path.join(rootFolder, subFolder);
|
||||
|
||||
try {
|
||||
await fs.access(imagesPath);
|
||||
} catch (err) {
|
||||
// Folder doesn't exist.
|
||||
return [];
|
||||
}
|
||||
|
||||
const images = await fs.readdir(imagesPath);
|
||||
const imagesList = [];
|
||||
|
||||
|
||||
@@ -26,6 +26,10 @@ export async function createDistFolder(blockName, projectPath = '') {
|
||||
}
|
||||
|
||||
export function getBlockFields(block = {}, type = 'content') {
|
||||
if (!block['field_groups']) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const fields_group = block['field_groups'].find((group) => group.name === type);
|
||||
const fields = [];
|
||||
|
||||
|
||||
@@ -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"),
|
||||
|
||||
Reference in New Issue
Block a user