From f172b944672520406c8a301a28297f12e741e4f1 Mon Sep 17 00:00:00 2001 From: Joseph Garrone Date: Sat, 13 Jul 2024 19:33:59 +0200 Subject: [PATCH] Use uppercase for constants --- scripts/dump-keycloak-realm.ts | 8 ++-- src/PUBLIC_URL.ts | 4 +- src/account/KcContext/kcContextMocks.ts | 6 +-- src/account/i18n/i18n.tsx | 8 ++-- src/bin/add-story.ts | 12 ++--- src/bin/eject-page.ts | 12 ++--- src/bin/keycloakify/buildJars/buildJar.ts | 8 ++-- .../keycloakify/generateFtl/generateFtl.ts | 8 ++-- .../generateResources/bringInAccountV1.ts | 14 +++--- .../generateMessageProperties.ts | 4 +- .../generateResourcesForMainTheme.ts | 30 ++++++------- .../generateResources/readExtraPageNames.ts | 8 ++-- src/bin/keycloakify/keycloakify.ts | 12 ++--- .../replacers/replaceImportsInCssCode.ts | 4 +- .../replacers/replaceImportsInJsCode/vite.ts | 6 +-- .../replaceImportsInJsCode/webpack.ts | 6 +-- src/bin/shared/buildContext.ts | 17 +++---- src/bin/shared/constants.ts | 34 +++++++------- .../shared/copyKeycloakResourcesToPublic.ts | 12 ++--- .../shared/downloadKeycloakDefaultTheme.ts | 4 +- .../shared/downloadKeycloakStaticResources.ts | 4 +- src/bin/start-keycloak/keycloakifyBuild.ts | 4 +- src/bin/start-keycloak/start-keycloak.ts | 10 ++--- src/login/KcContext/kcContextMocks.ts | 8 ++-- src/login/i18n/i18n.tsx | 8 ++-- src/vite-plugin/vite-plugin.ts | 16 +++---- test/bin/replacers.spec.ts | 44 +++++++++---------- 27 files changed, 157 insertions(+), 154 deletions(-) diff --git a/scripts/dump-keycloak-realm.ts b/scripts/dump-keycloak-realm.ts index 32dec48d..93cf1581 100644 --- a/scripts/dump-keycloak-realm.ts +++ b/scripts/dump-keycloak-realm.ts @@ -1,4 +1,4 @@ -import { containerName } from "../src/bin/shared/constants"; +import { CONTAINER_NAME } from "../src/bin/shared/constants"; import child_process from "child_process"; import { SemVer } from "../src/bin/tools/SemVer"; import { join as pathJoin, relative as pathRelative } from "path"; @@ -14,7 +14,7 @@ import { is } from "tsafe/is"; const child = child_process.spawn( "docker", [ - ...["exec", containerName], + ...["exec", CONTAINER_NAME], ...["/opt/keycloak/bin/kc.sh", "export"], ...["--dir", "/tmp"], ...["--realm", "myrealm"], @@ -62,7 +62,7 @@ import { is } from "tsafe/is"; const keycloakMajorVersionNumber = SemVer.parse( child_process - .execSync(`docker inspect --format '{{.Config.Image}}' ${containerName}`) + .execSync(`docker inspect --format '{{.Config.Image}}' ${CONTAINER_NAME}`) .toString("utf8") .trim() .split(":")[1] @@ -80,7 +80,7 @@ import { is } from "tsafe/is"; ) ); - run(`docker cp ${containerName}:/tmp/myrealm-realm.json ${targetFilePath}`); + run(`docker cp ${CONTAINER_NAME}:/tmp/myrealm-realm.json ${targetFilePath}`); console.log(`${chalk.green(`✓ Exported realm to`)} ${chalk.bold(targetFilePath)}`); })(); diff --git a/src/PUBLIC_URL.ts b/src/PUBLIC_URL.ts index 5de5a1c8..6ed04151 100644 --- a/src/PUBLIC_URL.ts +++ b/src/PUBLIC_URL.ts @@ -1,4 +1,4 @@ -import { basenameOfTheKeycloakifyResourcesDir } from "keycloakify/bin/shared/constants"; +import { BASENAME_OF_KEYCLOAKIFY_RESOURCES_DIR } from "keycloakify/bin/shared/constants"; import { assert } from "tsafe/assert"; /** @@ -17,5 +17,5 @@ export const PUBLIC_URL = (() => { return process.env.PUBLIC_URL; } - return `${kcContext.url.resourcesPath}/${basenameOfTheKeycloakifyResourcesDir}`; + return `${kcContext.url.resourcesPath}/${BASENAME_OF_KEYCLOAKIFY_RESOURCES_DIR}`; })(); diff --git a/src/account/KcContext/kcContextMocks.ts b/src/account/KcContext/kcContextMocks.ts index 7564c0cf..3f79faef 100644 --- a/src/account/KcContext/kcContextMocks.ts +++ b/src/account/KcContext/kcContextMocks.ts @@ -1,10 +1,10 @@ import "keycloakify/tools/Object.fromEntries"; -import { resources_common, keycloak_resources } from "keycloakify/bin/shared/constants"; +import { RESOURCES_COMMON, KEYCLOAK_RESOURCES } from "keycloakify/bin/shared/constants"; import { id } from "tsafe/id"; import type { KcContext } from "./KcContext"; import { BASE_URL } from "keycloakify/lib/BASE_URL"; -const resourcesPath = `${BASE_URL}${keycloak_resources}/account/resources`; +const resourcesPath = `${BASE_URL}${KEYCLOAK_RESOURCES}/account/resources`; export const kcContextCommonMock: KcContext.Common = { themeVersion: "0.0.0", @@ -13,7 +13,7 @@ export const kcContextCommonMock: KcContext.Common = { themeName: "my-theme-name", url: { resourcesPath, - resourcesCommonPath: `${resourcesPath}/${resources_common}`, + resourcesCommonPath: `${resourcesPath}/${RESOURCES_COMMON}`, resourceUrl: "#", accountUrl: "#", applicationsUrl: "#", diff --git a/src/account/i18n/i18n.tsx b/src/account/i18n/i18n.tsx index 3411c3f4..628705d7 100644 --- a/src/account/i18n/i18n.tsx +++ b/src/account/i18n/i18n.tsx @@ -3,7 +3,7 @@ import { assert } from "tsafe/assert"; import messages_defaultSet_fallbackLanguage from "./messages_defaultSet/en"; import { fetchMessages_defaultSet } from "./messages_defaultSet"; import type { KcContext } from "../KcContext"; -import { fallbackLanguageTag } from "keycloakify/bin/shared/constants"; +import { FALLBACK_LANGUAGE_TAG } from "keycloakify/bin/shared/constants"; import { id } from "tsafe/id"; export type KcContextLike = { @@ -104,7 +104,7 @@ export function createGetI18n(me } const partialI18n: Pick = { - currentLanguageTag: kcContext.locale?.currentLanguageTag ?? fallbackLanguageTag, + currentLanguageTag: kcContext.locale?.currentLanguageTag ?? FALLBACK_LANGUAGE_TAG, getChangeLocaleUrl: newLanguageTag => { const { locale } = kcContext; @@ -122,7 +122,7 @@ export function createGetI18n(me const { createI18nTranslationFunctions } = createI18nTranslationFunctionsFactory({ messages_themeDefined: messagesByLanguageTag_themeDefined[partialI18n.currentLanguageTag] ?? - messagesByLanguageTag_themeDefined[fallbackLanguageTag] ?? + messagesByLanguageTag_themeDefined[FALLBACK_LANGUAGE_TAG] ?? (() => { const firstLanguageTag = Object.keys(messagesByLanguageTag_themeDefined)[0]; if (firstLanguageTag === undefined) { @@ -133,7 +133,7 @@ export function createGetI18n(me messages_fromKcServer: kcContext["x-keycloakify"].messages }); - const isCurrentLanguageFallbackLanguage = partialI18n.currentLanguageTag === fallbackLanguageTag; + const isCurrentLanguageFallbackLanguage = partialI18n.currentLanguageTag === FALLBACK_LANGUAGE_TAG; const result: Result = { i18n: { diff --git a/src/bin/add-story.ts b/src/bin/add-story.ts index f2a080e9..6a765617 100644 --- a/src/bin/add-story.ts +++ b/src/bin/add-story.ts @@ -1,11 +1,11 @@ import { getThisCodebaseRootDirPath } from "./tools/getThisCodebaseRootDirPath"; import cliSelect from "cli-select"; import { - loginThemePageIds, - accountThemePageIds, + LOGIN_THEME_PAGE_IDS, + ACCOUNT_THEME_PAGE_IDS, type LoginThemePageId, type AccountThemePageId, - themeTypes, + THEME_TYPES, type ThemeType } from "./shared/constants"; import { capitalize } from "tsafe/capitalize"; @@ -27,7 +27,7 @@ export async function command(params: { cliCommandOptions: CliCommandOptions }) console.log(chalk.cyan("Theme type:")); const { value: themeType } = await cliSelect({ - values: [...themeTypes] + values: [...THEME_TYPES] }).catch(() => { process.exit(-1); }); @@ -40,9 +40,9 @@ export async function command(params: { cliCommandOptions: CliCommandOptions }) values: (() => { switch (themeType) { case "login": - return [...loginThemePageIds]; + return [...LOGIN_THEME_PAGE_IDS]; case "account": - return [...accountThemePageIds]; + return [...ACCOUNT_THEME_PAGE_IDS]; } assert>(false); })() diff --git a/src/bin/eject-page.ts b/src/bin/eject-page.ts index 5ab7c962..7a277707 100644 --- a/src/bin/eject-page.ts +++ b/src/bin/eject-page.ts @@ -3,11 +3,11 @@ import { getThisCodebaseRootDirPath } from "./tools/getThisCodebaseRootDirPath"; import cliSelect from "cli-select"; import { - loginThemePageIds, - accountThemePageIds, + LOGIN_THEME_PAGE_IDS, + ACCOUNT_THEME_PAGE_IDS, type LoginThemePageId, type AccountThemePageId, - themeTypes, + THEME_TYPES, type ThemeType } from "./shared/constants"; import { capitalize } from "tsafe/capitalize"; @@ -29,7 +29,7 @@ export async function command(params: { cliCommandOptions: CliCommandOptions }) console.log(chalk.cyan("Theme type:")); const { value: themeType } = await cliSelect({ - values: [...themeTypes] + values: [...THEME_TYPES] }).catch(() => { process.exit(-1); }); @@ -54,10 +54,10 @@ export async function command(params: { cliCommandOptions: CliCommandOptions }) return [ templateValue, userProfileFormFieldsValue, - ...loginThemePageIds + ...LOGIN_THEME_PAGE_IDS ]; case "account": - return [templateValue, ...accountThemePageIds]; + return [templateValue, ...ACCOUNT_THEME_PAGE_IDS]; } assert>(false); })() diff --git a/src/bin/keycloakify/buildJars/buildJar.ts b/src/bin/keycloakify/buildJars/buildJar.ts index 064fef18..e1d58213 100644 --- a/src/bin/keycloakify/buildJars/buildJar.ts +++ b/src/bin/keycloakify/buildJars/buildJar.ts @@ -7,7 +7,7 @@ import { join as pathJoin, dirname as pathDirname } from "path"; import { transformCodebase } from "../../tools/transformCodebase"; import type { BuildContext } from "../../shared/buildContext"; import * as fs from "fs/promises"; -import { accountV1ThemeName } from "../../shared/constants"; +import { ACCOUNT_V1_THEME_NAME } from "../../shared/constants"; import { generatePom, BuildContextLike as BuildContextLike_generatePom @@ -75,7 +75,7 @@ export async function buildJar(params: { if ( isInside({ - dirPath: pathJoin("theme", accountV1ThemeName), + dirPath: pathJoin("theme", ACCOUNT_V1_THEME_NAME), filePath: fileRelativePath }) ) { @@ -91,7 +91,7 @@ export async function buildJar(params: { sourceCode .toString("utf8") .replace( - `parent=${accountV1ThemeName}`, + `parent=${ACCOUNT_V1_THEME_NAME}`, "parent=keycloak" ), "utf8" @@ -126,7 +126,7 @@ export async function buildJar(params: { assert(metaInfKeycloakTheme !== undefined); metaInfKeycloakTheme.themes = metaInfKeycloakTheme.themes.filter( - ({ name }) => name !== accountV1ThemeName + ({ name }) => name !== ACCOUNT_V1_THEME_NAME ); return metaInfKeycloakTheme; diff --git a/src/bin/keycloakify/generateFtl/generateFtl.ts b/src/bin/keycloakify/generateFtl/generateFtl.ts index fb0fe797..e96f1296 100644 --- a/src/bin/keycloakify/generateFtl/generateFtl.ts +++ b/src/bin/keycloakify/generateFtl/generateFtl.ts @@ -13,8 +13,8 @@ import type { BuildContext } from "../../shared/buildContext"; import { assert } from "tsafe/assert"; import { type ThemeType, - basenameOfTheKeycloakifyResourcesDir, - resources_common + BASENAME_OF_KEYCLOAKIFY_RESOURCES_DIR, + RESOURCES_COMMON } from "../../shared/constants"; import { getThisCodebaseRootDirPath } from "../../tools/getThisCodebaseRootDirPath"; @@ -93,7 +93,7 @@ export function generateFtlFilesCodeFactory(params: { new RegExp( `^${(buildContext.urlPathname ?? "/").replace(/\//g, "\\/")}` ), - `\${xKeycloakify.resourcesPath}/${basenameOfTheKeycloakifyResourcesDir}/` + `\${xKeycloakify.resourcesPath}/${BASENAME_OF_KEYCLOAKIFY_RESOURCES_DIR}/` ) ); }) @@ -118,7 +118,7 @@ export function generateFtlFilesCodeFactory(params: { .replace("{{keycloakifyVersion}}", keycloakifyVersion) .replace("{{themeVersion}}", buildContext.themeVersion) .replace("{{fieldNames}}", fieldNames.map(name => `"${name}"`).join(", ")) - .replace("{{RESOURCES_COMMON}}", resources_common) + .replace("{{RESOURCES_COMMON}}", RESOURCES_COMMON) .replace( "{{userDefinedExclusions}}", buildContext.kcContextExclusionsFtlCode ?? "" diff --git a/src/bin/keycloakify/generateResources/bringInAccountV1.ts b/src/bin/keycloakify/generateResources/bringInAccountV1.ts index d32e9a3f..eb34dfc3 100644 --- a/src/bin/keycloakify/generateResources/bringInAccountV1.ts +++ b/src/bin/keycloakify/generateResources/bringInAccountV1.ts @@ -3,9 +3,9 @@ import { join as pathJoin } from "path"; import { assert } from "tsafe/assert"; import type { BuildContext } from "../../shared/buildContext"; import { - resources_common, - lastKeycloakVersionWithAccountV1, - accountV1ThemeName + RESOURCES_COMMON, + LAST_KEYCLOAK_VERSION_WITH_ACCOUNT_V1, + ACCOUNT_V1_THEME_NAME } from "../../shared/constants"; import { downloadKeycloakDefaultTheme, @@ -24,14 +24,14 @@ export async function bringInAccountV1(params: { const { resourcesDirPath, buildContext } = params; const { defaultThemeDirPath } = await downloadKeycloakDefaultTheme({ - keycloakVersion: lastKeycloakVersionWithAccountV1, + keycloakVersion: LAST_KEYCLOAK_VERSION_WITH_ACCOUNT_V1, buildContext }); const accountV1DirPath = pathJoin( resourcesDirPath, "theme", - accountV1ThemeName, + ACCOUNT_V1_THEME_NAME, "account" ); @@ -47,7 +47,7 @@ export async function bringInAccountV1(params: { transformCodebase({ srcDirPath: pathJoin(defaultThemeDirPath, "keycloak", "common", "resources"), - destDirPath: pathJoin(accountV1DirPath, "resources", resources_common) + destDirPath: pathJoin(accountV1DirPath, "resources", RESOURCES_COMMON) }); fs.writeFileSync( @@ -69,7 +69,7 @@ export async function bringInAccountV1(params: { "patternfly-additions.min.css" ].map( fileBasename => - `${resources_common}/node_modules/patternfly/dist/css/${fileBasename}` + `${RESOURCES_COMMON}/node_modules/patternfly/dist/css/${fileBasename}` ) ].join(" "), "", diff --git a/src/bin/keycloakify/generateResources/generateMessageProperties.ts b/src/bin/keycloakify/generateResources/generateMessageProperties.ts index 4f8e2339..4ae374b2 100644 --- a/src/bin/keycloakify/generateResources/generateMessageProperties.ts +++ b/src/bin/keycloakify/generateResources/generateMessageProperties.ts @@ -1,4 +1,4 @@ -import { type ThemeType, fallbackLanguageTag } from "../../shared/constants"; +import { type ThemeType, FALLBACK_LANGUAGE_TAG } from "../../shared/constants"; import { crawl } from "../../tools/crawl"; import { join as pathJoin } from "path"; import { symToStr } from "tsafe/symToStr"; @@ -168,7 +168,7 @@ export function generateMessageProperties(params: { ...(messageBundle === undefined ? {} : messageBundle[languageTag] ?? - messageBundle[fallbackLanguageTag] ?? + messageBundle[FALLBACK_LANGUAGE_TAG] ?? messageBundle[Object.keys(messageBundle)[0]] ?? {}) } diff --git a/src/bin/keycloakify/generateResources/generateResourcesForMainTheme.ts b/src/bin/keycloakify/generateResources/generateResourcesForMainTheme.ts index 057c7878..00577423 100644 --- a/src/bin/keycloakify/generateResources/generateResourcesForMainTheme.ts +++ b/src/bin/keycloakify/generateResources/generateResourcesForMainTheme.ts @@ -15,12 +15,12 @@ import { } from "../generateFtl"; import { type ThemeType, - lastKeycloakVersionWithAccountV1, - keycloak_resources, - accountV1ThemeName, - basenameOfTheKeycloakifyResourcesDir, - loginThemePageIds, - accountThemePageIds + LAST_KEYCLOAK_VERSION_WITH_ACCOUNT_V1, + KEYCLOAK_RESOURCES, + ACCOUNT_V1_THEME_NAME, + BASENAME_OF_KEYCLOAKIFY_RESOURCES_DIR, + LOGIN_THEME_PAGE_IDS, + ACCOUNT_THEME_PAGE_IDS } from "../../shared/constants"; import type { BuildContext } from "../../shared/buildContext"; import { assert, type Equals } from "tsafe/assert"; @@ -85,7 +85,7 @@ export async function generateResourcesForMainTheme(params: { const destDirPath = pathJoin( themeTypeDirPath, "resources", - basenameOfTheKeycloakifyResourcesDir + BASENAME_OF_KEYCLOAKIFY_RESOURCES_DIR ); // NOTE: Prevent accumulation of files in the assets dir, as names are hashed they pile up. @@ -103,7 +103,7 @@ export async function generateResourcesForMainTheme(params: { themeType: "login" }), "resources", - basenameOfTheKeycloakifyResourcesDir + BASENAME_OF_KEYCLOAKIFY_RESOURCES_DIR ), destDirPath }); @@ -114,7 +114,7 @@ export async function generateResourcesForMainTheme(params: { { const dirPath = pathJoin( buildContext.projectBuildDirPath, - keycloak_resources + KEYCLOAK_RESOURCES ); if (fs.existsSync(dirPath)) { @@ -122,7 +122,7 @@ export async function generateResourcesForMainTheme(params: { throw new Error( [ - `Keycloakify build error: The ${keycloak_resources} directory shouldn't exist in your build directory.`, + `Keycloakify build error: The ${KEYCLOAK_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`, @@ -182,9 +182,9 @@ export async function generateResourcesForMainTheme(params: { ...(() => { switch (themeType) { case "login": - return loginThemePageIds; + return LOGIN_THEME_PAGE_IDS; case "account": - return isAccountV3 ? ["index.ftl"] : accountThemePageIds; + return isAccountV3 ? ["index.ftl"] : ACCOUNT_THEME_PAGE_IDS; } })(), ...(isAccountV3 @@ -238,7 +238,7 @@ export async function generateResourcesForMainTheme(params: { keycloakVersion: (() => { switch (themeType) { case "account": - return lastKeycloakVersionWithAccountV1; + return LAST_KEYCLOAK_VERSION_WITH_ACCOUNT_V1; case "login": return buildContext.loginThemeResourcesFromKeycloakVersion; } @@ -256,7 +256,7 @@ export async function generateResourcesForMainTheme(params: { `parent=${(() => { switch (themeType) { case "account": - return isAccountV3 ? "base" : accountV1ThemeName; + return isAccountV3 ? "base" : ACCOUNT_V1_THEME_NAME; case "login": return "keycloak"; } @@ -347,7 +347,7 @@ export async function generateResourcesForMainTheme(params: { if (buildContext.recordIsImplementedByThemeType.account) { metaInfKeycloakThemes.themes.push({ - name: accountV1ThemeName, + name: ACCOUNT_V1_THEME_NAME, types: ["account"] }); } diff --git a/src/bin/keycloakify/generateResources/readExtraPageNames.ts b/src/bin/keycloakify/generateResources/readExtraPageNames.ts index aa100364..12171d95 100644 --- a/src/bin/keycloakify/generateResources/readExtraPageNames.ts +++ b/src/bin/keycloakify/generateResources/readExtraPageNames.ts @@ -5,8 +5,8 @@ import * as fs from "fs"; import { join as pathJoin } from "path"; import { type ThemeType, - accountThemePageIds, - loginThemePageIds + ACCOUNT_THEME_PAGE_IDS, + LOGIN_THEME_PAGE_IDS } from "../../shared/constants"; export function readExtraPagesNames(params: { @@ -41,9 +41,9 @@ export function readExtraPagesNames(params: { return extraPages.reduce(...removeDuplicates()).filter(pageId => { switch (themeType) { case "account": - return !id(accountThemePageIds).includes(pageId); + return !id(ACCOUNT_THEME_PAGE_IDS).includes(pageId); case "login": - return !id(loginThemePageIds).includes(pageId); + return !id(LOGIN_THEME_PAGE_IDS).includes(pageId); } }); } diff --git a/src/bin/keycloakify/keycloakify.ts b/src/bin/keycloakify/keycloakify.ts index a21a9a51..ec6be63b 100644 --- a/src/bin/keycloakify/keycloakify.ts +++ b/src/bin/keycloakify/keycloakify.ts @@ -3,7 +3,7 @@ import { join as pathJoin, relative as pathRelative, sep as pathSep } from "path import * as child_process from "child_process"; import * as fs from "fs"; import { getBuildContext } from "../shared/buildContext"; -import { vitePluginSubScriptEnvNames } from "../shared/constants"; +import { VITE_PLUGIN_SUB_SCRIPTS_ENV_NAMES } from "../shared/constants"; import { buildJars } from "./buildJars"; import type { CliCommandOptions } from "../main"; import chalk from "chalk"; @@ -93,10 +93,12 @@ export async function command(params: { cliCommandOptions: CliCommandOptions }) cwd: buildContext.projectDirPath, env: { ...process.env, - [vitePluginSubScriptEnvNames.runPostBuildScript]: JSON.stringify({ - resourcesDirPath, - buildContext - }) + [VITE_PLUGIN_SUB_SCRIPTS_ENV_NAMES.RUN_POST_BUILD_SCRIPT]: JSON.stringify( + { + resourcesDirPath, + buildContext + } + ) } }); } diff --git a/src/bin/keycloakify/replacers/replaceImportsInCssCode.ts b/src/bin/keycloakify/replacers/replaceImportsInCssCode.ts index 3d753b29..41306d85 100644 --- a/src/bin/keycloakify/replacers/replaceImportsInCssCode.ts +++ b/src/bin/keycloakify/replacers/replaceImportsInCssCode.ts @@ -1,5 +1,5 @@ import type { BuildContext } from "../../shared/buildContext"; -import { basenameOfTheKeycloakifyResourcesDir } from "../../shared/constants"; +import { BASENAME_OF_KEYCLOAKIFY_RESOURCES_DIR } from "../../shared/constants"; import { assert } from "tsafe/assert"; import { posix } from "path"; @@ -37,7 +37,7 @@ export function replaceImportsInCssCode(params: { break inline_style_in_html; } - return `url(\${xKeycloakify.resourcesPath}/${basenameOfTheKeycloakifyResourcesDir}${assetFileAbsoluteUrlPathname})`; + return `url(\${xKeycloakify.resourcesPath}/${BASENAME_OF_KEYCLOAKIFY_RESOURCES_DIR}${assetFileAbsoluteUrlPathname})`; } const assetFileRelativeUrlPathname = posix.relative( diff --git a/src/bin/keycloakify/replacers/replaceImportsInJsCode/vite.ts b/src/bin/keycloakify/replacers/replaceImportsInJsCode/vite.ts index 4cb64370..20048cf3 100644 --- a/src/bin/keycloakify/replacers/replaceImportsInJsCode/vite.ts +++ b/src/bin/keycloakify/replacers/replaceImportsInJsCode/vite.ts @@ -1,4 +1,4 @@ -import { basenameOfTheKeycloakifyResourcesDir } from "../../../shared/constants"; +import { BASENAME_OF_KEYCLOAKIFY_RESOURCES_DIR } from "../../../shared/constants"; import { assert } from "tsafe/assert"; import type { BuildContext } from "../../../shared/buildContext"; import * as nodePath from "path"; @@ -85,13 +85,13 @@ export function replaceImportsInJsCode_vite(params: { fixedJsCode = replaceAll( fixedJsCode, `"${relativePathOfAssetFile}"`, - `(window.kcContext["x-keycloakify"].resourcesPath.substring(1) + "/${basenameOfTheKeycloakifyResourcesDir}/${relativePathOfAssetFile}")` + `(window.kcContext["x-keycloakify"].resourcesPath.substring(1) + "/${BASENAME_OF_KEYCLOAKIFY_RESOURCES_DIR}/${relativePathOfAssetFile}")` ); fixedJsCode = replaceAll( fixedJsCode, `"${buildContext.urlPathname ?? "/"}${relativePathOfAssetFile}"`, - `(window.kcContext["x-keycloakify"].resourcesPath + "/${basenameOfTheKeycloakifyResourcesDir}/${relativePathOfAssetFile}")` + `(window.kcContext["x-keycloakify"].resourcesPath + "/${BASENAME_OF_KEYCLOAKIFY_RESOURCES_DIR}/${relativePathOfAssetFile}")` ); }); } diff --git a/src/bin/keycloakify/replacers/replaceImportsInJsCode/webpack.ts b/src/bin/keycloakify/replacers/replaceImportsInJsCode/webpack.ts index a5e53295..7c03125f 100644 --- a/src/bin/keycloakify/replacers/replaceImportsInJsCode/webpack.ts +++ b/src/bin/keycloakify/replacers/replaceImportsInJsCode/webpack.ts @@ -1,4 +1,4 @@ -import { basenameOfTheKeycloakifyResourcesDir } from "../../../shared/constants"; +import { BASENAME_OF_KEYCLOAKIFY_RESOURCES_DIR } from "../../../shared/constants"; import { assert } from "tsafe/assert"; import type { BuildContext } from "../../../shared/buildContext"; import * as nodePath from "path"; @@ -90,7 +90,7 @@ export function replaceImportsInJsCode_webpack(params: { return "${u}"; })()] = ${ isArrowFunction ? `${e} =>` : `function(${e}) { return ` - } "/${basenameOfTheKeycloakifyResourcesDir}/${staticDir}${language}/"` + } "/${BASENAME_OF_KEYCLOAKIFY_RESOURCES_DIR}/${staticDir}${language}/"` .replace(/\s+/g, " ") .trim(); } @@ -104,7 +104,7 @@ export function replaceImportsInJsCode_webpack(params: { `[a-zA-Z]+\\.[a-zA-Z]+\\+"${staticDir.replace(/\//g, "\\/")}`, "g" ), - `window.kcContext["x-keycloakify"].resourcesPath + "/${basenameOfTheKeycloakifyResourcesDir}/${staticDir}` + `window.kcContext["x-keycloakify"].resourcesPath + "/${BASENAME_OF_KEYCLOAKIFY_RESOURCES_DIR}/${staticDir}` ); return { fixedJsCode }; diff --git a/src/bin/shared/buildContext.ts b/src/bin/shared/buildContext.ts index e24046bc..c970f420 100644 --- a/src/bin/shared/buildContext.ts +++ b/src/bin/shared/buildContext.ts @@ -13,13 +13,13 @@ import * as fs from "fs"; import { assert, type Equals } from "tsafe/assert"; import * as child_process from "child_process"; import { - vitePluginSubScriptEnvNames, - buildForKeycloakMajorVersionEnvName + VITE_PLUGIN_SUB_SCRIPTS_ENV_NAMES, + BUILD_FOR_KEYCLOAK_MAJOR_VERSION_ENV_NAME } from "./constants"; import type { KeycloakVersionRange } from "./KeycloakVersionRange"; import { exclude } from "tsafe"; import { crawl } from "../tools/crawl"; -import { themeTypes } from "./constants"; +import { THEME_TYPES } from "./constants"; import { objectFromEntries } from "tsafe/objectFromEntries"; import { objectEntries } from "tsafe/objectEntries"; import { type ThemeType } from "./constants"; @@ -136,7 +136,7 @@ export function getBuildContext(params: { return { themeSrcDirPath }; } - for (const themeType of [...themeTypes, "email"]) { + for (const themeType of [...THEME_TYPES, "email"]) { if (!fs.existsSync(pathJoin(srcDirPath, themeType))) { continue; } @@ -171,18 +171,18 @@ export function getBuildContext(params: { cwd: projectDirPath, env: { ...process.env, - [vitePluginSubScriptEnvNames.resolveViteConfig]: "true" + [VITE_PLUGIN_SUB_SCRIPTS_ENV_NAMES.RESOLVE_VITE_CONFIG]: "true" } }) .toString("utf8"); assert( - output.includes(vitePluginSubScriptEnvNames.resolveViteConfig), + output.includes(VITE_PLUGIN_SUB_SCRIPTS_ENV_NAMES.RESOLVE_VITE_CONFIG), "Seems like the Keycloakify's Vite plugin is not installed." ); const resolvedViteConfigStr = output - .split(vitePluginSubScriptEnvNames.resolveViteConfig) + .split(VITE_PLUGIN_SUB_SCRIPTS_ENV_NAMES.RESOLVE_VITE_CONFIG) .reverse()[0]; const resolvedViteConfig: ResolvedViteConfig = JSON.parse(resolvedViteConfigStr); @@ -594,7 +594,8 @@ export function getBuildContext(params: { build_for_specific_keycloak_major_version: { const buildForKeycloakMajorVersionNumber = (() => { - const envValue = process.env[buildForKeycloakMajorVersionEnvName]; + const envValue = + process.env[BUILD_FOR_KEYCLOAK_MAJOR_VERSION_ENV_NAME]; if (envValue === undefined) { return undefined; diff --git a/src/bin/shared/constants.ts b/src/bin/shared/constants.ts index 40882a02..843cb8cf 100644 --- a/src/bin/shared/constants.ts +++ b/src/bin/shared/constants.ts @@ -1,22 +1,22 @@ -export const keycloak_resources = "keycloak-resources"; -export const resources_common = "resources-common"; -export const lastKeycloakVersionWithAccountV1 = "21.1.2"; -export const basenameOfTheKeycloakifyResourcesDir = "dist"; +export const KEYCLOAK_RESOURCES = "keycloak-resources"; +export const RESOURCES_COMMON = "resources-common"; +export const LAST_KEYCLOAK_VERSION_WITH_ACCOUNT_V1 = "21.1.2"; +export const BASENAME_OF_KEYCLOAKIFY_RESOURCES_DIR = "dist"; -export const themeTypes = ["login", "account"] as const; -export const accountV1ThemeName = "account-v1"; +export const THEME_TYPES = ["login", "account"] as const; +export const ACCOUNT_V1_THEME_NAME = "account-v1"; -export type ThemeType = (typeof themeTypes)[number]; +export type ThemeType = (typeof THEME_TYPES)[number]; -export const vitePluginSubScriptEnvNames = { - runPostBuildScript: "KEYCLOAKIFY_RUN_POST_BUILD_SCRIPT", - resolveViteConfig: "KEYCLOAKIFY_RESOLVE_VITE_CONFIG" +export const VITE_PLUGIN_SUB_SCRIPTS_ENV_NAMES = { + RUN_POST_BUILD_SCRIPT: "KEYCLOAKIFY_RUN_POST_BUILD_SCRIPT", + RESOLVE_VITE_CONFIG: "KEYCLOAKIFY_RESOLVE_VITE_CONFIG" } as const; -export const buildForKeycloakMajorVersionEnvName = +export const BUILD_FOR_KEYCLOAK_MAJOR_VERSION_ENV_NAME = "KEYCLOAKIFY_BUILD_FOR_KEYCLOAK_MAJOR_VERSION"; -export const loginThemePageIds = [ +export const LOGIN_THEME_PAGE_IDS = [ "login.ftl", "login-username.ftl", "login-password.ftl", @@ -53,7 +53,7 @@ export const loginThemePageIds = [ "webauthn-error.ftl" ] as const; -export const accountThemePageIds = [ +export const ACCOUNT_THEME_PAGE_IDS = [ "password.ftl", "account.ftl", "sessions.ftl", @@ -63,9 +63,9 @@ export const accountThemePageIds = [ "federatedIdentity.ftl" ] as const; -export type LoginThemePageId = (typeof loginThemePageIds)[number]; -export type AccountThemePageId = (typeof accountThemePageIds)[number]; +export type LoginThemePageId = (typeof LOGIN_THEME_PAGE_IDS)[number]; +export type AccountThemePageId = (typeof ACCOUNT_THEME_PAGE_IDS)[number]; -export const containerName = "keycloak-keycloakify"; +export const CONTAINER_NAME = "keycloak-keycloakify"; -export const fallbackLanguageTag = "en"; +export const FALLBACK_LANGUAGE_TAG = "en"; diff --git a/src/bin/shared/copyKeycloakResourcesToPublic.ts b/src/bin/shared/copyKeycloakResourcesToPublic.ts index a5aa4060..5f4778ab 100644 --- a/src/bin/shared/copyKeycloakResourcesToPublic.ts +++ b/src/bin/shared/copyKeycloakResourcesToPublic.ts @@ -4,9 +4,9 @@ import { } from "./downloadKeycloakStaticResources"; import { join as pathJoin, relative as pathRelative } from "path"; import { - themeTypes, - keycloak_resources, - lastKeycloakVersionWithAccountV1 + THEME_TYPES, + KEYCLOAK_RESOURCES, + LAST_KEYCLOAK_VERSION_WITH_ACCOUNT_V1 } from "../shared/constants"; import { readThisNpmPackageVersion } from "../tools/readThisNpmPackageVersion"; import { assert } from "tsafe/assert"; @@ -26,7 +26,7 @@ export async function copyKeycloakResourcesToPublic(params: { }) { const { buildContext } = params; - const destDirPath = pathJoin(buildContext.publicDirPath, keycloak_resources); + const destDirPath = pathJoin(buildContext.publicDirPath, KEYCLOAK_RESOURCES); const keycloakifyBuildinfoFilePath = pathJoin(destDirPath, "keycloakify.buildinfo"); @@ -66,14 +66,14 @@ export async function copyKeycloakResourcesToPublic(params: { fs.writeFileSync(pathJoin(destDirPath, ".gitignore"), Buffer.from("*", "utf8")); - for (const themeType of themeTypes) { + for (const themeType of THEME_TYPES) { await downloadKeycloakStaticResources({ keycloakVersion: (() => { switch (themeType) { case "login": return buildContext.loginThemeResourcesFromKeycloakVersion; case "account": - return lastKeycloakVersionWithAccountV1; + return LAST_KEYCLOAK_VERSION_WITH_ACCOUNT_V1; } })(), themeType, diff --git a/src/bin/shared/downloadKeycloakDefaultTheme.ts b/src/bin/shared/downloadKeycloakDefaultTheme.ts index a6da8e34..c72e251a 100644 --- a/src/bin/shared/downloadKeycloakDefaultTheme.ts +++ b/src/bin/shared/downloadKeycloakDefaultTheme.ts @@ -1,7 +1,7 @@ import { join as pathJoin, relative as pathRelative } from "path"; import { type BuildContext } from "./buildContext"; import { assert } from "tsafe/assert"; -import { lastKeycloakVersionWithAccountV1 } from "./constants"; +import { LAST_KEYCLOAK_VERSION_WITH_ACCOUNT_V1 } from "./constants"; import { downloadAndExtractArchive } from "../tools/downloadAndExtractArchive"; export type BuildContextLike = { @@ -43,7 +43,7 @@ export async function downloadKeycloakDefaultTheme(params: { } last_account_v1_transformations: { - if (lastKeycloakVersionWithAccountV1 !== keycloakVersion) { + if (LAST_KEYCLOAK_VERSION_WITH_ACCOUNT_V1 !== keycloakVersion) { break last_account_v1_transformations; } diff --git a/src/bin/shared/downloadKeycloakStaticResources.ts b/src/bin/shared/downloadKeycloakStaticResources.ts index a092abb5..a66b6272 100644 --- a/src/bin/shared/downloadKeycloakStaticResources.ts +++ b/src/bin/shared/downloadKeycloakStaticResources.ts @@ -4,7 +4,7 @@ import { downloadKeycloakDefaultTheme, type BuildContextLike as BuildContextLike_downloadKeycloakDefaultTheme } from "./downloadKeycloakDefaultTheme"; -import { resources_common, type ThemeType } from "./constants"; +import { RESOURCES_COMMON, type ThemeType } from "./constants"; import type { BuildContext } from "./buildContext"; import { assert } from "tsafe/assert"; import { existsAsync } from "../tools/fs.existsAsync"; @@ -48,6 +48,6 @@ export async function downloadKeycloakStaticResources(params: { transformCodebase({ srcDirPath: pathJoin(defaultThemeDirPath, "keycloak", "common", "resources"), - destDirPath: pathJoin(resourcesDirPath, resources_common) + destDirPath: pathJoin(resourcesDirPath, RESOURCES_COMMON) }); } diff --git a/src/bin/start-keycloak/keycloakifyBuild.ts b/src/bin/start-keycloak/keycloakifyBuild.ts index f8870228..0daaadcc 100644 --- a/src/bin/start-keycloak/keycloakifyBuild.ts +++ b/src/bin/start-keycloak/keycloakifyBuild.ts @@ -1,4 +1,4 @@ -import { buildForKeycloakMajorVersionEnvName } from "../shared/constants"; +import { BUILD_FOR_KEYCLOAK_MAJOR_VERSION_ENV_NAME } from "../shared/constants"; import * as child_process from "child_process"; import { Deferred } from "evt/tools/Deferred"; import { assert } from "tsafe/assert"; @@ -26,7 +26,7 @@ export async function keycloakifyBuild(params: { cwd: buildContext.projectDirPath, env: { ...process.env, - [buildForKeycloakMajorVersionEnvName]: `${buildForKeycloakMajorVersionNumber}` + [BUILD_FOR_KEYCLOAK_MAJOR_VERSION_ENV_NAME]: `${buildForKeycloakMajorVersionNumber}` }, shell: true }); diff --git a/src/bin/start-keycloak/start-keycloak.ts b/src/bin/start-keycloak/start-keycloak.ts index 61aed440..4d3fb46f 100644 --- a/src/bin/start-keycloak/start-keycloak.ts +++ b/src/bin/start-keycloak/start-keycloak.ts @@ -2,7 +2,7 @@ import { getBuildContext } from "../shared/buildContext"; import { exclude } from "tsafe/exclude"; import type { CliCommandOptions as CliCommandOptions_common } from "../main"; import { promptKeycloakVersion } from "../shared/promptKeycloakVersion"; -import { accountV1ThemeName, containerName } from "../shared/constants"; +import { ACCOUNT_V1_THEME_NAME, CONTAINER_NAME } from "../shared/constants"; import { SemVer } from "../tools/SemVer"; import { assert } from "tsafe/assert"; import * as fs from "fs"; @@ -269,7 +269,7 @@ export async function command(params: { cliCommandOptions: CliCommandOptions }) fs.copyFileSync(jarFilePath, jarFilePath_cacheDir); try { - child_process.execSync(`docker rm --force ${containerName}`, { + child_process.execSync(`docker rm --force ${CONTAINER_NAME}`, { stdio: "ignore" }); } catch {} @@ -279,7 +279,7 @@ export async function command(params: { cliCommandOptions: CliCommandOptions }) [ "run", ...["-p", `${cliCommandOptions.port}:8080`], - ...["--name", containerName], + ...["--name", CONTAINER_NAME], ...["-e", "KEYCLOAK_ADMIN=admin"], ...["-e", "KEYCLOAK_ADMIN_PASSWORD=admin"], ...(realmJsonFilePath === undefined @@ -301,10 +301,10 @@ export async function command(params: { cliCommandOptions: CliCommandOptions }) pathJoin( buildContext.keycloakifyBuildDirPath, "theme", - accountV1ThemeName + ACCOUNT_V1_THEME_NAME ) ) - ? [accountV1ThemeName] + ? [ACCOUNT_V1_THEME_NAME] : []) ] .map(themeName => ({ diff --git a/src/login/KcContext/kcContextMocks.ts b/src/login/KcContext/kcContextMocks.ts index f6cd502e..030fb089 100644 --- a/src/login/KcContext/kcContextMocks.ts +++ b/src/login/KcContext/kcContextMocks.ts @@ -1,8 +1,8 @@ import "keycloakify/tools/Object.fromEntries"; import type { KcContext, Attribute } from "./KcContext"; import { - resources_common, - keycloak_resources, + RESOURCES_COMMON, + KEYCLOAK_RESOURCES, type LoginThemePageId } from "keycloakify/bin/shared/constants"; import { id } from "tsafe/id"; @@ -76,7 +76,7 @@ const attributesByName = Object.fromEntries( ]).map(attribute => [attribute.name, attribute]) ); -const resourcesPath = `${BASE_URL}${keycloak_resources}/login/resources`; +const resourcesPath = `${BASE_URL}${KEYCLOAK_RESOURCES}/login/resources`; export const kcContextCommonMock: KcContext.Common = { themeVersion: "0.0.0", @@ -86,7 +86,7 @@ export const kcContextCommonMock: KcContext.Common = { url: { loginAction: "#", resourcesPath, - resourcesCommonPath: `${resourcesPath}/${resources_common}`, + resourcesCommonPath: `${resourcesPath}/${RESOURCES_COMMON}`, loginRestartFlowUrl: "#", loginUrl: "#", ssoLoginInOtherTabsUrl: "#" diff --git a/src/login/i18n/i18n.tsx b/src/login/i18n/i18n.tsx index 3bd56e49..ca721bd4 100644 --- a/src/login/i18n/i18n.tsx +++ b/src/login/i18n/i18n.tsx @@ -3,7 +3,7 @@ import { assert } from "tsafe/assert"; import messages_defaultSet_fallbackLanguage from "./messages_defaultSet/en"; import { fetchMessages_defaultSet } from "./messages_defaultSet"; import type { KcContext } from "../KcContext"; -import { fallbackLanguageTag } from "keycloakify/bin/shared/constants"; +import { FALLBACK_LANGUAGE_TAG } from "keycloakify/bin/shared/constants"; import { id } from "tsafe/id"; export type KcContextLike = { @@ -104,7 +104,7 @@ export function createGetI18n(me } const partialI18n: Pick = { - currentLanguageTag: kcContext.locale?.currentLanguageTag ?? fallbackLanguageTag, + currentLanguageTag: kcContext.locale?.currentLanguageTag ?? FALLBACK_LANGUAGE_TAG, getChangeLocaleUrl: newLanguageTag => { const { locale } = kcContext; @@ -122,7 +122,7 @@ export function createGetI18n(me const { createI18nTranslationFunctions } = createI18nTranslationFunctionsFactory({ messages_themeDefined: messagesByLanguageTag_themeDefined[partialI18n.currentLanguageTag] ?? - messagesByLanguageTag_themeDefined[fallbackLanguageTag] ?? + messagesByLanguageTag_themeDefined[FALLBACK_LANGUAGE_TAG] ?? (() => { const firstLanguageTag = Object.keys(messagesByLanguageTag_themeDefined)[0]; if (firstLanguageTag === undefined) { @@ -133,7 +133,7 @@ export function createGetI18n(me messages_fromKcServer: kcContext["x-keycloakify"].messages }); - const isCurrentLanguageFallbackLanguage = partialI18n.currentLanguageTag === fallbackLanguageTag; + const isCurrentLanguageFallbackLanguage = partialI18n.currentLanguageTag === FALLBACK_LANGUAGE_TAG; const result: Result = { i18n: { diff --git a/src/vite-plugin/vite-plugin.ts b/src/vite-plugin/vite-plugin.ts index a41010ae..7130969a 100644 --- a/src/vite-plugin/vite-plugin.ts +++ b/src/vite-plugin/vite-plugin.ts @@ -1,9 +1,9 @@ import { join as pathJoin, relative as pathRelative, sep as pathSep } from "path"; import type { Plugin } from "vite"; import { - basenameOfTheKeycloakifyResourcesDir, - keycloak_resources, - vitePluginSubScriptEnvNames + BASENAME_OF_KEYCLOAKIFY_RESOURCES_DIR, + KEYCLOAK_RESOURCES, + VITE_PLUGIN_SUB_SCRIPTS_ENV_NAMES } from "../bin/shared/constants"; import { id } from "tsafe/id"; import { rm } from "../bin/tools/fs.rm"; @@ -38,7 +38,7 @@ export function keycloakify(params?: Params) { run_post_build_script_case: { const envValue = - process.env[vitePluginSubScriptEnvNames.runPostBuildScript]; + process.env[VITE_PLUGIN_SUB_SCRIPTS_ENV_NAMES.RUN_POST_BUILD_SCRIPT]; if (envValue === undefined) { break run_post_build_script_case; @@ -94,13 +94,13 @@ export function keycloakify(params?: Params) { resolve_vite_config_case: { const envValue = - process.env[vitePluginSubScriptEnvNames.resolveViteConfig]; + process.env[VITE_PLUGIN_SUB_SCRIPTS_ENV_NAMES.RESOLVE_VITE_CONFIG]; if (envValue === undefined) { break resolve_vite_config_case; } - console.log(vitePluginSubScriptEnvNames.resolveViteConfig); + console.log(VITE_PLUGIN_SUB_SCRIPTS_ENV_NAMES.RESOLVE_VITE_CONFIG); console.log( JSON.stringify( @@ -172,7 +172,7 @@ export function keycloakify(params?: Params) { `(`, `(window.kcContext === undefined || import.meta.env.MODE === "development")?`, `"${urlPathname ?? "/"}":`, - `(window.kcContext["x-keycloakify"].resourcesPath + "/${basenameOfTheKeycloakifyResourcesDir}/")`, + `(window.kcContext["x-keycloakify"].resourcesPath + "/${BASENAME_OF_KEYCLOAKIFY_RESOURCES_DIR}/")`, `)` ].join("") ); @@ -205,7 +205,7 @@ export function keycloakify(params?: Params) { assert(buildDirPath !== undefined); - await rm(pathJoin(buildDirPath, keycloak_resources), { + await rm(pathJoin(buildDirPath, KEYCLOAK_RESOURCES), { recursive: true, force: true }); diff --git a/test/bin/replacers.spec.ts b/test/bin/replacers.spec.ts index 5cfb3f83..9635a104 100644 --- a/test/bin/replacers.spec.ts +++ b/test/bin/replacers.spec.ts @@ -2,7 +2,7 @@ import { replaceImportsInJsCode_vite } from "keycloakify/bin/keycloakify/replace import { replaceImportsInJsCode_webpack } from "keycloakify/bin/keycloakify/replacers/replaceImportsInJsCode/webpack"; import { replaceImportsInCssCode } from "keycloakify/bin/keycloakify/replacers/replaceImportsInCssCode"; import { expect, it, describe } from "vitest"; -import { basenameOfTheKeycloakifyResourcesDir } from "keycloakify/bin/shared/constants"; +import { BASENAME_OF_KEYCLOAKIFY_RESOURCES_DIR } from "keycloakify/bin/shared/constants"; describe("js replacer - vite", () => { it("replaceImportsInJsCode_vite - 1", () => { @@ -87,13 +87,13 @@ describe("js replacer - vite", () => { }); const fixedJsCodeExpected = ` - S=(window.kcContext["x-keycloakify"].resourcesPath + "/${basenameOfTheKeycloakifyResourcesDir}/assets/keycloakify-logo-mqjydaoZ.png"),H=(()=>{ + S=(window.kcContext["x-keycloakify"].resourcesPath + "/${BASENAME_OF_KEYCLOAKIFY_RESOURCES_DIR}/assets/keycloakify-logo-mqjydaoZ.png"),H=(()=>{ function __vite__mapDeps(indexes) { if (!__vite__mapDeps.viteFileDeps) { __vite__mapDeps.viteFileDeps = [ - (window.kcContext["x-keycloakify"].resourcesPath.substring(1) + "/${basenameOfTheKeycloakifyResourcesDir}/assets/Login-dJpPRzM4.js"), - (window.kcContext["x-keycloakify"].resourcesPath.substring(1) + "/${basenameOfTheKeycloakifyResourcesDir}/assets/index-XwzrZ5Gu.js") + (window.kcContext["x-keycloakify"].resourcesPath.substring(1) + "/${BASENAME_OF_KEYCLOAKIFY_RESOURCES_DIR}/assets/Login-dJpPRzM4.js"), + (window.kcContext["x-keycloakify"].resourcesPath.substring(1) + "/${BASENAME_OF_KEYCLOAKIFY_RESOURCES_DIR}/assets/index-XwzrZ5Gu.js") ] } return indexes.map((i) => __vite__mapDeps.viteFileDeps[i]) @@ -146,13 +146,13 @@ describe("js replacer - vite", () => { }); const fixedJsCodeExpected = ` - S=(window.kcContext["x-keycloakify"].resourcesPath + "/${basenameOfTheKeycloakifyResourcesDir}/foo/bar/keycloakify-logo-mqjydaoZ.png"),H=(()=>{ + S=(window.kcContext["x-keycloakify"].resourcesPath + "/${BASENAME_OF_KEYCLOAKIFY_RESOURCES_DIR}/foo/bar/keycloakify-logo-mqjydaoZ.png"),H=(()=>{ function __vite__mapDeps(indexes) { if (!__vite__mapDeps.viteFileDeps) { __vite__mapDeps.viteFileDeps = [ - (window.kcContext["x-keycloakify"].resourcesPath.substring(1) + "/${basenameOfTheKeycloakifyResourcesDir}/foo/bar/Login-dJpPRzM4.js"), - (window.kcContext["x-keycloakify"].resourcesPath.substring(1) + "/${basenameOfTheKeycloakifyResourcesDir}/foo/bar/index-XwzrZ5Gu.js") + (window.kcContext["x-keycloakify"].resourcesPath.substring(1) + "/${BASENAME_OF_KEYCLOAKIFY_RESOURCES_DIR}/foo/bar/Login-dJpPRzM4.js"), + (window.kcContext["x-keycloakify"].resourcesPath.substring(1) + "/${BASENAME_OF_KEYCLOAKIFY_RESOURCES_DIR}/foo/bar/index-XwzrZ5Gu.js") ] } return indexes.map((i) => __vite__mapDeps.viteFileDeps[i]) @@ -205,13 +205,13 @@ describe("js replacer - vite", () => { }); const fixedJsCodeExpected = ` - S=(window.kcContext["x-keycloakify"].resourcesPath + "/${basenameOfTheKeycloakifyResourcesDir}/assets/keycloakify-logo-mqjydaoZ.png"),H=(()=>{ + S=(window.kcContext["x-keycloakify"].resourcesPath + "/${BASENAME_OF_KEYCLOAKIFY_RESOURCES_DIR}/assets/keycloakify-logo-mqjydaoZ.png"),H=(()=>{ function __vite__mapDeps(indexes) { if (!__vite__mapDeps.viteFileDeps) { __vite__mapDeps.viteFileDeps = [ - (window.kcContext["x-keycloakify"].resourcesPath.substring(1) + "/${basenameOfTheKeycloakifyResourcesDir}/assets/Login-dJpPRzM4.js"), - (window.kcContext["x-keycloakify"].resourcesPath.substring(1) + "/${basenameOfTheKeycloakifyResourcesDir}/assets/index-XwzrZ5Gu.js") + (window.kcContext["x-keycloakify"].resourcesPath.substring(1) + "/${BASENAME_OF_KEYCLOAKIFY_RESOURCES_DIR}/assets/Login-dJpPRzM4.js"), + (window.kcContext["x-keycloakify"].resourcesPath.substring(1) + "/${BASENAME_OF_KEYCLOAKIFY_RESOURCES_DIR}/assets/index-XwzrZ5Gu.js") ] } return indexes.map((i) => __vite__mapDeps.viteFileDeps[i]) @@ -267,13 +267,13 @@ describe("js replacer - webpack", () => { const fixedJsCodeExpected = ` function f() { - return window.kcContext["x-keycloakify"].resourcesPath + "/${basenameOfTheKeycloakifyResourcesDir}/static/js/" + ({}[e] || e) + "." + { + return window.kcContext["x-keycloakify"].resourcesPath + "/${BASENAME_OF_KEYCLOAKIFY_RESOURCES_DIR}/static/js/" + ({}[e] || e) + "." + { 3: "0664cdc0" }[e] + ".chunk.js" } function sameAsF() { - return window.kcContext["x-keycloakify"].resourcesPath + "/${basenameOfTheKeycloakifyResourcesDir}/static/js/" + ({}[e] || e) + "." + { + return window.kcContext["x-keycloakify"].resourcesPath + "/${BASENAME_OF_KEYCLOAKIFY_RESOURCES_DIR}/static/js/" + ({}[e] || e) + "." + { 3: "0664cdc0" }[e] + ".chunk.js" } @@ -288,7 +288,7 @@ describe("js replacer - webpack", () => { } return "u"; })()] = function(e) { - return "/${basenameOfTheKeycloakifyResourcesDir}/static/js/" + e + "." + { + return "/${BASENAME_OF_KEYCLOAKIFY_RESOURCES_DIR}/static/js/" + e + "." + { 147: "6c5cee76", 787: "8da10fcf", 922: "be170a73" @@ -305,7 +305,7 @@ describe("js replacer - webpack", () => { } return "miniCssF"; })()] = function(e) { - return "/${basenameOfTheKeycloakifyResourcesDir}/static/css/" + e + "." + { + return "/${BASENAME_OF_KEYCLOAKIFY_RESOURCES_DIR}/static/css/" + e + "." + { 164:"dcfd7749", 908:"67c9ed2c" } [e] + ".chunk.css" @@ -320,7 +320,7 @@ describe("js replacer - webpack", () => { }); } return "u"; - })()] = e => "/${basenameOfTheKeycloakifyResourcesDir}/static/js/"+e+"."+{69:"4f205f87",128:"49264537",453:"b2fed72e",482:"f0106901"}[e]+".chunk.js" + })()] = e => "/${BASENAME_OF_KEYCLOAKIFY_RESOURCES_DIR}/static/js/"+e+"."+{69:"4f205f87",128:"49264537",453:"b2fed72e",482:"f0106901"}[e]+".chunk.js" t[(function(){ var pd = Object.getOwnPropertyDescriptor(t, "p"); @@ -331,7 +331,7 @@ describe("js replacer - webpack", () => { }); } return "miniCssF"; - })()] = e => "/${basenameOfTheKeycloakifyResourcesDir}/static/css/"+e+"."+{164:"dcfd7749",908:"67c9ed2c"}[e]+".chunk.css" + })()] = e => "/${BASENAME_OF_KEYCLOAKIFY_RESOURCES_DIR}/static/css/"+e+"."+{164:"dcfd7749",908:"67c9ed2c"}[e]+".chunk.css" `; expect(isSameCode(fixedJsCode, fixedJsCodeExpected)).toBe(true); @@ -479,15 +479,15 @@ describe("css replacer", () => { const fixedCssCodeExpected = ` .my-div { - background: url(\${xKeycloakify.resourcesPath}/${basenameOfTheKeycloakifyResourcesDir}/background.png) no-repeat center center; + background: url(\${xKeycloakify.resourcesPath}/${BASENAME_OF_KEYCLOAKIFY_RESOURCES_DIR}/background.png) no-repeat center center; } .my-div2 { - background: url(\${xKeycloakify.resourcesPath}/${basenameOfTheKeycloakifyResourcesDir}/assets/background.png) repeat center center; + background: url(\${xKeycloakify.resourcesPath}/${BASENAME_OF_KEYCLOAKIFY_RESOURCES_DIR}/assets/background.png) repeat center center; } .my-div3 { - background-image: url(\${xKeycloakify.resourcesPath}/${basenameOfTheKeycloakifyResourcesDir}/assets/media/something.svg); + background-image: url(\${xKeycloakify.resourcesPath}/${BASENAME_OF_KEYCLOAKIFY_RESOURCES_DIR}/assets/media/something.svg); } `; @@ -517,15 +517,15 @@ describe("css replacer", () => { const fixedCssCodeExpected = ` .my-div { - background: url(\${xKeycloakify.resourcesPath}/${basenameOfTheKeycloakifyResourcesDir}/background.png) no-repeat center center; + background: url(\${xKeycloakify.resourcesPath}/${BASENAME_OF_KEYCLOAKIFY_RESOURCES_DIR}/background.png) no-repeat center center; } .my-div2 { - background: url(\${xKeycloakify.resourcesPath}/${basenameOfTheKeycloakifyResourcesDir}/assets/background.png) repeat center center; + background: url(\${xKeycloakify.resourcesPath}/${BASENAME_OF_KEYCLOAKIFY_RESOURCES_DIR}/assets/background.png) repeat center center; } .my-div3 { - background-image: url(\${xKeycloakify.resourcesPath}/${basenameOfTheKeycloakifyResourcesDir}/assets/media/something.svg); + background-image: url(\${xKeycloakify.resourcesPath}/${BASENAME_OF_KEYCLOAKIFY_RESOURCES_DIR}/assets/media/something.svg); } `;