Skip to content

Commit

Permalink
Compat with Keycloak 16 (and probably 17, 18) #79
Browse files Browse the repository at this point in the history
  • Loading branch information
garronej committed Jan 20, 2022
1 parent 4023737 commit fb0be32
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
14 changes: 8 additions & 6 deletions src/bin/build-keycloak-theme/generateKeycloakThemeResources.ts
@@ -1,6 +1,6 @@
import { transformCodebase } from "../tools/transformCodebase";
import * as fs from "fs";
import { join as pathJoin } from "path";
import { join as pathJoin, basename as pathBasename } from "path";
import { replaceImportsInCssCode, replaceImportsFromStaticInJsCode } from "./replaceImportFromStatic";
import { generateFtlFilesCodeFactory, pageIds } from "./generateFtl";
import { downloadBuiltinKeycloakTheme } from "../download-builtin-keycloak-theme";
Expand Down Expand Up @@ -112,20 +112,22 @@ export function generateKeycloakThemeResources(params: {
const reactAppPublicDirPath = pathJoin(reactAppBuildDirPath, "..", "public");

transformCodebase({
"srcDirPath": themeResourcesDirPath,
"destDirPath": pathJoin(reactAppPublicDirPath, resourcesPath),
"srcDirPath": pathJoin(tmpDirPath, "keycloak", "common", "resources"),
"destDirPath": pathJoin(themeResourcesDirPath, pathBasename(resourcesCommonPath)),
});

transformCodebase({
"srcDirPath": pathJoin(tmpDirPath, "keycloak", "common", "resources"),
"destDirPath": pathJoin(reactAppPublicDirPath, resourcesCommonPath),
"srcDirPath": themeResourcesDirPath,
"destDirPath": pathJoin(reactAppPublicDirPath, resourcesPath),
});

const keycloakResourcesWithinPublicDirPath = pathJoin(reactAppPublicDirPath, subDirOfPublicDirBasename);

fs.writeFileSync(
pathJoin(keycloakResourcesWithinPublicDirPath, "README.txt"),
Buffer.from(["This is just a test folder that helps develop", "the login and register page without having to yarn build"].join(" ")),
Buffer.from(
["This is just a test folder that helps develop", "the login and register page without having to run a Keycloak container"].join(" "),
),
);

fs.writeFileSync(pathJoin(keycloakResourcesWithinPublicDirPath, ".gitignore"), Buffer.from("*", "utf8"));
Expand Down
13 changes: 12 additions & 1 deletion src/lib/getKcContext/getKcContext.ts
Expand Up @@ -7,6 +7,9 @@ import { exclude } from "tsafe/exclude";
import { assert } from "tsafe/assert";
import type { ExtendsKcContextBase } from "./getKcContextFromWindow";
import { getKcContextFromWindow } from "./getKcContextFromWindow";
import { pathJoin } from "../tools/pathJoin";
import { pathBasename } from "../tools/pathBasename";
import { resourcesCommonPath } from "./kcContextMocks/urlResourcesPath";

export function getKcContext<KcContextExtended extends { pageId: string } = never>(params?: {
mockPageId?: ExtendsKcContextBase<KcContextExtended>["pageId"];
Expand Down Expand Up @@ -93,5 +96,13 @@ export function getKcContext<KcContextExtended extends { pageId: string } = neve
return { kcContext };
}

return { "kcContext": getKcContextFromWindow<KcContextExtended>() };
const kcContext = getKcContextFromWindow<KcContextExtended>();

if (kcContext !== undefined) {
const { url } = kcContext;

url.resourcesCommonPath = pathJoin(url.resourcesPath, pathBasename(resourcesCommonPath));
}

return { kcContext };
}
2 changes: 1 addition & 1 deletion src/lib/getKcContext/kcContextMocks/urlResourcesPath.ts
Expand Up @@ -2,4 +2,4 @@ import { pathJoin } from "../../tools/pathJoin";

export const subDirOfPublicDirBasename = "keycloak_static";
export const resourcesPath = pathJoin(subDirOfPublicDirBasename, "resources");
export const resourcesCommonPath = pathJoin(subDirOfPublicDirBasename, "resources_common");
export const resourcesCommonPath = pathJoin(resourcesPath, "resources_common");
3 changes: 3 additions & 0 deletions src/lib/tools/pathBasename.ts
@@ -0,0 +1,3 @@
export function pathBasename(path: string) {
return path.split("/").reverse()[0];
}

0 comments on commit fb0be32

Please sign in to comment.