From ef4f4d837496f7bf681f6e7e14e6241a9f1383eb Mon Sep 17 00:00:00 2001 From: Michael Kreuzer <kreuzer@bii-gmbh.com> Date: Wed, 11 Sep 2024 11:07:06 +0200 Subject: [PATCH 1/8] allow docker start script to work with podman --- src/bin/start-keycloak/start-keycloak.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/bin/start-keycloak/start-keycloak.ts b/src/bin/start-keycloak/start-keycloak.ts index 736ce0f5..c85b09dc 100644 --- a/src/bin/start-keycloak/start-keycloak.ts +++ b/src/bin/start-keycloak/start-keycloak.ts @@ -37,15 +37,17 @@ export type CliCommandOptions = CliCommandOptions_common & { export async function command(params: { cliCommandOptions: CliCommandOptions }) { exit_if_docker_not_installed: { - let commandOutput: Buffer | undefined = undefined; + let commandOutput: string | undefined = undefined; try { - commandOutput = child_process.execSync("docker --version", { - stdio: ["ignore", "pipe", "ignore"] - }); + commandOutput = child_process + .execSync("docker --version", { + stdio: ["ignore", "pipe", "ignore"] + }) + ?.toString("utf8"); } catch {} - if (commandOutput?.toString("utf8").includes("Docker")) { + if (commandOutput?.includes("Docker") || commandOutput?.includes("podman")) { break exit_if_docker_not_installed; } From 07e4f99f8010578197cdda04ede998ef4f990be8 Mon Sep 17 00:00:00 2001 From: Joseph Garrone <joseph.garrone.gj@gmail.com> Date: Fri, 13 Sep 2024 12:47:01 +0200 Subject: [PATCH 2/8] Bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a75533e3..4f5d3238 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "keycloakify", - "version": "10.1.0", + "version": "10.1.1", "description": "Create Keycloak themes using React", "repository": { "type": "git", From b4e94d3c00aed3a561d083b895a4b2c1302ea02e Mon Sep 17 00:00:00 2001 From: Joseph Garrone <joseph.garrone.gj@gmail.com> Date: Mon, 16 Sep 2024 13:36:50 +0200 Subject: [PATCH 3/8] Use keycloakify-dev-resources instead of .keycloakify --- scripts/build-storybook.ts | 51 ------------------- ...createPublicKeycloakifyDevResourcesDir.ts} | 4 +- scripts/build/main.ts | 4 +- src/account/KcContext/kcContextMocks.ts | 2 +- .../generateResourcesForMainTheme.ts | 6 +-- src/bin/shared/constants.ts | 2 +- .../shared/copyKeycloakResourcesToPublic.ts | 4 +- src/login/KcContext/kcContextMocks.ts | 2 +- src/vite-plugin/vite-plugin.ts | 5 +- 9 files changed, 16 insertions(+), 64 deletions(-) rename scripts/build/{createPublicDotKeycloakifyDir.ts => createPublicKeycloakifyDevResourcesDir.ts} (94%) diff --git a/scripts/build-storybook.ts b/scripts/build-storybook.ts index eeccbb9e..51aac8ca 100644 --- a/scripts/build-storybook.ts +++ b/scripts/build-storybook.ts @@ -1,59 +1,8 @@ import * as child_process from "child_process"; -import { transformCodebase } from "../src/bin/tools/transformCodebase"; -import { join as pathJoin, sep as pathSep } from "path"; -import { assert } from "tsafe/assert"; run("yarn build"); run("npx build-storybook"); -const storybookStaticDirPath = "storybook-static"; - -{ - let hasPatched = false; - - transformCodebase({ - srcDirPath: storybookStaticDirPath, - destDirPath: storybookStaticDirPath, - transformSourceCode: ({ fileRelativePath, sourceCode }) => { - replace_dot_keycloakify: { - if (fileRelativePath.includes(pathSep)) { - break replace_dot_keycloakify; - } - - if (!fileRelativePath.endsWith(".js")) { - break replace_dot_keycloakify; - } - - const search = `DOT_KEYCLOAKIFY:".keycloakify"`; - - if (!sourceCode.includes(search)) { - break replace_dot_keycloakify; - } - - hasPatched = true; - - return { - modifiedSourceCode: Buffer.from( - sourceCode - .toString("utf8") - .replace(search, `DOT_KEYCLOAKIFY:"dot_keycloakify"`), - "utf8" - ) - }; - } - - return { modifiedSourceCode: sourceCode }; - } - }); - - assert(hasPatched); -} - -transformCodebase({ - srcDirPath: pathJoin(storybookStaticDirPath, ".keycloakify"), - destDirPath: pathJoin(storybookStaticDirPath, "dot_keycloakify") -}); - function run(command: string, options?: { env?: NodeJS.ProcessEnv }) { console.log(`$ ${command}`); diff --git a/scripts/build/createPublicDotKeycloakifyDir.ts b/scripts/build/createPublicKeycloakifyDevResourcesDir.ts similarity index 94% rename from scripts/build/createPublicDotKeycloakifyDir.ts rename to scripts/build/createPublicKeycloakifyDevResourcesDir.ts index 667124ea..29673261 100644 --- a/scripts/build/createPublicDotKeycloakifyDir.ts +++ b/scripts/build/createPublicKeycloakifyDevResourcesDir.ts @@ -7,7 +7,7 @@ import { WELL_KNOWN_DIRECTORY_BASE_NAME } from "../../src/bin/shared/constants"; import { assert, type Equals } from "tsafe/assert"; import * as fsPr from "fs/promises"; -export async function createPublicDotKeycloakifyDir() { +export async function createPublicKeycloakifyDevResourcesDir() { await Promise.all( (["login", "account"] as const).map(async themeType => { const { extractedDirPath } = await downloadKeycloakDefaultTheme({ @@ -27,7 +27,7 @@ export async function createPublicDotKeycloakifyDir() { "dist", "res", "public", - WELL_KNOWN_DIRECTORY_BASE_NAME.DOT_KEYCLOAKIFY, + WELL_KNOWN_DIRECTORY_BASE_NAME.KEYCLOAKIFY_DEV_RESOURCES, themeType ); diff --git a/scripts/build/main.ts b/scripts/build/main.ts index 40896817..b07a054f 100644 --- a/scripts/build/main.ts +++ b/scripts/build/main.ts @@ -3,7 +3,7 @@ import * as fs from "fs"; import { join } from "path"; import { assert } from "tsafe/assert"; import { transformCodebase } from "../../src/bin/tools/transformCodebase"; -import { createPublicDotKeycloakifyDir } from "./createPublicDotKeycloakifyDir"; +import { createPublicKeycloakifyDevResourcesDir } from "./createPublicKeycloakifyDevResourcesDir"; import { createAccountV1Dir } from "./createAccountV1Dir"; import chalk from "chalk"; @@ -144,7 +144,7 @@ import chalk from "chalk"; fs.cpSync(dirBasename, destDirPath, { recursive: true }); } - await createPublicDotKeycloakifyDir(); + await createPublicKeycloakifyDevResourcesDir(); await createAccountV1Dir(); transformCodebase({ diff --git a/src/account/KcContext/kcContextMocks.ts b/src/account/KcContext/kcContextMocks.ts index a80ed058..6569bc4e 100644 --- a/src/account/KcContext/kcContextMocks.ts +++ b/src/account/KcContext/kcContextMocks.ts @@ -4,7 +4,7 @@ import { id } from "tsafe/id"; import type { KcContext } from "./KcContext"; import { BASE_URL } from "keycloakify/lib/BASE_URL"; -const resourcesPath = `${BASE_URL}${WELL_KNOWN_DIRECTORY_BASE_NAME.DOT_KEYCLOAKIFY}/account`; +const resourcesPath = `${BASE_URL}${WELL_KNOWN_DIRECTORY_BASE_NAME.KEYCLOAKIFY_DEV_RESOURCES}/account`; export const kcContextCommonMock: KcContext.Common = { themeVersion: "0.0.0", diff --git a/src/bin/keycloakify/generateResources/generateResourcesForMainTheme.ts b/src/bin/keycloakify/generateResources/generateResourcesForMainTheme.ts index bad77af6..e6ecf77e 100644 --- a/src/bin/keycloakify/generateResources/generateResourcesForMainTheme.ts +++ b/src/bin/keycloakify/generateResources/generateResourcesForMainTheme.ts @@ -99,7 +99,7 @@ export async function generateResourcesForMainTheme(params: { { const dirPath = pathJoin( buildContext.projectBuildDirPath, - WELL_KNOWN_DIRECTORY_BASE_NAME.DOT_KEYCLOAKIFY + WELL_KNOWN_DIRECTORY_BASE_NAME.KEYCLOAKIFY_DEV_RESOURCES ); if (fs.existsSync(dirPath)) { @@ -107,7 +107,7 @@ export async function generateResourcesForMainTheme(params: { throw new Error( [ - `Keycloakify build error: The ${WELL_KNOWN_DIRECTORY_BASE_NAME.DOT_KEYCLOAKIFY} directory shouldn't exist in your build directory.`, + `Keycloakify build error: The ${WELL_KNOWN_DIRECTORY_BASE_NAME.KEYCLOAKIFY_DEV_RESOURCES} directory shouldn't exist in your build directory.`, `(${pathRelative(process.cwd(), dirPath)}).\n`, `Theses assets are only required for local development with Storybook.", "Please remove this directory as an additional step of your command.\n`, @@ -256,7 +256,7 @@ export async function generateResourcesForMainTheme(params: { getThisCodebaseRootDirPath(), "res", "public", - WELL_KNOWN_DIRECTORY_BASE_NAME.DOT_KEYCLOAKIFY, + WELL_KNOWN_DIRECTORY_BASE_NAME.KEYCLOAKIFY_DEV_RESOURCES, themeType ), destDirPath: pathJoin(themeTypeDirPath, "resources") diff --git a/src/bin/shared/constants.ts b/src/bin/shared/constants.ts index adf6e3fc..d0707a90 100644 --- a/src/bin/shared/constants.ts +++ b/src/bin/shared/constants.ts @@ -1,5 +1,5 @@ export const WELL_KNOWN_DIRECTORY_BASE_NAME = { - DOT_KEYCLOAKIFY: ".keycloakify", + KEYCLOAKIFY_DEV_RESOURCES: "keycloakify-dev-resources", RESOURCES_COMMON: "resources-common", DIST: "dist" } as const; diff --git a/src/bin/shared/copyKeycloakResourcesToPublic.ts b/src/bin/shared/copyKeycloakResourcesToPublic.ts index e9a90762..bd73ef9c 100644 --- a/src/bin/shared/copyKeycloakResourcesToPublic.ts +++ b/src/bin/shared/copyKeycloakResourcesToPublic.ts @@ -21,7 +21,7 @@ export function copyKeycloakResourcesToPublic(params: { const destDirPath = pathJoin( buildContext.publicDirPath, - WELL_KNOWN_DIRECTORY_BASE_NAME.DOT_KEYCLOAKIFY + WELL_KNOWN_DIRECTORY_BASE_NAME.KEYCLOAKIFY_DEV_RESOURCES ); const keycloakifyBuildinfoFilePath = pathJoin(destDirPath, "keycloakify.buildinfo"); @@ -67,7 +67,7 @@ export function copyKeycloakResourcesToPublic(params: { getThisCodebaseRootDirPath(), "res", "public", - WELL_KNOWN_DIRECTORY_BASE_NAME.DOT_KEYCLOAKIFY + WELL_KNOWN_DIRECTORY_BASE_NAME.KEYCLOAKIFY_DEV_RESOURCES ), destDirPath }); diff --git a/src/login/KcContext/kcContextMocks.ts b/src/login/KcContext/kcContextMocks.ts index af190a45..6600708c 100644 --- a/src/login/KcContext/kcContextMocks.ts +++ b/src/login/KcContext/kcContextMocks.ts @@ -75,7 +75,7 @@ const attributesByName = Object.fromEntries( ]).map(attribute => [attribute.name, attribute]) ); -const resourcesPath = `${BASE_URL}${WELL_KNOWN_DIRECTORY_BASE_NAME.DOT_KEYCLOAKIFY}/login`; +const resourcesPath = `${BASE_URL}${WELL_KNOWN_DIRECTORY_BASE_NAME.KEYCLOAKIFY_DEV_RESOURCES}/login`; export const kcContextCommonMock: KcContext.Common = { themeVersion: "0.0.0", diff --git a/src/vite-plugin/vite-plugin.ts b/src/vite-plugin/vite-plugin.ts index d773be8b..1ccfaf89 100644 --- a/src/vite-plugin/vite-plugin.ts +++ b/src/vite-plugin/vite-plugin.ts @@ -201,7 +201,10 @@ export function keycloakify(params: keycloakify.Params) { assert(buildDirPath !== undefined); await rm( - pathJoin(buildDirPath, WELL_KNOWN_DIRECTORY_BASE_NAME.DOT_KEYCLOAKIFY), + pathJoin( + buildDirPath, + WELL_KNOWN_DIRECTORY_BASE_NAME.KEYCLOAKIFY_DEV_RESOURCES + ), { recursive: true, force: true From a42ddb959b54a55b43499c409f42d6115aca2f49 Mon Sep 17 00:00:00 2001 From: Joseph Garrone <joseph.garrone.gj@gmail.com> Date: Mon, 16 Sep 2024 13:38:05 +0200 Subject: [PATCH 4/8] Bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4f5d3238..d7a66b2c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "keycloakify", - "version": "10.1.1", + "version": "10.1.2", "description": "Create Keycloak themes using React", "repository": { "type": "git", From 9b22d946003d653a2bb3d2c23fb98c61bcccb07f Mon Sep 17 00:00:00 2001 From: Joseph Garrone <joseph.garrone.gj@gmail.com> Date: Mon, 16 Sep 2024 13:49:54 +0200 Subject: [PATCH 5/8] Remove previous .keycloakify dir --- src/bin/shared/copyKeycloakResourcesToPublic.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/bin/shared/copyKeycloakResourcesToPublic.ts b/src/bin/shared/copyKeycloakResourcesToPublic.ts index bd73ef9c..db78d313 100644 --- a/src/bin/shared/copyKeycloakResourcesToPublic.ts +++ b/src/bin/shared/copyKeycloakResourcesToPublic.ts @@ -57,6 +57,10 @@ export function copyKeycloakResourcesToPublic(params: { force: true, recursive: true }); + rmSync(pathJoin(pathDirname(destDirPath), ".keycloakify"), { + force: true, + recursive: true + }); fs.mkdirSync(destDirPath, { recursive: true }); From a5e3ecb38be832159dc50ade1a1a0a0a9a0b3bdc Mon Sep 17 00:00:00 2001 From: Joseph Garrone <joseph.garrone.gj@gmail.com> Date: Mon, 16 Sep 2024 13:50:08 +0200 Subject: [PATCH 6/8] Bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d7a66b2c..61a299ce 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "keycloakify", - "version": "10.1.2", + "version": "10.1.3", "description": "Create Keycloak themes using React", "repository": { "type": "git", From 9a97d86ff91f371fc13cd7900f92d8d6486d7343 Mon Sep 17 00:00:00 2001 From: Joseph Garrone <joseph.garrone.gj@gmail.com> Date: Mon, 16 Sep 2024 14:30:27 +0200 Subject: [PATCH 7/8] #638 #631 Follow up --- .../generateFtl/kcContextDeclarationTemplate.ftl | 13 +++++++++++++ src/login/Template.useStylesAndScripts.ts | 9 +-------- src/tools/useInsertScriptTags.ts | 2 +- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/bin/keycloakify/generateFtl/kcContextDeclarationTemplate.ftl b/src/bin/keycloakify/generateFtl/kcContextDeclarationTemplate.ftl index 51881ee4..d61b6980 100644 --- a/src/bin/keycloakify/generateFtl/kcContextDeclarationTemplate.ftl +++ b/src/bin/keycloakify/generateFtl/kcContextDeclarationTemplate.ftl @@ -85,6 +85,19 @@ attributes_to_attributesByName: { }); } window.kcContext = kcContext; + +<#if xKeycloakify.themeType == "login" > + const script = document.createElement("script"); + script.type = "importmap"; + script.textContent = JSON.stringify({ + imports: { + "rfc4648": kcContext.url.resourcesCommonPath + "/node_modules/rfc4648/lib/rfc4648.js" + } + }, null, 2); + + document.head.appendChild(script); +</#if> + function decodeHtmlEntities(htmlStr){ var element = decodeHtmlEntities.element; if (!element) { diff --git a/src/login/Template.useStylesAndScripts.ts b/src/login/Template.useStylesAndScripts.ts index 72933100..5cf7b4a0 100644 --- a/src/login/Template.useStylesAndScripts.ts +++ b/src/login/Template.useStylesAndScripts.ts @@ -55,14 +55,7 @@ export function useStylesAndScripts(params: { const { insertScriptTags } = useInsertScriptTags({ componentOrHookName: "Template", scriptTags: [ - { - type: "importmap", - textContent: JSON.stringify({ - imports: { - rfc4648: `${url.resourcesCommonPath}/node_modules/rfc4648/lib/rfc4648.js` - } - }) - }, + // NOTE: The importmap is added in by the FTL script because it's too late to add it here. { type: "module", src: `${url.resourcesPath}/js/menu-button-links.js` diff --git a/src/tools/useInsertScriptTags.ts b/src/tools/useInsertScriptTags.ts index 5cc47752..0865ba55 100644 --- a/src/tools/useInsertScriptTags.ts +++ b/src/tools/useInsertScriptTags.ts @@ -6,7 +6,7 @@ export type ScriptTag = ScriptTag.TextContent | ScriptTag.Src; export namespace ScriptTag { type Common = { - type: "text/javascript" | "module" | "importmap"; + type: "text/javascript" | "module"; }; export type TextContent = Common & { From fb6f450bfeb2d54f3c9807ca93e0fb9ab947aefa Mon Sep 17 00:00:00 2001 From: Joseph Garrone <joseph.garrone.gj@gmail.com> Date: Mon, 16 Sep 2024 14:30:50 +0200 Subject: [PATCH 8/8] Bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 61a299ce..ebf92702 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "keycloakify", - "version": "10.1.3", + "version": "10.1.4", "description": "Create Keycloak themes using React", "repository": { "type": "git",