Remove extraThemeNames option in favor of extending themeName to accept array
This commit is contained in:
parent
37dbd49589
commit
cd8548fc32
@ -8,8 +8,7 @@ import { getAbsoluteAndInOsFormatPath } from "../tools/getAbsoluteAndInOsFormatP
|
||||
export type BuildOptions = {
|
||||
isSilent: boolean;
|
||||
themeVersion: string;
|
||||
themeName: string;
|
||||
themeVariantNames: string[];
|
||||
themeNames: string[];
|
||||
extraThemeProperties: string[] | undefined;
|
||||
groupId: string;
|
||||
artifactId: string;
|
||||
@ -42,30 +41,32 @@ export function readBuildOptions(params: { reactAppRootDirPath: string; processA
|
||||
|
||||
const { name, keycloakify = {}, version, homepage } = parsedPackageJson;
|
||||
|
||||
const {
|
||||
extraThemeProperties,
|
||||
groupId,
|
||||
artifactId,
|
||||
doCreateJar,
|
||||
loginThemeResourcesFromKeycloakVersion,
|
||||
themeVariantNames = []
|
||||
} = keycloakify ?? {};
|
||||
const { extraThemeProperties, groupId, artifactId, doCreateJar, loginThemeResourcesFromKeycloakVersion } = keycloakify ?? {};
|
||||
|
||||
const themeName =
|
||||
keycloakify.themeName ??
|
||||
const themeNames = (() => {
|
||||
if (keycloakify.themeName === undefined) {
|
||||
return [
|
||||
name
|
||||
.replace(/^@(.*)/, "$1")
|
||||
.split("/")
|
||||
.join("-");
|
||||
.join("-")
|
||||
];
|
||||
}
|
||||
|
||||
if (typeof keycloakify.themeName === "string") {
|
||||
return [keycloakify.themeName];
|
||||
}
|
||||
|
||||
return keycloakify.themeName;
|
||||
})();
|
||||
|
||||
return {
|
||||
reactAppRootDirPath,
|
||||
themeName,
|
||||
themeVariantNames,
|
||||
themeNames,
|
||||
"doCreateJar": doCreateJar ?? true,
|
||||
"artifactId": process.env.KEYCLOAKIFY_ARTIFACT_ID ?? artifactId ?? `${themeName}-keycloak-theme`,
|
||||
"artifactId": process.env.KEYCLOAKIFY_ARTIFACT_ID ?? artifactId ?? `${themeNames[0]}-keycloak-theme`,
|
||||
"groupId": (() => {
|
||||
const fallbackGroupId = `${themeName}.keycloak`;
|
||||
const fallbackGroupId = `${themeNames[0]}.keycloak`;
|
||||
|
||||
return (
|
||||
process.env.KEYCLOAKIFY_GROUP_ID ??
|
||||
|
@ -11,7 +11,6 @@ import { assert } from "tsafe/assert";
|
||||
import type { ThemeType } from "../../constants";
|
||||
|
||||
export type BuildOptionsLike = {
|
||||
themeName: string;
|
||||
themeVersion: string;
|
||||
urlPathname: string | undefined;
|
||||
};
|
||||
@ -19,6 +18,7 @@ export type BuildOptionsLike = {
|
||||
assert<BuildOptions extends BuildOptionsLike ? true : false>();
|
||||
|
||||
export function generateFtlFilesCodeFactory(params: {
|
||||
themeName: string;
|
||||
indexHtmlCode: string;
|
||||
//NOTE: Expected to be an empty object if external assets mode is enabled.
|
||||
cssGlobalsToDefine: Record<string, string>;
|
||||
@ -27,7 +27,7 @@ export function generateFtlFilesCodeFactory(params: {
|
||||
themeType: ThemeType;
|
||||
fieldNames: string[];
|
||||
}) {
|
||||
const { cssGlobalsToDefine, indexHtmlCode, buildOptions, keycloakifyVersion, themeType, fieldNames } = params;
|
||||
const { themeName, cssGlobalsToDefine, indexHtmlCode, buildOptions, keycloakifyVersion, themeType, fieldNames } = params;
|
||||
|
||||
const $ = cheerio.load(indexHtmlCode);
|
||||
|
||||
@ -101,7 +101,7 @@ export function generateFtlFilesCodeFactory(params: {
|
||||
.replace("KEYCLOAKIFY_VERSION_xEdKd3xEdr", keycloakifyVersion)
|
||||
.replace("KEYCLOAKIFY_THEME_VERSION_sIgKd3xEdr3dx", buildOptions.themeVersion)
|
||||
.replace("KEYCLOAKIFY_THEME_TYPE_dExKd3xEdr", themeType)
|
||||
.replace("KEYCLOAKIFY_THEME_NAME_cXxKd3xEer", buildOptions.themeName),
|
||||
.replace("KEYCLOAKIFY_THEME_NAME_cXxKd3xEer", themeName),
|
||||
"<!-- xIdLqMeOedErIdLsPdNdI9dSlxI -->": [
|
||||
"<#if scripts??>",
|
||||
" <#list scripts as script>",
|
||||
|
@ -7,13 +7,12 @@ import { type ThemeType } from "../../constants";
|
||||
import { bringInAccountV1, accountV1 } from "./bringInAccountV1";
|
||||
|
||||
export type BuildOptionsLike = {
|
||||
themeName: string;
|
||||
themeVariantNames: string[];
|
||||
groupId: string;
|
||||
artifactId: string;
|
||||
themeVersion: string;
|
||||
cacheDirPath: string;
|
||||
keycloakifyBuildDirPath: string;
|
||||
themeNames: string[];
|
||||
};
|
||||
|
||||
{
|
||||
@ -178,7 +177,7 @@ export async function generateJavaStackFiles(params: {
|
||||
"types": ["account"]
|
||||
}
|
||||
]),
|
||||
...[buildOptions.themeName, ...buildOptions.themeVariantNames]
|
||||
...buildOptions.themeNames
|
||||
.map(themeName => [
|
||||
{
|
||||
"name": themeName,
|
||||
|
@ -15,7 +15,6 @@ import { generateMessageProperties } from "./generateMessageProperties";
|
||||
import { readStaticResourcesUsage } from "./readStaticResourcesUsage";
|
||||
|
||||
export type BuildOptionsLike = {
|
||||
themeName: string;
|
||||
extraThemeProperties: string[] | undefined;
|
||||
themeVersion: string;
|
||||
loginThemeResourcesFromKeycloakVersion: string;
|
||||
@ -28,15 +27,16 @@ export type BuildOptionsLike = {
|
||||
assert<BuildOptions extends BuildOptionsLike ? true : false>();
|
||||
|
||||
export async function generateTheme(params: {
|
||||
themeName: string;
|
||||
themeSrcDirPath: string;
|
||||
keycloakifySrcDirPath: string;
|
||||
buildOptions: BuildOptionsLike;
|
||||
keycloakifyVersion: string;
|
||||
}): Promise<void> {
|
||||
const { themeSrcDirPath, keycloakifySrcDirPath, buildOptions, keycloakifyVersion } = params;
|
||||
const { themeName, themeSrcDirPath, keycloakifySrcDirPath, buildOptions, keycloakifyVersion } = params;
|
||||
|
||||
const getThemeDirPath = (themeType: ThemeType | "email") =>
|
||||
pathJoin(buildOptions.keycloakifyBuildDirPath, "src", "main", "resources", "theme", buildOptions.themeName, themeType);
|
||||
pathJoin(buildOptions.keycloakifyBuildDirPath, "src", "main", "resources", "theme", themeName, themeType);
|
||||
|
||||
let allCssGlobalsToDefine: Record<string, string> = {};
|
||||
|
||||
@ -106,6 +106,7 @@ export async function generateTheme(params: {
|
||||
generateFtlFilesCode_glob !== undefined
|
||||
? generateFtlFilesCode_glob
|
||||
: generateFtlFilesCodeFactory({
|
||||
themeName,
|
||||
"indexHtmlCode": fs.readFileSync(pathJoin(buildOptions.reactAppBuildDirPath, "index.html")).toString("utf8"),
|
||||
"cssGlobalsToDefine": allCssGlobalsToDefine,
|
||||
buildOptions,
|
||||
|
@ -26,14 +26,12 @@ export async function main() {
|
||||
|
||||
const { themeSrcDirPath } = getThemeSrcDirPath({ reactAppRootDirPath });
|
||||
|
||||
for (const themeName of [buildOptions.themeName, ...buildOptions.themeVariantNames]) {
|
||||
for (const themeName of buildOptions.themeNames) {
|
||||
await generateTheme({
|
||||
themeName,
|
||||
themeSrcDirPath,
|
||||
"keycloakifySrcDirPath": pathJoin(keycloakifyDirPath, "src"),
|
||||
"buildOptions": {
|
||||
...buildOptions,
|
||||
"themeName": themeName
|
||||
},
|
||||
buildOptions,
|
||||
"keycloakifyVersion": (() => {
|
||||
const version = JSON.parse(fs.readFileSync(pathJoin(keycloakifyDirPath, "package.json")).toString("utf8"))["version"];
|
||||
|
||||
@ -124,15 +122,15 @@ export async function main() {
|
||||
"- Log into the admin console 👉 http://localhost:8080/admin username: admin, password: admin 👈",
|
||||
`- Create a realm: Master -> AddRealm -> Name: myrealm`,
|
||||
`- Enable registration: Realm settings -> Login tab -> User registration: on`,
|
||||
`- Enable the Account theme (optional): Realm settings -> Themes tab -> Account theme: ${buildOptions.themeName}`,
|
||||
` Clients -> account -> Login theme: ${buildOptions.themeName}`,
|
||||
`- Enable the email theme (optional): Realm settings -> Themes tab -> Email theme: ${buildOptions.themeName} (option will appear only if you have ran npx initialize-email-theme)`,
|
||||
`- Enable the Account theme (optional): Realm settings -> Themes tab -> Account theme: ${buildOptions.themeNames[0]}`,
|
||||
` Clients -> account -> Login theme: ${buildOptions.themeNames[0]}`,
|
||||
`- Enable the email theme (optional): Realm settings -> Themes tab -> Email theme: ${buildOptions.themeNames[0]} (option will appear only if you have ran npx initialize-email-theme)`,
|
||||
`- Create a client Clients -> Create -> Client ID: myclient`,
|
||||
` Root URL: https://www.keycloak.org/app/`,
|
||||
` Valid redirect URIs: https://www.keycloak.org/app* http://localhost* (localhost is optional)`,
|
||||
` Valid post logout redirect URIs: https://www.keycloak.org/app* http://localhost*`,
|
||||
` Web origins: *`,
|
||||
` Login Theme: ${buildOptions.themeName}`,
|
||||
` Login Theme: ${buildOptions.themeNames[0]}`,
|
||||
` Save (button at the bottom of the page)`,
|
||||
``,
|
||||
`- Go to 👉 https://www.keycloak.org/app/ 👈 Click "Save" then "Sign in". You should see your login page`,
|
||||
|
@ -17,8 +17,7 @@ export type ParsedPackageJson = {
|
||||
loginThemeResourcesFromKeycloakVersion?: string;
|
||||
reactAppBuildDirPath?: string;
|
||||
keycloakifyBuildDirPath?: string;
|
||||
themeName?: string;
|
||||
themeVariantNames?: string[];
|
||||
themeName?: string | string[];
|
||||
};
|
||||
};
|
||||
|
||||
@ -36,8 +35,7 @@ export const zParsedPackageJson = z.object({
|
||||
"loginThemeResourcesFromKeycloakVersion": z.string().optional(),
|
||||
"reactAppBuildDirPath": z.string().optional(),
|
||||
"keycloakifyBuildDirPath": z.string().optional(),
|
||||
"themeName": z.string().optional(),
|
||||
"themeVariantNames": z.array(z.string()).optional()
|
||||
"themeName": z.union([z.string(), z.array(z.string())]).optional()
|
||||
})
|
||||
.optional()
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user