|
|
|
@ -7,8 +7,11 @@ const {modulesPath, projectPath} = getConfigs(); |
|
|
|
export async function buildHubspotEmail(blockName) { |
|
|
|
const distPath = await createDistFolder(blockName); |
|
|
|
|
|
|
|
await copyFile(`${projectPath}/src/${blockName}.template.hbs`, `${distPath}/module.html`) |
|
|
|
// Template
|
|
|
|
let handlebars = await readFile(path.join(srcPath, `${blockName}.template.hbs`), "utf8"); |
|
|
|
await writeFile(path.join(distPath, 'module.html'), handlebarsToHubl(handlebars)); |
|
|
|
|
|
|
|
// JSON
|
|
|
|
await buildHubspotJSONFiles(distPath, { |
|
|
|
global: false, |
|
|
|
host_template_types: ["EMAIL"], |
|
|
|
@ -243,3 +246,23 @@ export async function buildHubspotJSONFiles(distPath, metaData) { |
|
|
|
// Export JSON file.
|
|
|
|
await writeFile(path.join(distPath, 'fields.json'), JSON.stringify(fields, null, 4)); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function handlebarsToHubl(handlebars) { |
|
|
|
handlebars = handlebars.replace(/{{#if /g, '{% if module.'); |
|
|
|
handlebars = handlebars.replace(/{{\/if}}/g, '{% endif %}'); |
|
|
|
handlebars = handlebars.replace(/{{#each /g, '{% for module.'); |
|
|
|
handlebars = handlebars.replace(/{{\/each}}/g, '{% endfor %}'); |
|
|
|
handlebars = handlebars.replace(/{{base_url}}/g, ''); |
|
|
|
handlebars = handlebars.replace(/{esc_attr /g, '{'); |
|
|
|
handlebars = handlebars.replace(/{esc_url /g, '{'); |
|
|
|
handlebars = handlebars.replace(/{esc_html /g, '{'); |
|
|
|
handlebars = handlebars.replace(/{{{ /g, '{{'); |
|
|
|
handlebars = handlebars.replace(/ }}}/g, '}}'); |
|
|
|
handlebars = handlebars.replace(/{{{/g, '{{'); |
|
|
|
handlebars = handlebars.replace(/}}}/g, '}}'); |
|
|
|
handlebars = handlebars.replace(/{{/g, '{{module.'); |
|
|
|
handlebars = handlebars.replace(/{{module. /g, '{{ module.'); |
|
|
|
|
|
|
|
return handlebars; |
|
|
|
} |
|
|
|
|