From 9b8952336bd3aee3187d10678355c9b1228ecfd2 Mon Sep 17 00:00:00 2001 From: Joseph Garrone Date: Sat, 11 May 2024 23:20:15 +0200 Subject: [PATCH] Remove retrocompatiblity before re-introducing it --- src/bin/constants.ts | 1 - .../buildOptions/UserProvidedBuildOptions.ts | 4 +- .../keycloakify/buildOptions/buildOptions.ts | 2 - .../generateTheme/generateTheme.ts | 67 ++----------------- src/bin/keycloakify/keycloakify.ts | 19 +----- 5 files changed, 6 insertions(+), 87 deletions(-) diff --git a/src/bin/constants.ts b/src/bin/constants.ts index bea2eee8..84ba505a 100644 --- a/src/bin/constants.ts +++ b/src/bin/constants.ts @@ -6,7 +6,6 @@ export const resolvedViteConfigJsonBasename = "vite.json"; export const basenameOfTheKeycloakifyResourcesDir = "build"; export const themeTypes = ["login", "account"] as const; -export const retrocompatPostfix = "_retrocompat"; export const accountV1ThemeName = "account-v1"; export type ThemeType = (typeof themeTypes)[number]; diff --git a/src/bin/keycloakify/buildOptions/UserProvidedBuildOptions.ts b/src/bin/keycloakify/buildOptions/UserProvidedBuildOptions.ts index f4f5933e..ae555752 100644 --- a/src/bin/keycloakify/buildOptions/UserProvidedBuildOptions.ts +++ b/src/bin/keycloakify/buildOptions/UserProvidedBuildOptions.ts @@ -9,7 +9,6 @@ export type UserProvidedBuildOptions = { reactAppBuildDirPath?: string; keycloakifyBuildDirPath?: string; themeName?: string | string[]; - doBuildRetrocompatAccountTheme?: boolean; }; export const zUserProvidedBuildOptions = z.object({ @@ -20,6 +19,5 @@ export const zUserProvidedBuildOptions = z.object({ "loginThemeResourcesFromKeycloakVersion": z.string().optional(), "reactAppBuildDirPath": z.string().optional(), "keycloakifyBuildDirPath": z.string().optional(), - "themeName": z.union([z.string(), z.array(z.string())]).optional(), - "doBuildRetrocompatAccountTheme": z.boolean().optional() + "themeName": z.union([z.string(), z.array(z.string())]).optional() }); diff --git a/src/bin/keycloakify/buildOptions/buildOptions.ts b/src/bin/keycloakify/buildOptions/buildOptions.ts index 3f1550ed..68e13ffe 100644 --- a/src/bin/keycloakify/buildOptions/buildOptions.ts +++ b/src/bin/keycloakify/buildOptions/buildOptions.ts @@ -30,7 +30,6 @@ export type BuildOptions = { * In this case the urlPathname will be "/my-app/" */ urlPathname: string | undefined; assetsDirPath: string; - doBuildRetrocompatAccountTheme: boolean; npmWorkspaceRootDirPath: string; }; @@ -187,7 +186,6 @@ export function readBuildOptions(params: { processArgv: string[] }): BuildOption return pathJoin(reactAppBuildDirPath, resolvedViteConfig.assetsDir); })(), - "doBuildRetrocompatAccountTheme": userProvidedBuildOptions.doBuildRetrocompatAccountTheme ?? true, npmWorkspaceRootDirPath }; } diff --git a/src/bin/keycloakify/generateTheme/generateTheme.ts b/src/bin/keycloakify/generateTheme/generateTheme.ts index c39ada7c..db6f9532 100644 --- a/src/bin/keycloakify/generateTheme/generateTheme.ts +++ b/src/bin/keycloakify/generateTheme/generateTheme.ts @@ -1,6 +1,6 @@ import { transformCodebase } from "../../tools/transformCodebase"; import * as fs from "fs"; -import { join as pathJoin, basename as pathBasename, resolve as pathResolve, dirname as pathDirname } from "path"; +import { join as pathJoin, resolve as pathResolve, dirname as pathDirname } from "path"; import { replaceImportsInJsCode } from "../replacers/replaceImportsInJsCode"; import { replaceImportsInCssCode } from "../replacers/replaceImportsInCssCode"; import { generateFtlFilesCodeFactory, loginThemePageIds, accountThemePageIds } from "../generateFtl"; @@ -8,7 +8,6 @@ import { type ThemeType, lastKeycloakVersionWithAccountV1, keycloak_resources, - retrocompatPostfix, accountV1ThemeName, basenameOfTheKeycloakifyResourcesDir } from "../../constants"; @@ -32,7 +31,6 @@ export type BuildOptionsLike = { cacheDirPath: string; assetsDirPath: string; urlPathname: string | undefined; - doBuildRetrocompatAccountTheme: boolean; themeNames: string[]; npmWorkspaceRootDirPath: string; }; @@ -48,17 +46,9 @@ export async function generateTheme(params: { }): Promise { const { themeName, themeSrcDirPath, keycloakifySrcDirPath, buildOptions, keycloakifyVersion } = params; - const getThemeTypeDirPath = (params: { themeType: ThemeType | "email"; isRetrocompat?: true }) => { - const { themeType, isRetrocompat = false } = params; - return pathJoin( - buildOptions.keycloakifyBuildDirPath, - "src", - "main", - "resources", - "theme", - `${themeName}${isRetrocompat ? retrocompatPostfix : ""}`, - themeType - ); + const getThemeTypeDirPath = (params: { themeType: ThemeType | "email" }) => { + const { themeType } = params; + return pathJoin(buildOptions.keycloakifyBuildDirPath, "src", "main", "resources", "theme", themeName, themeType); }; const cssGlobalsToDefine: Record = {}; @@ -222,25 +212,6 @@ export async function generateTheme(params: { "utf8" ) ); - - if (themeType === "account" && buildOptions.doBuildRetrocompatAccountTheme) { - transformCodebase({ - "srcDirPath": themeTypeDirPath, - "destDirPath": getThemeTypeDirPath({ themeType, "isRetrocompat": true }), - "transformSourceCode": ({ filePath, sourceCode }) => { - if (pathBasename(filePath) === "theme.properties") { - return { - "modifiedSourceCode": Buffer.from( - sourceCode.toString("utf8").replace(`parent=${accountV1ThemeName}`, "parent=keycloak"), - "utf8" - ) - }; - } - - return { "modifiedSourceCode": sourceCode }; - } - }); - } } email: { @@ -280,36 +251,6 @@ export async function generateTheme(params: { "name": accountV1ThemeName, "types": ["account"] }); - - add_retrocompat_account_theme: { - if (!buildOptions.doBuildRetrocompatAccountTheme) { - break add_retrocompat_account_theme; - } - - transformCodebase({ - "srcDirPath": getThemeTypeDirPath({ "themeType": "account" }), - "destDirPath": getThemeTypeDirPath({ "themeType": "account", "isRetrocompat": true }), - "transformSourceCode": ({ filePath, sourceCode }) => { - if (pathBasename(filePath) === "theme.properties") { - return { - "modifiedSourceCode": Buffer.from( - sourceCode.toString("utf8").replace(`parent=${accountV1ThemeName}`, "parent=keycloak"), - "utf8" - ) - }; - } - - return { "modifiedSourceCode": sourceCode }; - } - }); - - buildOptions.themeNames.forEach(themeName => - parsedKeycloakThemeJson.themes.push({ - "name": `${themeName}${retrocompatPostfix}`, - "types": ["account"] - }) - ); - } } { diff --git a/src/bin/keycloakify/keycloakify.ts b/src/bin/keycloakify/keycloakify.ts index 2587373c..eb2be7e1 100644 --- a/src/bin/keycloakify/keycloakify.ts +++ b/src/bin/keycloakify/keycloakify.ts @@ -1,6 +1,6 @@ import { generateTheme } from "./generateTheme"; import { generatePom } from "./generatePom"; -import { join as pathJoin, relative as pathRelative, basename as pathBasename, dirname as pathDirname, sep as pathSep } from "path"; +import { join as pathJoin, relative as pathRelative, sep as pathSep } from "path"; import * as child_process from "child_process"; import { generateStartKeycloakTestingContainer } from "./generateStartKeycloakTestingContainer"; import * as fs from "fs"; @@ -69,23 +69,6 @@ export async function main() { } child_process.execSync("mvn clean install", { "cwd": buildOptions.keycloakifyBuildDirPath }); - - const jarDirPath = pathDirname(jarFilePath); - const retrocompatJarFilePath = pathJoin(jarDirPath, "retrocompat-" + pathBasename(jarFilePath)); - - fs.renameSync(pathJoin(jarDirPath, "original-" + pathBasename(jarFilePath)), retrocompatJarFilePath); - - fs.writeFileSync( - pathJoin(jarDirPath, "README.md"), - Buffer.from( - [ - `- The ${jarFilePath} is to be used in Keycloak 23 and up. `, - `- The ${retrocompatJarFilePath} is to be used in Keycloak 22 and below.`, - ` Note that Keycloak 22 is only supported for login and email theme but not for account themes. ` - ].join("\n"), - "utf8" - ) - ); } logger.log(