2 changed files with 52 additions and 73 deletions
@ -1,56 +1,25 @@ |
|||||
import path from "path"; |
import path from "path"; |
||||
import {readFile, writeFile, mkdir, copyFile} from "fs/promises"; |
import {copyFile} from "fs/promises"; |
||||
import {copy} from "fs-extra"; |
import {copy} from "fs-extra"; |
||||
import {capitalize, getConfigs} from "../../helpers.js"; |
import {capitalize, getConfigs} from "../../helpers.js"; |
||||
import {convertToHubspotField, getBlockFields} from "./hubspot-email-adapter.js"; |
import {buildHubspotJSONFiles, createDistFolder,} from "./hubspot-email-adapter.js"; |
||||
|
|
||||
const {modulesPath, projectPath} = getConfigs(); |
const {modulesPath, projectPath} = getConfigs(); |
||||
|
|
||||
export async function buildHubspotPage(blockName) { |
export async function buildHubspotPage(blockName) { |
||||
const distPath = `./exports/hubspot/${blockName}.module`; |
const distPath = await createDistFolder(blockName); |
||||
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( |
const srcPath = path.join(projectPath, 'src'); |
||||
path.join(projectPath, 'src', 'images'), |
await copyFile(path.join(srcPath, `${blockName}.template.hbs`), path.join(distPath, 'module.html')); |
||||
path.join(distPath, 'images'), |
await copyFile(path.join(srcPath, 'styles', `${blockName}.min.css`), path.join(distPath, 'module.css')); |
||||
); |
await copyFile(path.join(srcPath, 'scripts', `${blockName}.min.js`), path.join(distPath, 'module.js')); |
||||
|
await copy(path.join(projectPath, 'src', 'images'), path.join(distPath, 'images')); |
||||
|
|
||||
const metaData = { |
await buildHubspotJSONFiles(distPath, { |
||||
global: false, |
global: false, |
||||
host_template_types: ["PAGE"], |
host_template_types: ["PAGE"], |
||||
label: capitalize(blockName), |
label: capitalize(blockName), |
||||
is_available_for_new_content: true |
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)); |
|
||||
} |
} |
||||
|
|
||||
|
|||||
Loading…
Reference in new issue