|
|
|
@ -1,48 +1,27 @@ |
|
|
|
import path from "path"; |
|
|
|
import {readFile, writeFile, mkdir, copyFile} from "fs/promises"; |
|
|
|
import {capitalize, getConfigs} from "../../helpers.js"; |
|
|
|
|
|
|
|
const {modulesPath, projectPath} = getConfigs(); |
|
|
|
|
|
|
|
export async function buildHubspotEmail(blockName) { |
|
|
|
const distPath = `./exports/hubspot/${blockName}.module`; |
|
|
|
await mkdir(distPath, {recursive: true}) |
|
|
|
const distPath = await createDistFolder(blockName); |
|
|
|
|
|
|
|
await copyFile(`${projectPath}/src/${blockName}.template.hbs`, `${distPath}/module.html`) |
|
|
|
|
|
|
|
const metaData = { |
|
|
|
await buildHubspotJSONFiles(distPath, { |
|
|
|
global: false, |
|
|
|
host_template_types: ["EMAIL"], |
|
|
|
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)); |
|
|
|
export async function createDistFolder(blockName) { |
|
|
|
const distPath = path.join('exports', 'hubspot', `${blockName}.module`); |
|
|
|
await mkdir(distPath, {recursive: true}) |
|
|
|
|
|
|
|
return distPath; |
|
|
|
} |
|
|
|
|
|
|
|
export function getBlockFields(block = {}, type = 'content') { |
|
|
|
@ -231,3 +210,34 @@ export function convertToHubspotField(field = {}) { |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
export async function buildHubspotJSONFiles(distPath, metaData) { |
|
|
|
await writeFile(path.join(distPath, 'meta.json'), JSON.stringify(metaData, null, 4)); |
|
|
|
|
|
|
|
const blockJSON = await readFile(path.join(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(path.join(distPath, 'fields.json'), JSON.stringify(fields, null, 4)); |
|
|
|
} |
|
|
|
|