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