Reintroduce doBuildRetrocompatAccountTheme (for now)

This commit is contained in:
Joseph Garrone 2024-02-04 10:25:48 +01:00
parent 75c54df109
commit a29b6097a4
6 changed files with 53 additions and 8 deletions

View File

@ -6,6 +6,7 @@ export const resolvedViteConfigJsonBasename = ".keycloakifyViteConfig.json";
export const basenameOfTheKeycloakifyResourcesDir = "build"; export const basenameOfTheKeycloakifyResourcesDir = "build";
export const themeTypes = ["login", "account"] as const; export const themeTypes = ["login", "account"] as const;
export const retrocompatPostfix = "_retrocompat";
export const accountV1ThemeName = "account-v1"; export const accountV1ThemeName = "account-v1";
export type ThemeType = (typeof themeTypes)[number]; export type ThemeType = (typeof themeTypes)[number];

View File

@ -27,6 +27,7 @@ export type BuildOptions = {
* In this case the urlPathname will be "/my-app/" */ * In this case the urlPathname will be "/my-app/" */
urlPathname: string | undefined; urlPathname: string | undefined;
assetsDirPath: string; assetsDirPath: string;
doBuildRetrocompatAccountTheme: boolean;
}; };
export function readBuildOptions(params: { reactAppRootDirPath: string; processArgv: string[] }): BuildOptions { export function readBuildOptions(params: { reactAppRootDirPath: string; processArgv: string[] }): BuildOptions {
@ -178,6 +179,7 @@ export function readBuildOptions(params: { reactAppRootDirPath: string; processA
} }
return pathJoin(reactAppBuildDirPath, resolvedViteConfig.assetsDir); return pathJoin(reactAppBuildDirPath, resolvedViteConfig.assetsDir);
})() })(),
"doBuildRetrocompatAccountTheme": parsedPackageJson.keycloakify?.doBuildRetrocompatAccountTheme ?? true
}; };
} }

View File

@ -17,6 +17,7 @@ export type ParsedPackageJson = {
reactAppBuildDirPath?: string; reactAppBuildDirPath?: string;
keycloakifyBuildDirPath?: string; keycloakifyBuildDirPath?: string;
themeName?: string | string[]; themeName?: string | string[];
doBuildRetrocompatAccountTheme?: boolean;
}; };
}; };
@ -33,7 +34,8 @@ const zParsedPackageJson = z.object({
"loginThemeResourcesFromKeycloakVersion": z.string().optional(), "loginThemeResourcesFromKeycloakVersion": z.string().optional(),
"reactAppBuildDirPath": z.string().optional(), "reactAppBuildDirPath": z.string().optional(),
"keycloakifyBuildDirPath": z.string().optional(), "keycloakifyBuildDirPath": z.string().optional(),
"themeName": z.union([z.string(), z.array(z.string())]).optional() "themeName": z.union([z.string(), z.array(z.string())]).optional(),
"doBuildRetrocompatAccountTheme": z.boolean().optional()
}) })
.optional() .optional()
}); });

View File

@ -3,7 +3,7 @@ import { join as pathJoin, dirname as pathDirname } from "path";
import { assert } from "tsafe/assert"; import { assert } from "tsafe/assert";
import { Reflect } from "tsafe/Reflect"; import { Reflect } from "tsafe/Reflect";
import type { BuildOptions } from "../buildOptions"; import type { BuildOptions } from "../buildOptions";
import { type ThemeType, accountV1ThemeName } from "../../constants"; import { type ThemeType, retrocompatPostfix, accountV1ThemeName } from "../../constants";
import { bringInAccountV1 } from "./bringInAccountV1"; import { bringInAccountV1 } from "./bringInAccountV1";
type BuildOptionsLike = { type BuildOptionsLike = {
@ -13,6 +13,7 @@ type BuildOptionsLike = {
cacheDirPath: string; cacheDirPath: string;
keycloakifyBuildDirPath: string; keycloakifyBuildDirPath: string;
themeNames: string[]; themeNames: string[];
doBuildRetrocompatAccountTheme: boolean;
}; };
{ {
@ -113,7 +114,15 @@ export async function generateJavaStackFiles(params: {
"types": Object.entries(implementedThemeTypes) "types": Object.entries(implementedThemeTypes)
.filter(([, isImplemented]) => isImplemented) .filter(([, isImplemented]) => isImplemented)
.map(([themeType]) => themeType) .map(([themeType]) => themeType)
} },
...(!implementedThemeTypes.account || !buildOptions.doBuildRetrocompatAccountTheme
? []
: [
{
"name": `${themeName}${retrocompatPostfix}`,
"types": ["account"]
}
])
]) ])
.flat() .flat()
] ]

View File

@ -1,6 +1,6 @@
import { transformCodebase } from "../../tools/transformCodebase"; import { transformCodebase } from "../../tools/transformCodebase";
import * as fs from "fs"; import * as fs from "fs";
import { join as pathJoin, resolve as pathResolve } from "path"; import { join as pathJoin, basename as pathBasename, resolve as pathResolve } from "path";
import { replaceImportsInJsCode } from "../replacers/replaceImportsInJsCode"; import { replaceImportsInJsCode } from "../replacers/replaceImportsInJsCode";
import { replaceImportsInCssCode } from "../replacers/replaceImportsInCssCode"; import { replaceImportsInCssCode } from "../replacers/replaceImportsInCssCode";
import { generateFtlFilesCodeFactory, loginThemePageIds, accountThemePageIds } from "../generateFtl"; import { generateFtlFilesCodeFactory, loginThemePageIds, accountThemePageIds } from "../generateFtl";
@ -9,6 +9,7 @@ import {
type ThemeType, type ThemeType,
lastKeycloakVersionWithAccountV1, lastKeycloakVersionWithAccountV1,
keycloak_resources, keycloak_resources,
retrocompatPostfix,
accountV1ThemeName, accountV1ThemeName,
basenameOfTheKeycloakifyResourcesDir basenameOfTheKeycloakifyResourcesDir
} from "../../constants"; } from "../../constants";
@ -31,6 +32,7 @@ export type BuildOptionsLike = {
cacheDirPath: string; cacheDirPath: string;
assetsDirPath: string; assetsDirPath: string;
urlPathname: string | undefined; urlPathname: string | undefined;
doBuildRetrocompatAccountTheme: boolean;
}; };
assert<BuildOptions extends BuildOptionsLike ? true : false>(); assert<BuildOptions extends BuildOptionsLike ? true : false>();
@ -44,9 +46,17 @@ export async function generateTheme(params: {
}): Promise<void> { }): Promise<void> {
const { themeName, themeSrcDirPath, keycloakifySrcDirPath, buildOptions, keycloakifyVersion } = params; const { themeName, themeSrcDirPath, keycloakifySrcDirPath, buildOptions, keycloakifyVersion } = params;
const getThemeTypeDirPath = (params: { themeType: ThemeType | "email" }) => { const getThemeTypeDirPath = (params: { themeType: ThemeType | "email"; isRetrocompat?: true }) => {
const { themeType } = params; const { themeType, isRetrocompat = false } = params;
return pathJoin(buildOptions.keycloakifyBuildDirPath, "src", "main", "resources", "theme", themeName, themeType); return pathJoin(
buildOptions.keycloakifyBuildDirPath,
"src",
"main",
"resources",
"theme",
`${themeName}${isRetrocompat ? retrocompatPostfix : ""}`,
themeType
);
}; };
let allCssGlobalsToDefine: Record<string, string> = {}; let allCssGlobalsToDefine: Record<string, string> = {};
@ -197,6 +207,25 @@ export async function generateTheme(params: {
"utf8" "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: { email: {

View File

@ -1,6 +1,7 @@
import { getLatestsSemVersionedTagFactory } from "./tools/octokit-addons/getLatestsSemVersionedTag"; import { getLatestsSemVersionedTagFactory } from "./tools/octokit-addons/getLatestsSemVersionedTag";
import { Octokit } from "@octokit/rest"; import { Octokit } from "@octokit/rest";
import cliSelect from "cli-select"; import cliSelect from "cli-select";
import { lastKeycloakVersionWithAccountV1 } from "./constants";
export async function promptKeycloakVersion() { export async function promptKeycloakVersion() {
const { getLatestsSemVersionedTag } = (() => { const { getLatestsSemVersionedTag } = (() => {
@ -26,6 +27,7 @@ export async function promptKeycloakVersion() {
"owner": "keycloak", "owner": "keycloak",
"repo": "keycloak" "repo": "keycloak"
}).then(arr => arr.map(({ tag }) => tag))), }).then(arr => arr.map(({ tag }) => tag))),
lastKeycloakVersionWithAccountV1,
"11.0.3" "11.0.3"
]; ];