From 92b505dd56a4e62c922b9258a4a33d642aeb732c Mon Sep 17 00:00:00 2001 From: Joseph Garrone Date: Fri, 13 Dec 2024 12:07:21 +0100 Subject: [PATCH] Load custom extention for logging realm change --- scripts/build/downloadKeycloakifyLogging.ts | 39 +++++++++++++++++++++ scripts/build/main.ts | 10 ++++-- src/bin/shared/constants.ts | 4 +++ src/bin/start-keycloak/start-keycloak.ts | 24 ++++++++----- 4 files changed, 65 insertions(+), 12 deletions(-) create mode 100644 scripts/build/downloadKeycloakifyLogging.ts diff --git a/scripts/build/downloadKeycloakifyLogging.ts b/scripts/build/downloadKeycloakifyLogging.ts new file mode 100644 index 00000000..bfd77b84 --- /dev/null +++ b/scripts/build/downloadKeycloakifyLogging.ts @@ -0,0 +1,39 @@ +import { downloadAndExtractArchive } from "../../src/bin/tools/downloadAndExtractArchive"; +import { cacheDirPath } from "../shared/cacheDirPath"; +import { getProxyFetchOptions } from "../../src/bin/tools/fetchProxyOptions"; +import { getThisCodebaseRootDirPath } from "../../src/bin/tools/getThisCodebaseRootDirPath"; +import { existsAsync } from "../../src/bin/tools/fs.existsAsync"; +import * as fs from "fs/promises"; +import { + KEYCLOAKIFY_LOGGING_VERSION, + KEYCLOAKIFY_LOGIN_JAR_BASENAME +} from "../../src/bin/shared/constants"; +import { join as pathJoin } from "path"; + +export async function downloadKeycloakifyLogging(params: { distDirPath: string }) { + const { distDirPath } = params; + + const jarFilePath = pathJoin( + distDirPath, + "src", + "bin", + "start-keycloak", + KEYCLOAKIFY_LOGIN_JAR_BASENAME + ); + + if (await existsAsync(jarFilePath)) { + return; + } + + const { archiveFilePath } = await downloadAndExtractArchive({ + cacheDirPath, + fetchOptions: getProxyFetchOptions({ + npmConfigGetCwd: getThisCodebaseRootDirPath() + }), + url: `https://github.com/keycloakify/keycloakify-logging/releases/download/${KEYCLOAKIFY_LOGGING_VERSION}/keycloakify-logging-${KEYCLOAKIFY_LOGGING_VERSION}.jar`, + uniqueIdOfOnArchiveFile: "no extraction", + onArchiveFile: async () => {} + }); + + await fs.cp(archiveFilePath, jarFilePath); +} diff --git a/scripts/build/main.ts b/scripts/build/main.ts index 2fdcdbc6..937c06db 100644 --- a/scripts/build/main.ts +++ b/scripts/build/main.ts @@ -7,6 +7,7 @@ import { createAccountV1Dir } from "./createAccountV1Dir"; import chalk from "chalk"; import { run } from "../shared/run"; import { vendorFrontendDependencies } from "./vendorFrontendDependencies"; +import { downloadKeycloakifyLogging } from "./downloadKeycloakifyLogging"; (async () => { console.log(chalk.cyan("Building Keycloakify...")); @@ -148,9 +149,6 @@ import { vendorFrontendDependencies } from "./vendorFrontendDependencies"; fs.cpSync(dirBasename, destDirPath, { recursive: true }); } - await createPublicKeycloakifyDevResourcesDir(); - await createAccountV1Dir(); - transformCodebase({ srcDirPath: join("stories"), destDirPath: join("dist", "stories"), @@ -163,6 +161,12 @@ import { vendorFrontendDependencies } from "./vendorFrontendDependencies"; } }); + await createPublicKeycloakifyDevResourcesDir(); + await createAccountV1Dir(); + await downloadKeycloakifyLogging({ + distDirPath: join(process.cwd(), "dist") + }); + console.log( chalk.green(`✓ built in ${((Date.now() - startTime) / 1000).toFixed(2)}s`) ); diff --git a/src/bin/shared/constants.ts b/src/bin/shared/constants.ts index 56433dd4..0084e9d3 100644 --- a/src/bin/shared/constants.ts +++ b/src/bin/shared/constants.ts @@ -81,3 +81,7 @@ export const CUSTOM_HANDLER_ENV_NAMES = { export const KEYCLOAK_THEME = "keycloak-theme"; export const KEYCLOAKIFY_SPA_DEV_SERVER_PORT = "KEYCLOAKIFY_SPA_DEV_SERVER_PORT"; + +export const KEYCLOAKIFY_LOGGING_VERSION = "1.0.1"; + +export const KEYCLOAKIFY_LOGIN_JAR_BASENAME = `keycloakify-login-${KEYCLOAKIFY_LOGGING_VERSION}.jar`; diff --git a/src/bin/start-keycloak/start-keycloak.ts b/src/bin/start-keycloak/start-keycloak.ts index 42326c93..a70ba002 100644 --- a/src/bin/start-keycloak/start-keycloak.ts +++ b/src/bin/start-keycloak/start-keycloak.ts @@ -1,7 +1,11 @@ import type { BuildContext } from "../shared/buildContext"; import { exclude } from "tsafe/exclude"; import { promptKeycloakVersion } from "../shared/promptKeycloakVersion"; -import { CONTAINER_NAME, KEYCLOAKIFY_SPA_DEV_SERVER_PORT } from "../shared/constants"; +import { + CONTAINER_NAME, + KEYCLOAKIFY_SPA_DEV_SERVER_PORT, + KEYCLOAKIFY_LOGIN_JAR_BASENAME +} from "../shared/constants"; import { SemVer } from "../tools/SemVer"; import { assert, type Equals } from "tsafe/assert"; import * as fs from "fs"; @@ -214,16 +218,18 @@ export async function command(params: { }) ); + const thisDirPath = pathJoin( + getThisCodebaseRootDirPath(), + "src", + "bin", + "start-keycloak" + ); + + extensionJarFilePaths.unshift(pathJoin(thisDirPath, KEYCLOAKIFY_LOGIN_JAR_BASENAME)); + const getRealmJsonFilePath_defaultForKeycloakMajor = ( keycloakMajorVersionNumber: number - ) => - pathJoin( - getThisCodebaseRootDirPath(), - "src", - "bin", - "start-keycloak", - `myrealm-realm-${keycloakMajorVersionNumber}.json` - ); + ) => pathJoin(thisDirPath, `myrealm-realm-${keycloakMajorVersionNumber}.json`); const realmJsonFilePath = await (async () => { if (cliCommandOptions.realmJsonFilePath !== undefined) {