import cheerio from "cheerio"; import { replaceImportFromStaticInJsCode, generateCssCodeToDefineGlobals } from "../replaceImportFromStatic"; import fs from "fs"; import { join as pathJoin } from "path"; import { objectKeys } from "evt/tools/typeSafety/objectKeys"; export type PageId = "login.ftl" | "register.ftl" | "info.ftl" | "error.ftl"; function loadFtlFile(ftlFileBasename: PageId | "template.ftl") { return fs.readFileSync(pathJoin(__dirname, ftlFileBasename)) .toString("utf8") .match(/^', ' ', '', ].join("\n") }; $("head").prepend( [ ...(Object.keys(cssGlobalsToDefine).length === 0 ? [] : [ '', '', '' ]), '', '', objectKeys(ftlCommonPlaceholders)[1], '' ].join("\n"), ); const partiallyFixedIndexHtmlCode = $.html(); function generateFtlFilesCode( params: { pageId: PageId; } ): { ftlCode: string; } { const { pageId } = params; const $ = cheerio.load(partiallyFixedIndexHtmlCode); const ftlPlaceholders = { '{ "x": "kxOlLqMeOed9sdLdIdOxd444" }': loadFtlFile(pageId), ...ftlCommonPlaceholders }; $("head").prepend( [ '', '', '' ].join("\n") ); let ftlCode = $.html(); objectKeys(ftlPlaceholders) .forEach(id => ftlCode = ftlCode.replace(id, ftlPlaceholders[id])); return { ftlCode }; } return { generateFtlFilesCode }; }