Browse Source

Support missing images folder.

wordpress-build
Roman Axelrod 2 years ago
parent
commit
a1929fe33c
  1. 8
      helpers.js
  2. 4
      platforms/hubspot/hubspot-email-adapter.js
  3. 17
      platforms/wordpress/wordpress-adapter.js

8
helpers.js

@ -213,6 +213,14 @@ export async function uploadFile(filePath, uploadUrl, validator) {
export async function getImagesList(rootFolder, subFolder = '') { export async function getImagesList(rootFolder, subFolder = '') {
const imagesPath = path.join(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 images = await fs.readdir(imagesPath);
const imagesList = []; const imagesList = [];

4
platforms/hubspot/hubspot-email-adapter.js

@ -26,6 +26,10 @@ export async function createDistFolder(blockName, projectPath = '') {
} }
export function getBlockFields(block = {}, type = 'content') { export function getBlockFields(block = {}, type = 'content') {
if (!block['field_groups']) {
return [];
}
const fields_group = block['field_groups'].find((group) => group.name === type); const fields_group = block['field_groups'].find((group) => group.name === type);
const fields = []; const fields = [];

17
platforms/wordpress/wordpress-adapter.js

@ -1,5 +1,5 @@
import path from "path"; 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 {capitalize, createFiles, getBlockName, getConfigs, readJSONFile} from "../../helpers.js";
import {fileURLToPath} from 'url'; import {fileURLToPath} from 'url';
import {copy} from "fs-extra"; import {copy} from "fs-extra";
@ -68,10 +68,17 @@ export async function buildWordPress(blockName, args = {}) {
path.join(distPath, 'templates', 'scripts', `${data.blockFilename}.min.js`), path.join(distPath, 'templates', 'scripts', `${data.blockFilename}.min.js`),
); );
await copy( try {
path.join(projectPath, 'src', 'images'), const imagesPath = path.join(projectPath, 'src', 'images');
path.join(distPath, 'templates', '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', { const phpDataObject = await execPHPFile(path.join(phpGeneratorPath, 'build.php'), 'jsonToPhp', {
json: await readJSONFile(path.join(projectPath, 'data', 'default.json'), "utf8"), json: await readJSONFile(path.join(projectPath, 'data', 'default.json'), "utf8"),

Loading…
Cancel
Save