Skip to content

Commit

Permalink
remove templateName rename for user_attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
fbianchicodermine committed Nov 25, 2024
1 parent c881c7a commit b98a70d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 41 deletions.
11 changes: 4 additions & 7 deletions scripts/templates-builder/src/generateHtmlTemplates.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const {
BASE_SOURCE_DIR,
loadTranslations,
BASE_OUTPUT_DIR,
getOutputTemplateName,
getOutputFileName,
} = require("./utils");
const log = require("./logger");
Expand All @@ -23,7 +22,6 @@ async function generateHtmlTemplate() {

for (const entry of entries) {
const templateName = entry.name;
const outputTemplateName = getOutputTemplateName(templateName);

if (!entry.isDirectory() || entry.name === "partials") {
continue;
Expand Down Expand Up @@ -61,7 +59,7 @@ async function generateHtmlTemplate() {
if (!hasLanguages) {
const outputFileName = getOutputFileName(templateName);
await renderAndWriteFile({
templateName: outputTemplateName,
templateName,
fileName: outputFileName,
content: templateContent,
});
Expand All @@ -85,7 +83,7 @@ async function generateHtmlTemplate() {
"utf8"
);
await renderAndWriteFile({
templateName: outputTemplateName,
templateName,
fileName: outputFileName,
content: langContent,
});
Expand All @@ -95,7 +93,7 @@ async function generateHtmlTemplate() {
const translations = await loadTranslations(lang, templateDir);

await renderAndWriteFile({
templateName: outputTemplateName,
templateName,
fileName: outputFileName,
content: templateContent,
renderData: {
Expand Down Expand Up @@ -123,10 +121,9 @@ async function renderAndWriteFile({
content,
renderData,
}) {
const outputTemplateName = templateName;
const outputFileName = fileName;

const outputDir = path.join(BASE_OUTPUT_DIR, "templates", outputTemplateName);
const outputDir = path.join(BASE_OUTPUT_DIR, "templates", templateName);
await fs.ensureDir(outputDir);

const outputFile = path.join(outputDir, `${outputFileName}.html`);
Expand Down
18 changes: 2 additions & 16 deletions scripts/templates-builder/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,16 @@ async function loadTranslations(language, templateDir) {
return { ...itaContent, ...lngContent };
}

// TODO: discuss this solution (and template name) with the team
const RENAME_FOR_USER_ATTRIBUTES = {
Mail_VerificationCode: "emailbody",
PEC_VerificationCodeMessage: "pecbody",
PEC_ValidationContactsSuccessMessage: "pecbodyconfirm",
PEC_ValidationContactsRejectMessage: "pecbodyreject",
};

function getOutputTemplateName(templateName) {
return RENAME_FOR_USER_ATTRIBUTES[templateName] || templateName;
}

function getOutputFileName(templateName, language) {
const template = getOutputTemplateName(templateName);
if (!language || language === "it") {
return template;
return templateName;
}
return `${template}_${language}`;
return `${templateName}_${language}`;
}

module.exports = {
BASE_SOURCE_DIR,
BASE_OUTPUT_DIR,
loadTranslations,
getOutputTemplateName,
getOutputFileName,
};
18 changes: 0 additions & 18 deletions scripts/templates-builder/test/utils.test.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,16 @@
const path = require("node:path");
const {
getOutputTemplateName,
getOutputFileName,
loadTranslations,
BASE_SOURCE_DIR,
} = require("../src/utils");

describe("getOutputTemplateName", () => {
it.each([
["Some_Other_Template", "Some_Other_Template"],
["Mail_VerificationCode", "emailbody"],
["PEC_VerificationCodeMessage", "pecbody"],
["PEC_ValidationContactsSuccessMessage", "pecbodyconfirm"],
["PEC_ValidationContactsRejectMessage", "pecbodyreject"],
])(
"should return the renamed template name for %s",
(input, expected) => {
expect(getOutputTemplateName(input)).toBe(expected);
}
);
});

describe("getOutputFileName", () => {
it.each([
["TestTemplateName", undefined, "TestTemplateName"],
["TestTemplateName", "it", "TestTemplateName"],
["TestTemplateName", "en", "TestTemplateName_en"],
["TestTemplateName", "fr", "TestTemplateName_fr"],
["Mail_VerificationCode", "en", "emailbody_en"],
["PEC_VerificationCodeMessage", "fr", "pecbody_fr"],
])(
"should return the correct output file name for template %s with language %s",
(templateName, lang, expected) => {
Expand Down

0 comments on commit b98a70d

Please sign in to comment.