From c8ca598465f319cbe5a01b3e6ffa684beb6821c6 Mon Sep 17 00:00:00 2001 From: Joseph Garrone Date: Fri, 27 Sep 2024 23:45:14 +0200 Subject: [PATCH] Refactor --- .../generateResources/generateResources.ts | 65 +++++++------------ 1 file changed, 22 insertions(+), 43 deletions(-) diff --git a/src/bin/keycloakify/generateResources/generateResources.ts b/src/bin/keycloakify/generateResources/generateResources.ts index 0748973e..f029a6f9 100644 --- a/src/bin/keycloakify/generateResources/generateResources.ts +++ b/src/bin/keycloakify/generateResources/generateResources.ts @@ -225,11 +225,6 @@ export async function generateResources(params: { writeMessagePropertiesFilesByThemeType[themeType] = writeMessagePropertiesFiles; - - writeMessagePropertiesFiles({ - messageDirPath: pathJoin(themeTypeDirPath, "messages"), - themeName - }); } bring_in_account_v3_i18n_messages: { @@ -392,12 +387,14 @@ export async function generateResources(params: { { const metaInfKeycloakThemes: MetaInfKeycloakTheme = { themes: [] }; - metaInfKeycloakThemes.themes.push({ - name: themeName, - types: objectEntries(buildContext.implementedThemeTypes) - .filter(([, { isImplemented }]) => isImplemented) - .map(([themeType]) => themeType) - }); + for (const themeName of buildContext.themeNames) { + metaInfKeycloakThemes.themes.push({ + name: themeName, + types: objectEntries(buildContext.implementedThemeTypes) + .filter(([, { isImplemented }]) => isImplemented) + .map(([themeType]) => themeType) + }); + } if (buildContext.implementedThemeTypes.account.isImplemented) { metaInfKeycloakThemes.themes.push({ @@ -445,36 +442,22 @@ export async function generateResources(params: { return { modifiedSourceCode: sourceCode }; } }); + } - writeMetaInfKeycloakThemes({ - resourcesDirPath, - getNewMetaInfKeycloakTheme: ({ metaInfKeycloakTheme }) => { - assert(metaInfKeycloakTheme !== undefined); - - const newMetaInfKeycloakTheme = metaInfKeycloakTheme; - - newMetaInfKeycloakTheme.themes.push({ - name: themeVariantName, - types: (() => { - const theme = newMetaInfKeycloakTheme.themes.find( - ({ name }) => name === themeName - ); - assert(theme !== undefined); - return theme.types; - })() - }); - - return newMetaInfKeycloakTheme; - } - }); - + for (const themeName of buildContext.themeNames) { objectEntries(writeMessagePropertiesFilesByThemeType).forEach( ([themeType, writeMessagePropertiesFiles]) => { if (writeMessagePropertiesFiles === undefined) { return; } writeMessagePropertiesFiles({ - messageDirPath: pathJoin(themeVariantDirPath, themeType, "messages"), + messageDirPath: pathJoin( + resourcesDirPath, + "theme", + themeName, + themeType, + "messages" + ), themeName }); } @@ -486,15 +469,14 @@ export async function generateResources(params: { break email; } - for (const themeVariantName of buildContext.themeNames) { - const themeVariantDirPath = pathJoin( + for (const themeName of buildContext.themeNames) { + const emailThemeDirPath = pathJoin( resourcesDirPath, "theme", - themeVariantName + themeName, + "email" ); - const emailThemeDirPath = pathJoin(themeVariantDirPath, "email"); - transformCodebase({ srcDirPath: emailThemeDirPath, destDirPath: emailThemeDirPath, @@ -507,10 +489,7 @@ export async function generateResources(params: { modifiedSourceCode: Buffer.from( sourceCode .toString("utf8") - .replace( - /xKeycloakify.themeName/g, - `"${themeVariantName}"` - ), + .replace(/xKeycloakify.themeName/g, `"${themeName}"`), "utf8" ) };