Compare commits

...

9 Commits

4 changed files with 66 additions and 69 deletions

View File

@ -1,6 +1,6 @@
{
"name": "keycloakify",
"version": "11.8.1",
"version": "11.8.5",
"description": "Framework to create custom Keycloak UIs",
"repository": {
"type": "git",

View File

@ -6,8 +6,7 @@ import {
join as pathJoin,
relative as pathRelative,
dirname as pathDirname,
extname as pathExtname,
sep as pathSep
basename as pathBasename
} from "path";
import { replaceImportsInJsCode } from "../replacers/replaceImportsInJsCode";
import { replaceImportsInCssCode } from "../replacers/replaceImportsInCssCode";
@ -37,6 +36,7 @@ import propertiesParser from "properties-parser";
import { createObjectThatThrowsIfAccessed } from "../../tools/createObjectThatThrowsIfAccessed";
import { listInstalledModules } from "../../tools/listInstalledModules";
import { isInside } from "../../tools/isInside";
import { id } from "tsafe/id";
export type BuildContextLike = BuildContextLike_kcContextExclusionsFtlCode &
BuildContextLike_generateMessageProperties & {
@ -57,6 +57,8 @@ export async function generateResources(params: {
buildContext: BuildContextLike;
resourcesDirPath: string;
}): Promise<void> {
const start = Date.now();
const { resourcesDirPath, buildContext } = params;
const [themeName] = buildContext.themeNames;
@ -661,7 +663,7 @@ export async function generateResources(params: {
}
}
for (const themeVariantName of buildContext.themeNames) {
for (const themeVariantName of [...buildContext.themeNames].reverse()) {
for (const themeType of [...THEME_TYPES, "email"] as const) {
copy_main_theme_to_theme_variant_theme: {
let isNative: boolean;
@ -676,39 +678,59 @@ export async function generateResources(params: {
isNative = !v.isImplemented && v.isImplemented_native;
}
if (themeVariantName === themeName) {
if (!isNative && themeVariantName === themeName) {
break copy_main_theme_to_theme_variant_theme;
}
transformCodebase({
srcDirPath: pathJoin(resourcesDirPath, "theme", themeName),
destDirPath: pathJoin(resourcesDirPath, "theme", themeVariantName),
transformSourceCode: isNative
? undefined
: ({ fileRelativePath, sourceCode }) => {
if (
pathExtname(fileRelativePath) === ".ftl" &&
fileRelativePath.split(pathSep).length === 2
) {
const modifiedSourceCode = Buffer.from(
Buffer.from(sourceCode)
.toString("utf-8")
.replace(
`"themeName": "${themeName}"`,
`"themeName": "${themeVariantName}"`
),
"utf8"
);
srcDirPath: getThemeTypeDirPath({ themeName, themeType }),
destDirPath: getThemeTypeDirPath({
themeName: themeVariantName,
themeType
}),
transformSourceCode: ({ fileRelativePath, sourceCode }) => {
patch_xKeycloakify_themeName: {
if (!fileRelativePath.endsWith(".ftl")) {
break patch_xKeycloakify_themeName;
}
assert(
Buffer.compare(modifiedSourceCode, sourceCode) !== 0
);
if (
!isNative &&
pathBasename(fileRelativePath) !== fileRelativePath
) {
break patch_xKeycloakify_themeName;
}
return { modifiedSourceCode };
}
const modifiedSourceCode = Buffer.from(
Buffer.from(sourceCode)
.toString("utf-8")
.replace(
...id<[string | RegExp, string]>(
isNative
? [
/xKeycloakify\.themeName/g,
`"${themeVariantName}"`
]
: [
`"themeName": "${themeName}"`,
`"themeName": "${themeVariantName}"`
]
)
),
"utf8"
);
return { modifiedSourceCode: sourceCode };
}
if (!isNative) {
assert(
Buffer.compare(modifiedSourceCode, sourceCode) !== 0
);
}
return { modifiedSourceCode };
}
return { modifiedSourceCode: sourceCode };
}
});
}
run_writeMessagePropertiesFiles: {
@ -727,42 +749,8 @@ export async function generateResources(params: {
themeName: themeVariantName
});
}
replace_xKeycloakify_themeName_in_native_ftl_files: {
{
const v = buildContext.implementedThemeTypes[themeType];
if (v.isImplemented || !v.isImplemented_native) {
break replace_xKeycloakify_themeName_in_native_ftl_files;
}
}
const emailThemeDirPath = getThemeTypeDirPath({
themeName,
themeType
});
transformCodebase({
srcDirPath: emailThemeDirPath,
destDirPath: emailThemeDirPath,
transformSourceCode: ({ filePath, sourceCode }) => {
if (!filePath.endsWith(".ftl")) {
return { modifiedSourceCode: sourceCode };
}
return {
modifiedSourceCode: Buffer.from(
sourceCode
.toString("utf8")
.replace(
/xKeycloakify\.themeName/g,
`"${themeName}"`
),
"utf8"
)
};
}
});
}
}
}
console.log(`Generated resources in ${Date.now() - start}ms`);
}

View File

@ -101,7 +101,6 @@ function addOrEditTestUser(params: {
);
newUser.username = defaultUser_default.username;
newUser.email = defaultUser_default.email;
delete_existing_password_credential_if_any: {
const i = newUser.credentials.findIndex(

View File

@ -100,9 +100,19 @@ function addCommentToSourceCode(params: {
}
if (fileRelativePath.endsWith(".ftl")) {
return toResult(
[`<#--`, ...commentLines.map(line => ` ${line}`), `-->`].join("\n")
const comment = [`<#--`, ...commentLines.map(line => ` ${line}`), `-->`].join(
"\n"
);
if (sourceCode.trim().startsWith("<#ftl")) {
const [first, ...rest] = sourceCode.split(">");
const last = rest.join(">");
return [`${first}>`, comment, last].join("\n");
}
return toResult(comment);
}
if (fileRelativePath.endsWith(".html") || fileRelativePath.endsWith(".svg")) {