Support Hubspot pages.
This commit is contained in:
@@ -3,9 +3,10 @@
|
|||||||
|
|
||||||
import config from 'config';
|
import config from 'config';
|
||||||
import prompts from "prompts";
|
import prompts from "prompts";
|
||||||
import {buildHubspot} from "./platforms/hubspot/hubspot-adapter.js";
|
import {buildHubspotEmail} from "./platforms/hubspot/hubspot-email-adapter.js";
|
||||||
import {getConfigs} from "./helpers.js";
|
import {getConfigs} from "./helpers.js";
|
||||||
import {buildWordPress} from "./platforms/wordpress/wordpress-adapter.js";
|
import {buildWordPress} from "./platforms/wordpress/wordpress-adapter.js";
|
||||||
|
import {buildHubspotPage} from "./platforms/hubspot/hubspot-page-adapter.js";
|
||||||
|
|
||||||
const {isDev, developmentBlockName} = getConfigs();
|
const {isDev, developmentBlockName} = getConfigs();
|
||||||
const blockName = !isDev && config.has('blockName') ? config.get('blockName') : developmentBlockName;
|
const blockName = !isDev && config.has('blockName') ? config.get('blockName') : developmentBlockName;
|
||||||
@@ -51,9 +52,9 @@ export async function buildExportFiles(platform) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (platform.name === 'hubspot-email') {
|
} else if (platform.name === 'hubspot-email') {
|
||||||
await buildHubspot(blockName)
|
await buildHubspotEmail(blockName)
|
||||||
} else if (platform.name === 'hubspot') {
|
} else if (platform.name === 'hubspot') {
|
||||||
console.log('"Hubspot" Coming soon...');
|
await buildHubspotPage(blockName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
import {readFile, writeFile, mkdir, copyFile} from "fs/promises";
|
import {readFile, writeFile, mkdir, copyFile} from "fs/promises";
|
||||||
|
import {capitalize, getConfigs} from "../../helpers.js";
|
||||||
|
|
||||||
export async function buildHubspot(blockName) {
|
const {modulesPath, projectPath} = getConfigs();
|
||||||
|
|
||||||
|
export async function buildHubspotEmail(blockName) {
|
||||||
const distPath = `./exports/hubspot/${blockName}.module`;
|
const distPath = `./exports/hubspot/${blockName}.module`;
|
||||||
await mkdir(distPath, {recursive: true})
|
await mkdir(distPath, {recursive: true})
|
||||||
await copyFile(`./src/${blockName}.template.hbs`, `${distPath}/module.html`)
|
await copyFile(`${projectPath}/src/${blockName}.template.hbs`, `${distPath}/module.html`)
|
||||||
|
|
||||||
const metaData = {
|
const metaData = {
|
||||||
global: false,
|
global: false,
|
||||||
@@ -14,7 +17,7 @@ export async function buildHubspot(blockName) {
|
|||||||
|
|
||||||
await writeFile(`${distPath}/meta.json`, JSON.stringify(metaData, null, 4));
|
await writeFile(`${distPath}/meta.json`, JSON.stringify(metaData, null, 4));
|
||||||
|
|
||||||
const blockJSON = await readFile(`./block.json`, "utf8");
|
const blockJSON = await readFile(`${projectPath}/block.json`, "utf8");
|
||||||
const block = JSON.parse(blockJSON);
|
const block = JSON.parse(blockJSON);
|
||||||
|
|
||||||
const fields = getBlockFields(block, 'content');
|
const fields = getBlockFields(block, 'content');
|
||||||
@@ -30,8 +33,9 @@ export async function buildHubspot(blockName) {
|
|||||||
type: 'group',
|
type: 'group',
|
||||||
name: 'style',
|
name: 'style',
|
||||||
label: "Style",
|
label: "Style",
|
||||||
sub_fields: stylingFieldsByName,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
stylingGroup.children = Object.values(stylingFieldsByName);
|
||||||
stylingGroup.tab = "STYLE";
|
stylingGroup.tab = "STYLE";
|
||||||
|
|
||||||
fields.push(stylingGroup);
|
fields.push(stylingGroup);
|
||||||
@@ -41,7 +45,7 @@ export async function buildHubspot(blockName) {
|
|||||||
await writeFile(`${distPath}/fields.json`, JSON.stringify(fields, null, 4));
|
await writeFile(`${distPath}/fields.json`, JSON.stringify(fields, null, 4));
|
||||||
}
|
}
|
||||||
|
|
||||||
function getBlockFields(block = {}, type = 'content') {
|
export function getBlockFields(block = {}, type = 'content') {
|
||||||
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 = [];
|
||||||
|
|
||||||
@@ -61,7 +65,7 @@ function getBlockFields(block = {}, type = 'content') {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function convertToHubspotField(field = {}) {
|
export function convertToHubspotField(field = {}) {
|
||||||
const data = {
|
const data = {
|
||||||
id: field.name,
|
id: field.name,
|
||||||
name: field.name,
|
name: field.name,
|
||||||
@@ -70,9 +74,12 @@ function convertToHubspotField(field = {}) {
|
|||||||
validation_regex: "",
|
validation_regex: "",
|
||||||
required: false,
|
required: false,
|
||||||
locked: false,
|
locked: false,
|
||||||
default: field.default
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (field.default) {
|
||||||
|
data.default = field.default;
|
||||||
|
}
|
||||||
|
|
||||||
let sub_fields = [];
|
let sub_fields = [];
|
||||||
|
|
||||||
switch (field.type) {
|
switch (field.type) {
|
||||||
@@ -111,12 +118,12 @@ function convertToHubspotField(field = {}) {
|
|||||||
display: "checkbox",
|
display: "checkbox",
|
||||||
});
|
});
|
||||||
case 'select':
|
case 'select':
|
||||||
const choices = [];
|
const options = [];
|
||||||
Object.keys(data.choices).forEach(value => choices.push([value, data.choices[value]]));
|
Object.keys(field.options).forEach(value => options.push([value, field.options[value]]));
|
||||||
|
|
||||||
return Object.assign({}, data, {
|
return Object.assign({}, data, {
|
||||||
type: "select",
|
type: "choice",
|
||||||
choices: [choices]
|
choices: options
|
||||||
});
|
});
|
||||||
case 'link':
|
case 'link':
|
||||||
return Object.assign({}, data, {
|
return Object.assign({}, data, {
|
||||||
@@ -224,18 +231,3 @@ function convertToHubspotField(field = {}) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function capitalize(str) {
|
|
||||||
if (typeof str !== 'string') {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
return str
|
|
||||||
.toLowerCase()
|
|
||||||
.split(/[ -_]/g)
|
|
||||||
.filter((word) => !!word)
|
|
||||||
.map((word) => {
|
|
||||||
return word.charAt(0).toUpperCase() + word.slice(1);
|
|
||||||
})
|
|
||||||
.join(' ');
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
import path from "path";
|
||||||
|
import {readFile, writeFile, mkdir, copyFile} from "fs/promises";
|
||||||
|
import {copy} from "fs-extra";
|
||||||
|
import {capitalize, getConfigs} from "../../helpers.js";
|
||||||
|
import {convertToHubspotField, getBlockFields} from "./hubspot-email-adapter.js";
|
||||||
|
|
||||||
|
const {modulesPath, projectPath} = getConfigs();
|
||||||
|
|
||||||
|
export async function buildHubspotPage(blockName) {
|
||||||
|
const distPath = `./exports/hubspot/${blockName}.module`;
|
||||||
|
await mkdir(distPath, {recursive: true})
|
||||||
|
await copyFile(`${projectPath}/src/${blockName}.template.hbs`, `${distPath}/module.html`)
|
||||||
|
await copyFile(`${projectPath}/src/styles/${blockName}.min.css`, `${distPath}/module.css`)
|
||||||
|
await copyFile(`${projectPath}/src/scripts/${blockName}.min.js`, `${distPath}/module.js`)
|
||||||
|
|
||||||
|
await copy(
|
||||||
|
path.join(projectPath, 'src', 'images'),
|
||||||
|
path.join(distPath, 'images'),
|
||||||
|
);
|
||||||
|
|
||||||
|
const metaData = {
|
||||||
|
global: false,
|
||||||
|
host_template_types: ["PAGE"],
|
||||||
|
label: capitalize(blockName),
|
||||||
|
is_available_for_new_content: true
|
||||||
|
}
|
||||||
|
|
||||||
|
await writeFile(`${distPath}/meta.json`, JSON.stringify(metaData, null, 4));
|
||||||
|
|
||||||
|
const blockJSON = await readFile(`${projectPath}/block.json`, "utf8");
|
||||||
|
const block = JSON.parse(blockJSON);
|
||||||
|
|
||||||
|
const fields = getBlockFields(block, 'content');
|
||||||
|
|
||||||
|
// Styling TAB.
|
||||||
|
const stylingFields = getBlockFields(block, 'styling');
|
||||||
|
|
||||||
|
if (stylingFields.length) {
|
||||||
|
const stylingFieldsByName = {};
|
||||||
|
stylingFields.forEach(field => stylingFieldsByName[field.name] = field);
|
||||||
|
|
||||||
|
const stylingGroup = convertToHubspotField({
|
||||||
|
type: 'group',
|
||||||
|
name: 'style',
|
||||||
|
label: "Style",
|
||||||
|
});
|
||||||
|
|
||||||
|
stylingGroup.children = Object.values(stylingFieldsByName);
|
||||||
|
stylingGroup.tab = "STYLE";
|
||||||
|
|
||||||
|
fields.push(stylingGroup);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Export JSON file.
|
||||||
|
await writeFile(`${distPath}/fields.json`, JSON.stringify(fields, null, 4));
|
||||||
|
}
|
||||||
@@ -1,9 +1,8 @@
|
|||||||
import path from "path";
|
import path from "path";
|
||||||
import {mkdir, copyFile, readFile} from "fs/promises";
|
import {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";
|
||||||
import fsExtra from "fs-extra";
|
|
||||||
import {exec} from 'child_process';
|
import {exec} from 'child_process';
|
||||||
import execPhp from "exec-php";
|
import execPhp from "exec-php";
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user