diff --git a/src/bin/keycloakify/buildJars/buildJar.ts b/src/bin/keycloakify/buildJars/buildJar.ts index 4a952343..96bb6e2b 100644 --- a/src/bin/keycloakify/buildJars/buildJar.ts +++ b/src/bin/keycloakify/buildJars/buildJar.ts @@ -15,7 +15,6 @@ import { readFileSync } from "fs"; import { isInside } from "../../tools/isInside"; import child_process from "child_process"; import { rmSync } from "../../tools/fs.rmSync"; -import { writeMetaInfKeycloakThemes } from "../../shared/metaInfKeycloakThemes"; import { existsAsync } from "../../tools/fs.existsAsync"; export type BuildContextLike = BuildContextLike_generatePom & { @@ -106,29 +105,45 @@ export async function buildJar(params: { } }); - remove_account_v1_in_meta_inf: { - if (!doesImplementAccountV1Theme) { - // NOTE: We do not have account v1 anyway - break remove_account_v1_in_meta_inf; - } + { + const filePath = pathJoin( + tmpResourcesDirPath, + "META-INF", + "keycloak-themes.json" + ); - if (keycloakAccountV1Version !== null) { - // NOTE: No, we need to keep account-v1 in meta-inf - break remove_account_v1_in_meta_inf; - } + await fs.mkdir(pathDirname(filePath)); - writeMetaInfKeycloakThemes({ - resourcesDirPath: tmpResourcesDirPath, - getNewMetaInfKeycloakTheme: ({ metaInfKeycloakTheme }) => { - assert(metaInfKeycloakTheme !== undefined); + await fs.writeFile( + filePath, + Buffer.from( + JSON.stringify( + { + themes: await (async () => { + const dirPath = pathJoin(tmpResourcesDirPath, "theme"); - metaInfKeycloakTheme.themes = metaInfKeycloakTheme.themes.filter( - ({ name }) => name !== "account-v1" - ); + const themeNames = await fs.readdir(dirPath); - return metaInfKeycloakTheme; - } - }); + return Promise.all( + themeNames.map(async themeName => { + const types = await fs.readdir( + pathJoin(dirPath, themeName) + ); + + return { + name: themeName, + types + }; + }) + ); + })() + }, + null, + 2 + ), + "utf8" + ) + ); } route_legacy_pages: { diff --git a/src/bin/keycloakify/generateResources/generateResources.ts b/src/bin/keycloakify/generateResources/generateResources.ts index ec772547..04ac6fe8 100644 --- a/src/bin/keycloakify/generateResources/generateResources.ts +++ b/src/bin/keycloakify/generateResources/generateResources.ts @@ -31,11 +31,6 @@ import { type BuildContextLike as BuildContextLike_generateMessageProperties } from "./generateMessageProperties"; import { readThisNpmPackageVersion } from "../../tools/readThisNpmPackageVersion"; -import { - writeMetaInfKeycloakThemes, - type MetaInfKeycloakTheme -} from "../../shared/metaInfKeycloakThemes"; -import { objectEntries } from "tsafe/objectEntries"; import { escapeStringForPropertiesFile } from "../../tools/escapeStringForPropertiesFile"; import { getThisCodebaseRootDirPath } from "../../tools/getThisCodebaseRootDirPath"; import propertiesParser from "properties-parser"; @@ -770,33 +765,4 @@ export async function generateResources(params: { } } } - - // Generate meta-inf/keycloak-themes.json - { - const metaInfKeycloakThemes: MetaInfKeycloakTheme = { themes: [] }; - - for (const themeName of buildContext.themeNames) { - metaInfKeycloakThemes.themes.push({ - name: themeName, - types: objectEntries(buildContext.implementedThemeTypes) - .filter(([, v]) => v.isImplemented || v.isImplemented_native) - .map(([themeType]) => themeType) - }); - } - - if ( - buildContext.implementedThemeTypes.account.isImplemented && - buildContext.implementedThemeTypes.account.type === "Multi-Page" - ) { - metaInfKeycloakThemes.themes.push({ - name: "account-v1", - types: ["account"] - }); - } - - writeMetaInfKeycloakThemes({ - resourcesDirPath, - getNewMetaInfKeycloakTheme: () => metaInfKeycloakThemes - }); - } } diff --git a/src/bin/shared/metaInfKeycloakThemes.ts b/src/bin/shared/metaInfKeycloakThemes.ts deleted file mode 100644 index ef55b078..00000000 --- a/src/bin/shared/metaInfKeycloakThemes.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { join as pathJoin, dirname as pathDirname } from "path"; -import type { ThemeType } from "./constants"; -import * as fs from "fs"; - -export type MetaInfKeycloakTheme = { - themes: { name: string; types: (ThemeType | "email")[] }[]; -}; - -export function writeMetaInfKeycloakThemes(params: { - resourcesDirPath: string; - getNewMetaInfKeycloakTheme: (params: { - metaInfKeycloakTheme: MetaInfKeycloakTheme | undefined; - }) => MetaInfKeycloakTheme; -}) { - const { resourcesDirPath, getNewMetaInfKeycloakTheme } = params; - - const filePath = pathJoin(resourcesDirPath, "META-INF", "keycloak-themes.json"); - - const currentMetaInfKeycloakTheme = !fs.existsSync(filePath) - ? undefined - : (JSON.parse( - fs.readFileSync(filePath).toString("utf8") - ) as MetaInfKeycloakTheme); - - const newMetaInfKeycloakThemes = getNewMetaInfKeycloakTheme({ - metaInfKeycloakTheme: currentMetaInfKeycloakTheme - }); - - { - const dirPath = pathDirname(filePath); - if (!fs.existsSync(dirPath)) { - fs.mkdirSync(dirPath, { recursive: true }); - } - } - - fs.writeFileSync( - filePath, - Buffer.from(JSON.stringify(newMetaInfKeycloakThemes, null, 2), "utf8") - ); -}