Compare commits
2 Commits
v10.0.0-rc
...
v10.0.0-rc
Author | SHA1 | Date | |
---|---|---|---|
0aca4cc449 | |||
777d8690c2 |
2
.github/workflows/ci.yaml
vendored
2
.github/workflows/ci.yaml
vendored
@ -17,7 +17,7 @@ jobs:
|
||||
- uses: actions/setup-node@v4
|
||||
- uses: bahmutov/npm-install@v1
|
||||
- name: If this step fails run 'npm run format' then commit again.
|
||||
run: npm run _format --list-different
|
||||
run: npm run format:check
|
||||
test:
|
||||
runs-on: ${{ matrix.os }}
|
||||
needs: test_lint
|
||||
|
14
README.md
14
README.md
@ -17,12 +17,9 @@
|
||||
<a href="https://github.com/thomasdarimont/awesome-keycloak">
|
||||
<img src="https://awesome.re/mentioned-badge.svg"/>
|
||||
</a>
|
||||
<p align="center">
|
||||
Check out our discord server!<br/>
|
||||
<a href="https://discord.gg/mJdYJSdcm4">
|
||||
<img src="https://dcbadge.limes.pink/api/server/kYFZG7fQmn"/>
|
||||
</a>
|
||||
</p>
|
||||
<a href="https://discord.gg/kYFZG7fQmn">
|
||||
<img src="https://img.shields.io/discord/1097708346976505977"/>
|
||||
</a>
|
||||
<p align="center">
|
||||
<a href="https://www.keycloakify.dev">Home</a>
|
||||
-
|
||||
@ -41,9 +38,10 @@
|
||||
<img width="400" src="https://github.com/keycloakify/keycloakify/assets/6702424/e66d105c-c06f-47d1-8a31-a6ab09da4e80">
|
||||
</p>
|
||||
|
||||
Keycloakify is fully compatible with Keycloak 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, [~~22~~](https://github.com/keycloakify/keycloakify/issues/389#issuecomment-1822509763), 23, 24, 25...[and beyond](https://github.com/keycloakify/keycloakify/discussions/346#discussioncomment-5889791)
|
||||
Keycloakify is fully compatible with Keycloak 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, [~~22~~](https://github.com/keycloakify/keycloakify/issues/389#issuecomment-1822509763), **23** [and up](https://github.com/keycloakify/keycloakify/discussions/346#discussioncomment-5889791)!
|
||||
|
||||
> NOTE: Keycloakify 10 is still in realase-candidate state. [Follow progress](https://github.com/keycloakify/keycloakify/pull/538).
|
||||
> NOTE: Keycloak 24 introduces [important changes](https://www.keycloak.org/docs/latest/upgrading/index.html#changes-to-freemarker-templates-to-render-pages-based-on-the-user-profile-and-realm).
|
||||
> We're actively working on incorporating them into Keycloakify. [Follow progress](https://github.com/keycloakify/keycloakify/pull/538).
|
||||
|
||||
## Sponsor
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "keycloakify",
|
||||
"version": "10.0.0-rc.105",
|
||||
"version": "10.0.0-rc.90",
|
||||
"description": "Create Keycloak themes using React",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@ -15,6 +15,7 @@
|
||||
"test:types": "tsc -p test/tsconfig.json --noEmit",
|
||||
"_format": "prettier '**/*.{ts,tsx,json,md}'",
|
||||
"format": "yarn _format --write",
|
||||
"format:check": "yarn _format --list-different",
|
||||
"link-in-app": "tsx scripts/link-in-app.ts",
|
||||
"build-storybook": "tsx scripts/build-storybook.ts",
|
||||
"dump-keycloak-realm": "tsx scripts/dump-keycloak-realm.ts"
|
||||
@ -40,14 +41,14 @@
|
||||
"!dist/bin/",
|
||||
"dist/bin/main.js",
|
||||
"dist/bin/*.index.js",
|
||||
"dist/bin/*.node",
|
||||
"!dist/bin/shared/*.js",
|
||||
"dist/bin/shared/constants.js",
|
||||
"dist/bin/shared/*.d.ts",
|
||||
"dist/bin/shared/*.js.map",
|
||||
"!dist/vite-plugin/",
|
||||
"dist/vite-plugin/index.js",
|
||||
"dist/vite-plugin/index.d.ts",
|
||||
"dist/vite-plugin/vite-plugin.d.ts"
|
||||
"dist/vite-plugin/vite-plugin.d.ts",
|
||||
"dist/vite-plugin/index.js"
|
||||
],
|
||||
"keywords": [
|
||||
"keycloak",
|
||||
|
@ -16,7 +16,7 @@ if (fs.existsSync(join("dist", "bin", "main.original.js"))) {
|
||||
);
|
||||
|
||||
fs.readdirSync(join("dist", "bin")).forEach(fileBasename => {
|
||||
if (/[0-9]\.index.js/.test(fileBasename) || fileBasename.endsWith(".node")) {
|
||||
if (/[0-9]\.index.js/.test(fileBasename)) {
|
||||
fs.rmSync(join("dist", "bin", fileBasename));
|
||||
}
|
||||
});
|
||||
@ -111,10 +111,9 @@ run(
|
||||
)}`
|
||||
);
|
||||
|
||||
fs.readdirSync(join("dist", "ncc_out")).forEach(fileBasename => {
|
||||
assert(!fileBasename.endsWith(".index.js"));
|
||||
assert(!fileBasename.endsWith(".node"));
|
||||
});
|
||||
fs.readdirSync(join("dist", "ncc_out")).forEach(fileBasename =>
|
||||
assert(!fileBasename.endsWith(".index.js"))
|
||||
);
|
||||
|
||||
transformCodebase({
|
||||
srcDirPath: join("dist", "ncc_out"),
|
||||
|
@ -12,7 +12,6 @@ import { crawl } from "../src/bin/tools/crawl";
|
||||
import { downloadKeycloakDefaultTheme } from "../src/bin/shared/downloadKeycloakDefaultTheme";
|
||||
import { getThisCodebaseRootDirPath } from "../src/bin/tools/getThisCodebaseRootDirPath";
|
||||
import { deepAssign } from "../src/tools/deepAssign";
|
||||
import { getProxyFetchOptions } from "../src/bin/tools/fetchProxyOptions";
|
||||
|
||||
// NOTE: To run without argument when we want to generate src/i18n/generated_kcMessages files,
|
||||
// update the version array for generating for newer version.
|
||||
@ -34,9 +33,7 @@ async function main() {
|
||||
".cache",
|
||||
"keycloakify"
|
||||
),
|
||||
fetchOptions: getProxyFetchOptions({
|
||||
npmConfigGetCwd: thisCodebaseRootDirPath
|
||||
})
|
||||
npmWorkspaceRootDirPath: thisCodebaseRootDirPath
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -10,16 +10,14 @@ fs.rmSync(".yarn_home", { recursive: true, force: true });
|
||||
run("yarn install");
|
||||
run("yarn build");
|
||||
|
||||
const starterName = "keycloakify-starter";
|
||||
|
||||
fs.rmSync(join("..", starterName, "node_modules"), {
|
||||
fs.rmSync(join("..", "keycloakify-starter", "node_modules"), {
|
||||
recursive: true,
|
||||
force: true
|
||||
});
|
||||
|
||||
run("yarn install", { cwd: join("..", starterName) });
|
||||
run("yarn install", { cwd: join("..", "keycloakify-starter") });
|
||||
|
||||
run(`npx tsx ${join("scripts", "link-in-app.ts")} ${starterName}`);
|
||||
run(`npx tsx ${join("scripts", "link-in-app.ts")} keycloakify-starter`);
|
||||
|
||||
startRebuildOnSrcChange();
|
||||
|
||||
|
@ -145,12 +145,7 @@ export default function Template(props: TemplateProps<KcContext, I18n>) {
|
||||
<div className={clsx("alert", `alert-${message.type}`)}>
|
||||
{message.type === "success" && <span className="pficon pficon-ok"></span>}
|
||||
{message.type === "error" && <span className="pficon pficon-error-circle-o"></span>}
|
||||
<span
|
||||
className="kc-feedback-text"
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: message.summary
|
||||
}}
|
||||
/>
|
||||
<span className="kc-feedback-text">{message.summary}</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
|
@ -62,6 +62,7 @@ export default function Applications(props: PageProps<Extract<KcContext, { pageI
|
||||
{index < application.realmRolesAvailable.length - 1 && ", "}
|
||||
</span>
|
||||
))}
|
||||
{!isArrayWithEmptyObject(application.realmRolesAvailable) && application.resourceRolesAvailable && ", "}
|
||||
{application.resourceRolesAvailable &&
|
||||
Object.keys(application.resourceRolesAvailable).map(resource => (
|
||||
<span key={resource}>
|
||||
|
@ -154,14 +154,9 @@ export default function Totp(props: PageProps<Extract<KcContext, { pageId: "totp
|
||||
/>
|
||||
|
||||
{messagesPerField.existsError("totp") && (
|
||||
<span
|
||||
id="input-error-otp-code"
|
||||
className={kcClsx("kcInputErrorMessageClass")}
|
||||
aria-live="polite"
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: messagesPerField.get("totp")
|
||||
}}
|
||||
/>
|
||||
<span id="input-error-otp-code" className={kcClsx("kcInputErrorMessageClass")} aria-live="polite">
|
||||
{messagesPerField.get("totp")}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<input type="hidden" id="totpSecret" name="totpSecret" value={totp.totpSecret} />
|
||||
@ -185,14 +180,9 @@ export default function Totp(props: PageProps<Extract<KcContext, { pageId: "totp
|
||||
aria-invalid={messagesPerField.existsError("userLabel")}
|
||||
/>
|
||||
{messagesPerField.existsError("userLabel") && (
|
||||
<span
|
||||
id="input-error-otp-label"
|
||||
className={kcClsx("kcInputErrorMessageClass")}
|
||||
aria-live="polite"
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: messagesPerField.get("userLabel")
|
||||
}}
|
||||
/>
|
||||
<span id="input-error-otp-label" className={kcClsx("kcInputErrorMessageClass")} aria-live="polite">
|
||||
{messagesPerField.get("userLabel")}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
@ -81,8 +81,7 @@ export async function command(params: { cliCommandOptions: CliCommandOptions })
|
||||
)
|
||||
)
|
||||
.toString("utf8")
|
||||
.replace('import React from "react";\n', "")
|
||||
.replace(/from "[./]+dist\//, 'from "keycloakify/');
|
||||
.replace('import React from "react";\n', "");
|
||||
|
||||
{
|
||||
const targetDirPath = pathDirname(targetFilePath);
|
||||
|
@ -33,7 +33,6 @@ export async function buildJar(params: {
|
||||
keycloakAccountV1Version: KeycloakAccountV1Version;
|
||||
keycloakThemeAdditionalInfoExtensionVersion: KeycloakThemeAdditionalInfoExtensionVersion;
|
||||
resourcesDirPath: string;
|
||||
doesImplementAccountV1Theme: boolean;
|
||||
buildContext: BuildContextLike;
|
||||
}): Promise<void> {
|
||||
const {
|
||||
@ -41,7 +40,6 @@ export async function buildJar(params: {
|
||||
keycloakAccountV1Version,
|
||||
keycloakThemeAdditionalInfoExtensionVersion,
|
||||
resourcesDirPath,
|
||||
doesImplementAccountV1Theme,
|
||||
buildContext
|
||||
} = params;
|
||||
|
||||
@ -63,7 +61,7 @@ export async function buildJar(params: {
|
||||
srcDirPath: resourcesDirPath,
|
||||
destDirPath: tmpResourcesDirPath,
|
||||
transformSourceCode:
|
||||
!doesImplementAccountV1Theme || keycloakAccountV1Version !== null
|
||||
keycloakAccountV1Version !== null
|
||||
? undefined
|
||||
: (params: {
|
||||
fileRelativePath: string;
|
||||
@ -107,17 +105,7 @@ export async function buildJar(params: {
|
||||
}
|
||||
});
|
||||
|
||||
remove_account_v1_in_meta_inf: {
|
||||
if (!doesImplementAccountV1Theme) {
|
||||
// NOTE: We do not have account v1 anyway
|
||||
break remove_account_v1_in_meta_inf;
|
||||
}
|
||||
|
||||
if (keycloakAccountV1Version !== null) {
|
||||
// NOTE: No, we need to keep account-v1 in meta-inf
|
||||
break remove_account_v1_in_meta_inf;
|
||||
}
|
||||
|
||||
if (keycloakAccountV1Version === null) {
|
||||
writeMetaInfKeycloakThemes({
|
||||
resourcesDirPath: tmpResourcesDirPath,
|
||||
getNewMetaInfKeycloakTheme: ({ metaInfKeycloakTheme }) => {
|
||||
@ -147,7 +135,6 @@ export async function buildJar(params: {
|
||||
}
|
||||
})();
|
||||
|
||||
// TODO: Remove this optimization, it's a bit hacky.
|
||||
if (doBreak) {
|
||||
break route_legacy_pages;
|
||||
}
|
||||
@ -207,7 +194,7 @@ export async function buildJar(params: {
|
||||
|
||||
await new Promise<void>((resolve, reject) =>
|
||||
child_process.exec(
|
||||
`mvn clean install -Dmaven.repo.local="${pathJoin(keycloakifyBuildTmpDirPath, ".m2")}"`,
|
||||
`mvn clean install -Dmaven.repo.local=${pathJoin(keycloakifyBuildTmpDirPath, ".m2")}`,
|
||||
{ cwd: keycloakifyBuildTmpDirPath },
|
||||
error => {
|
||||
if (error !== null) {
|
||||
|
@ -12,7 +12,6 @@ export type BuildContextLike = BuildContextLike_buildJar & {
|
||||
keycloakifyBuildDirPath: string;
|
||||
recordIsImplementedByThemeType: BuildContext["recordIsImplementedByThemeType"];
|
||||
jarTargets: BuildContext["jarTargets"];
|
||||
doUseAccountV3: boolean;
|
||||
};
|
||||
|
||||
assert<BuildContext extends BuildContextLike ? true : false>();
|
||||
@ -23,9 +22,7 @@ export async function buildJars(params: {
|
||||
}): Promise<void> {
|
||||
const { resourcesDirPath, buildContext } = params;
|
||||
|
||||
const doesImplementAccountV1Theme =
|
||||
buildContext.recordIsImplementedByThemeType.account &&
|
||||
!buildContext.doUseAccountV3;
|
||||
const doesImplementAccountTheme = buildContext.recordIsImplementedByThemeType.account;
|
||||
|
||||
await Promise.all(
|
||||
keycloakAccountV1Versions
|
||||
@ -33,7 +30,7 @@ export async function buildJars(params: {
|
||||
keycloakThemeAdditionalInfoExtensionVersions.map(
|
||||
keycloakThemeAdditionalInfoExtensionVersion => {
|
||||
const keycloakVersionRange = getKeycloakVersionRangeForJar({
|
||||
doesImplementAccountV1Theme,
|
||||
doesImplementAccountTheme,
|
||||
keycloakAccountV1Version,
|
||||
keycloakThemeAdditionalInfoExtensionVersion
|
||||
});
|
||||
@ -58,7 +55,6 @@ export async function buildJars(params: {
|
||||
keycloakAccountV1Version,
|
||||
keycloakThemeAdditionalInfoExtensionVersion,
|
||||
resourcesDirPath,
|
||||
doesImplementAccountV1Theme,
|
||||
buildContext
|
||||
});
|
||||
}
|
||||
|
@ -6,17 +6,17 @@ import type {
|
||||
import type { KeycloakVersionRange } from "../../shared/KeycloakVersionRange";
|
||||
|
||||
export function getKeycloakVersionRangeForJar(params: {
|
||||
doesImplementAccountV1Theme: boolean;
|
||||
doesImplementAccountTheme: boolean;
|
||||
keycloakAccountV1Version: KeycloakAccountV1Version;
|
||||
keycloakThemeAdditionalInfoExtensionVersion: KeycloakThemeAdditionalInfoExtensionVersion;
|
||||
}): KeycloakVersionRange | undefined {
|
||||
const {
|
||||
keycloakAccountV1Version,
|
||||
keycloakThemeAdditionalInfoExtensionVersion,
|
||||
doesImplementAccountV1Theme
|
||||
doesImplementAccountTheme
|
||||
} = params;
|
||||
|
||||
if (doesImplementAccountV1Theme) {
|
||||
if (doesImplementAccountTheme) {
|
||||
const keycloakVersionRange = (() => {
|
||||
switch (keycloakAccountV1Version) {
|
||||
case null:
|
||||
@ -63,7 +63,7 @@ export function getKeycloakVersionRangeForJar(params: {
|
||||
assert<
|
||||
Equals<
|
||||
typeof keycloakVersionRange,
|
||||
KeycloakVersionRange.WithAccountV1Theme | undefined
|
||||
KeycloakVersionRange.WithAccountTheme | undefined
|
||||
>
|
||||
>();
|
||||
|
||||
@ -87,7 +87,7 @@ export function getKeycloakVersionRangeForJar(params: {
|
||||
assert<
|
||||
Equals<
|
||||
typeof keycloakVersionRange,
|
||||
KeycloakVersionRange.WithoutAccountV1Theme | undefined
|
||||
KeycloakVersionRange.WithoutAccountTheme | undefined
|
||||
>
|
||||
>();
|
||||
|
||||
|
@ -1,12 +1,6 @@
|
||||
import cheerio from "cheerio";
|
||||
import {
|
||||
replaceImportsInJsCode,
|
||||
BuildContextLike as BuildContextLike_replaceImportsInJsCode
|
||||
} from "../replacers/replaceImportsInJsCode";
|
||||
import {
|
||||
replaceImportsInCssCode,
|
||||
BuildContextLike as BuildContextLike_replaceImportsInCssCode
|
||||
} from "../replacers/replaceImportsInCssCode";
|
||||
import { replaceImportsInJsCode } from "../replacers/replaceImportsInJsCode";
|
||||
import { replaceImportsInCssCode } from "../replacers/replaceImportsInCssCode";
|
||||
import * as fs from "fs";
|
||||
import { join as pathJoin } from "path";
|
||||
import type { BuildContext } from "../../shared/buildContext";
|
||||
@ -18,12 +12,14 @@ import {
|
||||
} from "../../shared/constants";
|
||||
import { getThisCodebaseRootDirPath } from "../../tools/getThisCodebaseRootDirPath";
|
||||
|
||||
export type BuildContextLike = BuildContextLike_replaceImportsInJsCode &
|
||||
BuildContextLike_replaceImportsInCssCode & {
|
||||
urlPathname: string | undefined;
|
||||
themeVersion: string;
|
||||
kcContextExclusionsFtlCode: string | undefined;
|
||||
};
|
||||
export type BuildContextLike = {
|
||||
bundler: "vite" | "webpack";
|
||||
themeVersion: string;
|
||||
urlPathname: string | undefined;
|
||||
projectBuildDirPath: string;
|
||||
assetsDirPath: string;
|
||||
kcContextExclusionsFtlCode: string | undefined;
|
||||
};
|
||||
|
||||
assert<BuildContext extends BuildContextLike ? true : false>();
|
||||
|
||||
@ -34,7 +30,6 @@ export function generateFtlFilesCodeFactory(params: {
|
||||
keycloakifyVersion: string;
|
||||
themeType: ThemeType;
|
||||
fieldNames: string[];
|
||||
isAccountV3: boolean;
|
||||
}) {
|
||||
const {
|
||||
themeName,
|
||||
@ -42,8 +37,7 @@ export function generateFtlFilesCodeFactory(params: {
|
||||
buildContext,
|
||||
keycloakifyVersion,
|
||||
themeType,
|
||||
fieldNames,
|
||||
isAccountV3
|
||||
fieldNames
|
||||
} = params;
|
||||
|
||||
const $ = cheerio.load(indexHtmlCode);
|
||||
@ -70,8 +64,7 @@ export function generateFtlFilesCodeFactory(params: {
|
||||
const { fixedCssCode } = replaceImportsInCssCode({
|
||||
cssCode,
|
||||
cssFileRelativeDirPath: undefined,
|
||||
buildContext,
|
||||
isAccountV3
|
||||
buildContext
|
||||
});
|
||||
|
||||
$(element).text(fixedCssCode);
|
||||
@ -96,7 +89,7 @@ export function generateFtlFilesCodeFactory(params: {
|
||||
new RegExp(
|
||||
`^${(buildContext.urlPathname ?? "/").replace(/\//g, "\\/")}`
|
||||
),
|
||||
`\${${!isAccountV3 ? "url.resourcesPath" : "resourceUrl"}}/${basenameOfTheKeycloakifyResourcesDir}/`
|
||||
`\${url.resourcesPath}/${basenameOfTheKeycloakifyResourcesDir}/`
|
||||
)
|
||||
);
|
||||
})
|
||||
|
@ -1,5 +1,4 @@
|
||||
<#assign pageId="PAGE_ID_xIgLsPgGId9D8e">
|
||||
<#assign themeType="KEYCLOAKIFY_THEME_TYPE_dExKd3xEdr">
|
||||
const kcContext = ${ftl_object_to_js_code_declaring_an_object(.data_model, [])?no_esc};
|
||||
if( kcContext.messagesPerField ){
|
||||
var existsError_singleFieldName = kcContext.messagesPerField.existsError;
|
||||
@ -28,7 +27,7 @@ if( kcContext.messagesPerField ){
|
||||
}
|
||||
kcContext.keycloakifyVersion = "KEYCLOAKIFY_VERSION_xEdKd3xEdr";
|
||||
kcContext.themeVersion = "KEYCLOAKIFY_THEME_VERSION_sIgKd3xEdr3dx";
|
||||
kcContext.themeType = "${themeType}";
|
||||
kcContext.themeType = "KEYCLOAKIFY_THEME_TYPE_dExKd3xEdr";
|
||||
kcContext.themeName = "KEYCLOAKIFY_THEME_NAME_cXxKd3xEer";
|
||||
kcContext.pageId = "${pageId}";
|
||||
if( kcContext.url && kcContext.url.resourcesPath ){
|
||||
|
@ -4,8 +4,7 @@ import {
|
||||
join as pathJoin,
|
||||
resolve as pathResolve,
|
||||
relative as pathRelative,
|
||||
dirname as pathDirname,
|
||||
basename as pathBasename
|
||||
dirname as pathDirname
|
||||
} from "path";
|
||||
import { replaceImportsInJsCode } from "../replacers/replaceImportsInJsCode";
|
||||
import { replaceImportsInCssCode } from "../replacers/replaceImportsInCssCode";
|
||||
@ -43,7 +42,6 @@ import {
|
||||
} from "../../shared/metaInfKeycloakThemes";
|
||||
import { objectEntries } from "tsafe/objectEntries";
|
||||
import { escapeStringForPropertiesFile } from "../../tools/escapeStringForPropertiesFile";
|
||||
import { downloadAndExtractArchive } from "../../tools/downloadAndExtractArchive";
|
||||
|
||||
export type BuildContextLike = BuildContextLike_kcContextExclusionsFtlCode &
|
||||
BuildContextLike_downloadKeycloakStaticResources &
|
||||
@ -55,8 +53,6 @@ export type BuildContextLike = BuildContextLike_kcContextExclusionsFtlCode &
|
||||
environmentVariables: { name: string; default: string }[];
|
||||
recordIsImplementedByThemeType: BuildContext["recordIsImplementedByThemeType"];
|
||||
themeSrcDirPath: string;
|
||||
bundler: { type: "vite" } | { type: "webpack" };
|
||||
doUseAccountV3: boolean;
|
||||
};
|
||||
|
||||
assert<BuildContext extends BuildContextLike ? true : false>();
|
||||
@ -74,7 +70,6 @@ export async function generateResourcesForMainTheme(params: {
|
||||
};
|
||||
|
||||
for (const themeType of ["login", "account"] as const) {
|
||||
const isAccountV3 = themeType === "account" && buildContext.doUseAccountV3;
|
||||
if (!buildContext.recordIsImplementedByThemeType[themeType]) {
|
||||
continue;
|
||||
}
|
||||
@ -118,7 +113,7 @@ export async function generateResourcesForMainTheme(params: {
|
||||
);
|
||||
|
||||
if (fs.existsSync(dirPath)) {
|
||||
assert(buildContext.bundler.type === "webpack");
|
||||
assert(buildContext.bundler === "webpack");
|
||||
|
||||
throw new Error(
|
||||
[
|
||||
@ -140,8 +135,7 @@ export async function generateResourcesForMainTheme(params: {
|
||||
const { fixedCssCode } = replaceImportsInCssCode({
|
||||
cssCode: sourceCode.toString("utf8"),
|
||||
cssFileRelativeDirPath: pathDirname(fileRelativePath),
|
||||
buildContext,
|
||||
isAccountV3
|
||||
buildContext
|
||||
});
|
||||
|
||||
return {
|
||||
@ -176,8 +170,7 @@ export async function generateResourcesForMainTheme(params: {
|
||||
fieldNames: readFieldNameUsage({
|
||||
themeSrcDirPath: buildContext.themeSrcDirPath,
|
||||
themeType
|
||||
}),
|
||||
isAccountV3
|
||||
})
|
||||
});
|
||||
|
||||
[
|
||||
@ -186,15 +179,13 @@ export async function generateResourcesForMainTheme(params: {
|
||||
case "login":
|
||||
return loginThemePageIds;
|
||||
case "account":
|
||||
return isAccountV3 ? ["index.ftl"] : accountThemePageIds;
|
||||
return accountThemePageIds;
|
||||
}
|
||||
})(),
|
||||
...(isAccountV3
|
||||
? []
|
||||
: readExtraPagesNames({
|
||||
themeType,
|
||||
themeSrcDirPath: buildContext.themeSrcDirPath
|
||||
}))
|
||||
...readExtraPagesNames({
|
||||
themeType,
|
||||
themeSrcDirPath: buildContext.themeSrcDirPath
|
||||
})
|
||||
].forEach(pageId => {
|
||||
const { ftlCode } = generateFtlFilesCode({ pageId });
|
||||
|
||||
@ -204,52 +195,40 @@ export async function generateResourcesForMainTheme(params: {
|
||||
);
|
||||
});
|
||||
|
||||
i18n_messages_generation: {
|
||||
if (isAccountV3) {
|
||||
break i18n_messages_generation;
|
||||
}
|
||||
generateMessageProperties({
|
||||
themeSrcDirPath: buildContext.themeSrcDirPath,
|
||||
themeType
|
||||
}).forEach(({ languageTag, propertiesFileSource }) => {
|
||||
const messagesDirPath = pathJoin(themeTypeDirPath, "messages");
|
||||
|
||||
generateMessageProperties({
|
||||
themeSrcDirPath: buildContext.themeSrcDirPath,
|
||||
themeType
|
||||
}).forEach(({ languageTag, propertiesFileSource }) => {
|
||||
const messagesDirPath = pathJoin(themeTypeDirPath, "messages");
|
||||
|
||||
fs.mkdirSync(pathJoin(themeTypeDirPath, "messages"), {
|
||||
recursive: true
|
||||
});
|
||||
|
||||
const propertiesFilePath = pathJoin(
|
||||
messagesDirPath,
|
||||
`messages_${languageTag}.properties`
|
||||
);
|
||||
|
||||
fs.writeFileSync(
|
||||
propertiesFilePath,
|
||||
Buffer.from(propertiesFileSource, "utf8")
|
||||
);
|
||||
fs.mkdirSync(pathJoin(themeTypeDirPath, "messages"), {
|
||||
recursive: true
|
||||
});
|
||||
}
|
||||
|
||||
keycloak_static_resources: {
|
||||
if (isAccountV3) {
|
||||
break keycloak_static_resources;
|
||||
}
|
||||
const propertiesFilePath = pathJoin(
|
||||
messagesDirPath,
|
||||
`messages_${languageTag}.properties`
|
||||
);
|
||||
|
||||
await downloadKeycloakStaticResources({
|
||||
keycloakVersion: (() => {
|
||||
switch (themeType) {
|
||||
case "account":
|
||||
return lastKeycloakVersionWithAccountV1;
|
||||
case "login":
|
||||
return buildContext.loginThemeResourcesFromKeycloakVersion;
|
||||
}
|
||||
})(),
|
||||
themeDirPath: pathResolve(pathJoin(themeTypeDirPath, "..")),
|
||||
themeType,
|
||||
buildContext
|
||||
});
|
||||
}
|
||||
fs.writeFileSync(
|
||||
propertiesFilePath,
|
||||
Buffer.from(propertiesFileSource, "utf8")
|
||||
);
|
||||
});
|
||||
|
||||
await downloadKeycloakStaticResources({
|
||||
keycloakVersion: (() => {
|
||||
switch (themeType) {
|
||||
case "account":
|
||||
return lastKeycloakVersionWithAccountV1;
|
||||
case "login":
|
||||
return buildContext.loginThemeResourcesFromKeycloakVersion;
|
||||
}
|
||||
})(),
|
||||
themeDirPath: pathResolve(pathJoin(themeTypeDirPath, "..")),
|
||||
themeType,
|
||||
buildContext
|
||||
});
|
||||
|
||||
fs.writeFileSync(
|
||||
pathJoin(themeTypeDirPath, "theme.properties"),
|
||||
@ -258,13 +237,12 @@ export async function generateResourcesForMainTheme(params: {
|
||||
`parent=${(() => {
|
||||
switch (themeType) {
|
||||
case "account":
|
||||
return isAccountV3 ? "base" : accountV1ThemeName;
|
||||
return accountV1ThemeName;
|
||||
case "login":
|
||||
return "keycloak";
|
||||
}
|
||||
assert<Equals<typeof themeType, never>>(false);
|
||||
})()}`,
|
||||
...(isAccountV3 ? ["deprecatedMode=false"] : []),
|
||||
...(buildContext.extraThemeProperties ?? []),
|
||||
...buildContext.environmentVariables.map(
|
||||
({ name, default: defaultValue }) =>
|
||||
@ -289,54 +267,13 @@ export async function generateResourcesForMainTheme(params: {
|
||||
});
|
||||
}
|
||||
|
||||
bring_in_account_v1: {
|
||||
if (buildContext.doUseAccountV3) {
|
||||
break bring_in_account_v1;
|
||||
}
|
||||
|
||||
if (!buildContext.recordIsImplementedByThemeType.account) {
|
||||
break bring_in_account_v1;
|
||||
}
|
||||
|
||||
if (buildContext.recordIsImplementedByThemeType.account) {
|
||||
await bringInAccountV1({
|
||||
resourcesDirPath,
|
||||
buildContext
|
||||
});
|
||||
}
|
||||
|
||||
bring_in_account_v3_i18n_messages: {
|
||||
if (!buildContext.doUseAccountV3) {
|
||||
break bring_in_account_v3_i18n_messages;
|
||||
}
|
||||
|
||||
const { extractedDirPath } = await downloadAndExtractArchive({
|
||||
url: "https://repo1.maven.org/maven2/org/keycloak/keycloak-account-ui/25.0.1/keycloak-account-ui-25.0.1.jar",
|
||||
cacheDirPath: buildContext.cacheDirPath,
|
||||
fetchOptions: buildContext.fetchOptions,
|
||||
uniqueIdOfOnArchiveFile: "bring_in_account_v3_i18n_messages",
|
||||
onArchiveFile: async ({ fileRelativePath, writeFile }) => {
|
||||
if (
|
||||
!fileRelativePath.startsWith(
|
||||
pathJoin("theme", "keycloak.v3", "account", "messages")
|
||||
)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
await writeFile({
|
||||
fileRelativePath: pathBasename(fileRelativePath)
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
transformCodebase({
|
||||
srcDirPath: extractedDirPath,
|
||||
destDirPath: pathJoin(
|
||||
getThemeTypeDirPath({ themeType: "account" }),
|
||||
"messages"
|
||||
)
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
const metaInfKeycloakThemes: MetaInfKeycloakTheme = { themes: [] };
|
||||
|
||||
|
@ -34,7 +34,10 @@ export function readExtraPagesNames(params: {
|
||||
const rawSourceFile = fs.readFileSync(candidateFilPath).toString("utf8");
|
||||
|
||||
extraPages.push(
|
||||
...Array.from(rawSourceFile.matchAll(/["']([^.\s]+.ftl)["']:/g), m => m[1])
|
||||
...Array.from(
|
||||
rawSourceFile.matchAll(/["']?pageId["']?\s*:\s*["']([^.]+.ftl)["']/g),
|
||||
m => m[1]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,12 @@ import * as os from "os";
|
||||
import { rmSync } from "../tools/fs.rmSync";
|
||||
|
||||
export async function command(params: { cliCommandOptions: CliCommandOptions }) {
|
||||
console.log("DEBUG:", {
|
||||
__filename,
|
||||
__dirname,
|
||||
"process.cwd()": process.cwd()
|
||||
});
|
||||
|
||||
exit_if_maven_not_installed: {
|
||||
let commandOutput: Buffer | undefined = undefined;
|
||||
|
||||
@ -85,7 +91,7 @@ export async function command(params: { cliCommandOptions: CliCommandOptions })
|
||||
});
|
||||
|
||||
run_post_build_script: {
|
||||
if (buildContext.bundler.type !== "vite") {
|
||||
if (buildContext.bundler !== "vite") {
|
||||
break run_post_build_script;
|
||||
}
|
||||
|
||||
|
@ -12,12 +12,11 @@ assert<BuildContext extends BuildContextLike ? true : false>();
|
||||
export function replaceImportsInCssCode(params: {
|
||||
cssCode: string;
|
||||
cssFileRelativeDirPath: string | undefined;
|
||||
isAccountV3: boolean;
|
||||
buildContext: BuildContextLike;
|
||||
}): {
|
||||
fixedCssCode: string;
|
||||
} {
|
||||
const { cssCode, cssFileRelativeDirPath, buildContext, isAccountV3 } = params;
|
||||
const { cssCode, cssFileRelativeDirPath, buildContext } = params;
|
||||
|
||||
const fixedCssCode = cssCode.replace(
|
||||
/url\(["']?(\/[^/][^)"']+)["']?\)/g,
|
||||
@ -38,7 +37,7 @@ export function replaceImportsInCssCode(params: {
|
||||
break inline_style_in_html;
|
||||
}
|
||||
|
||||
return `url(\${${!isAccountV3 ? "url.resourcesPath" : "resourceUrl"}}/${basenameOfTheKeycloakifyResourcesDir}${assetFileAbsoluteUrlPathname})`;
|
||||
return `url(\${url.resourcesPath}/${basenameOfTheKeycloakifyResourcesDir}${assetFileAbsoluteUrlPathname})`;
|
||||
}
|
||||
|
||||
const assetFileRelativeUrlPathname = posix.relative(
|
||||
|
@ -8,7 +8,7 @@ export type BuildContextLike = {
|
||||
projectBuildDirPath: string;
|
||||
assetsDirPath: string;
|
||||
urlPathname: string | undefined;
|
||||
bundler: { type: "vite" } | { type: "webpack" };
|
||||
bundler: "vite" | "webpack";
|
||||
};
|
||||
|
||||
assert<BuildContext extends BuildContextLike ? true : false>();
|
||||
@ -20,7 +20,7 @@ export function replaceImportsInJsCode(params: {
|
||||
const { jsCode, buildContext } = params;
|
||||
|
||||
const { fixedJsCode } = (() => {
|
||||
switch (buildContext.bundler.type) {
|
||||
switch (buildContext.bundler) {
|
||||
case "vite":
|
||||
return replaceImportsInJsCode_vite({
|
||||
jsCode,
|
||||
|
@ -3,14 +3,11 @@
|
||||
import { termost } from "termost";
|
||||
import { readThisNpmPackageVersion } from "./tools/readThisNpmPackageVersion";
|
||||
import * as child_process from "child_process";
|
||||
import { assertNoPnpmDlx } from "./tools/assertNoPnpmDlx";
|
||||
|
||||
export type CliCommandOptions = {
|
||||
projectDirPath: string | undefined;
|
||||
};
|
||||
|
||||
assertNoPnpmDlx();
|
||||
|
||||
const program = termost<CliCommandOptions>(
|
||||
{
|
||||
name: "keycloakify",
|
||||
|
@ -1,9 +1,9 @@
|
||||
export type KeycloakVersionRange =
|
||||
| KeycloakVersionRange.WithAccountV1Theme
|
||||
| KeycloakVersionRange.WithoutAccountV1Theme;
|
||||
| KeycloakVersionRange.WithAccountTheme
|
||||
| KeycloakVersionRange.WithoutAccountTheme;
|
||||
|
||||
export namespace KeycloakVersionRange {
|
||||
export type WithoutAccountV1Theme = "21-and-below" | "22-and-above";
|
||||
export type WithoutAccountTheme = "21-and-below" | "22-and-above";
|
||||
|
||||
export type WithAccountV1Theme = "21-and-below" | "23" | "24" | "25-and-above";
|
||||
export type WithAccountTheme = "21-and-below" | "23" | "24" | "25-and-above";
|
||||
}
|
||||
|
@ -1,12 +1,7 @@
|
||||
import { parse as urlParse } from "url";
|
||||
import {
|
||||
join as pathJoin,
|
||||
sep as pathSep,
|
||||
relative as pathRelative,
|
||||
resolve as pathResolve,
|
||||
dirname as pathDirname
|
||||
} from "path";
|
||||
import { join as pathJoin } from "path";
|
||||
import { getAbsoluteAndInOsFormatPath } from "../tools/getAbsoluteAndInOsFormatPath";
|
||||
import { getNpmWorkspaceRootDirPath } from "../tools/getNpmWorkspaceRootDirPath";
|
||||
import type { CliCommandOptions } from "../main";
|
||||
import { z } from "zod";
|
||||
import * as fs from "fs";
|
||||
@ -26,9 +21,9 @@ import { type ThemeType } from "./constants";
|
||||
import { id } from "tsafe/id";
|
||||
import { symToStr } from "tsafe/symToStr";
|
||||
import chalk from "chalk";
|
||||
import { getProxyFetchOptions, type ProxyFetchOptions } from "../tools/fetchProxyOptions";
|
||||
|
||||
export type BuildContext = {
|
||||
bundler: "vite" | "webpack";
|
||||
themeVersion: string;
|
||||
themeNames: [string, ...string[]];
|
||||
extraThemeProperties: string[] | undefined;
|
||||
@ -45,7 +40,7 @@ export type BuildContext = {
|
||||
* In this case the urlPathname will be "/my-app/" */
|
||||
urlPathname: string | undefined;
|
||||
assetsDirPath: string;
|
||||
fetchOptions: ProxyFetchOptions;
|
||||
npmWorkspaceRootDirPath: string;
|
||||
kcContextExclusionsFtlCode: string | undefined;
|
||||
environmentVariables: { name: string; default: string }[];
|
||||
themeSrcDirPath: string;
|
||||
@ -54,16 +49,6 @@ export type BuildContext = {
|
||||
keycloakVersionRange: KeycloakVersionRange;
|
||||
jarFileBasename: string;
|
||||
}[];
|
||||
bundler:
|
||||
| {
|
||||
type: "vite";
|
||||
}
|
||||
| {
|
||||
type: "webpack";
|
||||
packageJsonDirPath: string;
|
||||
packageJsonScripts: Record<string, string>;
|
||||
};
|
||||
doUseAccountV3: boolean;
|
||||
};
|
||||
|
||||
export type BuildOptions = {
|
||||
@ -78,17 +63,16 @@ export type BuildOptions = {
|
||||
kcContextExclusionsFtl?: string;
|
||||
/** https://docs.keycloakify.dev/v/v10/targetting-specific-keycloak-versions */
|
||||
keycloakVersionTargets?: BuildOptions.KeycloakVersionTargets;
|
||||
doUseAccountV3?: boolean;
|
||||
};
|
||||
|
||||
export namespace BuildOptions {
|
||||
export type KeycloakVersionTargets =
|
||||
| ({ hasAccountTheme: true } & Record<
|
||||
KeycloakVersionRange.WithAccountV1Theme,
|
||||
KeycloakVersionRange.WithAccountTheme,
|
||||
string | boolean
|
||||
>)
|
||||
| ({ hasAccountTheme: false } & Record<
|
||||
KeycloakVersionRange.WithoutAccountV1Theme,
|
||||
KeycloakVersionRange.WithoutAccountTheme,
|
||||
string | boolean
|
||||
>);
|
||||
}
|
||||
@ -106,56 +90,21 @@ export function getBuildContext(params: {
|
||||
}): BuildContext {
|
||||
const { cliCommandOptions } = params;
|
||||
|
||||
const projectDirPath =
|
||||
cliCommandOptions.projectDirPath !== undefined
|
||||
? getAbsoluteAndInOsFormatPath({
|
||||
pathIsh: cliCommandOptions.projectDirPath,
|
||||
cwd: process.cwd()
|
||||
})
|
||||
: process.cwd();
|
||||
console.log("DEBUG:", { cliCommandOptions });
|
||||
|
||||
const { themeSrcDirPath } = (() => {
|
||||
const srcDirPath = pathJoin(projectDirPath, "src");
|
||||
|
||||
const themeSrcDirPath: string | undefined = crawl({
|
||||
dirPath: srcDirPath,
|
||||
returnedPathsType: "relative to dirPath"
|
||||
})
|
||||
.map(fileRelativePath => {
|
||||
for (const themeSrcDirBasename of ["keycloak-theme", "keycloak_theme"]) {
|
||||
const split = fileRelativePath.split(themeSrcDirBasename);
|
||||
if (split.length === 2) {
|
||||
return pathJoin(srcDirPath, split[0] + themeSrcDirBasename);
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
})
|
||||
.filter(exclude(undefined))[0];
|
||||
|
||||
if (themeSrcDirPath !== undefined) {
|
||||
return { themeSrcDirPath };
|
||||
const projectDirPath = (() => {
|
||||
if (cliCommandOptions.projectDirPath === undefined) {
|
||||
return process.cwd();
|
||||
}
|
||||
|
||||
for (const themeType of [...themeTypes, "email"]) {
|
||||
if (!fs.existsSync(pathJoin(srcDirPath, themeType))) {
|
||||
continue;
|
||||
}
|
||||
return { themeSrcDirPath: srcDirPath };
|
||||
}
|
||||
|
||||
console.log(
|
||||
chalk.red(
|
||||
[
|
||||
`Can't locate your Keycloak theme source directory in .${pathSep}${pathRelative(process.cwd(), srcDirPath)}`,
|
||||
`Make sure to either use the Keycloakify CLI in the root of your Keycloakify project or use the --project CLI option`,
|
||||
`If you are collocating your Keycloak theme with your app you must have a directory named 'keycloak-theme' or 'keycloak_theme' in your 'src' directory`
|
||||
].join("\n")
|
||||
)
|
||||
);
|
||||
|
||||
process.exit(1);
|
||||
return getAbsoluteAndInOsFormatPath({
|
||||
pathIsh: cliCommandOptions.projectDirPath,
|
||||
cwd: process.cwd()
|
||||
});
|
||||
})();
|
||||
|
||||
console.log("DEBUG:", { projectDirPath });
|
||||
|
||||
const { resolvedViteConfig } = (() => {
|
||||
if (
|
||||
fs
|
||||
@ -190,59 +139,24 @@ export function getBuildContext(params: {
|
||||
return { resolvedViteConfig };
|
||||
})();
|
||||
|
||||
const packageJsonFilePath = (function getPackageJSonDirPath(upCount: number): string {
|
||||
const dirPath = pathResolve(
|
||||
pathJoin(...[projectDirPath, ...Array(upCount).fill("..")])
|
||||
);
|
||||
|
||||
assert(dirPath !== pathSep, "Root package.json not found");
|
||||
|
||||
success: {
|
||||
const packageJsonFilePath = pathJoin(dirPath, "package.json");
|
||||
|
||||
if (!fs.existsSync(packageJsonFilePath)) {
|
||||
break success;
|
||||
}
|
||||
|
||||
const parsedPackageJson = z
|
||||
.object({
|
||||
name: z.string().optional(),
|
||||
dependencies: z.record(z.string()).optional(),
|
||||
devDependencies: z.record(z.string()).optional()
|
||||
})
|
||||
.parse(JSON.parse(fs.readFileSync(packageJsonFilePath).toString("utf8")));
|
||||
|
||||
if (
|
||||
parsedPackageJson.dependencies?.keycloakify === undefined &&
|
||||
parsedPackageJson.devDependencies?.keycloakify === undefined &&
|
||||
parsedPackageJson.name !== "keycloakify" // NOTE: For local storybook build
|
||||
) {
|
||||
break success;
|
||||
}
|
||||
|
||||
return packageJsonFilePath;
|
||||
}
|
||||
|
||||
return getPackageJSonDirPath(upCount + 1);
|
||||
})(0);
|
||||
console.log("DEBUG:", { resolvedViteConfig });
|
||||
|
||||
const parsedPackageJson = (() => {
|
||||
type BuildOptions_packageJson = BuildOptions & {
|
||||
projectBuildDirPath?: string;
|
||||
staticDirPathInProjectBuildDirPath?: string;
|
||||
publicDirPath?: string;
|
||||
doUseAccountV3?: boolean;
|
||||
};
|
||||
|
||||
type ParsedPackageJson = {
|
||||
name?: string;
|
||||
name: string;
|
||||
version?: string;
|
||||
homepage?: string;
|
||||
keycloakify?: BuildOptions_packageJson;
|
||||
};
|
||||
|
||||
const zParsedPackageJson = z.object({
|
||||
name: z.string().optional(),
|
||||
name: z.string(),
|
||||
version: z.string().optional(),
|
||||
homepage: z.string().optional(),
|
||||
keycloakify: id<z.ZodType<BuildOptions_packageJson>>(
|
||||
@ -300,8 +214,7 @@ export function getBuildContext(params: {
|
||||
|
||||
return zKeycloakVersionTargets;
|
||||
})()
|
||||
).optional(),
|
||||
doUseAccountV3: z.boolean().optional()
|
||||
).optional()
|
||||
});
|
||||
|
||||
{
|
||||
@ -321,24 +234,63 @@ export function getBuildContext(params: {
|
||||
assert<Equals<Got, Expected>>();
|
||||
}
|
||||
|
||||
const configurationPackageJsonFilePath = (() => {
|
||||
const rootPackageJsonFilePath = pathJoin(projectDirPath, "package.json");
|
||||
|
||||
return fs.existsSync(rootPackageJsonFilePath)
|
||||
? rootPackageJsonFilePath
|
||||
: packageJsonFilePath;
|
||||
})();
|
||||
|
||||
return zParsedPackageJson.parse(
|
||||
JSON.parse(fs.readFileSync(configurationPackageJsonFilePath).toString("utf8"))
|
||||
JSON.parse(
|
||||
fs.readFileSync(pathJoin(projectDirPath, "package.json")).toString("utf8")
|
||||
)
|
||||
);
|
||||
})();
|
||||
|
||||
console.log("DEBUG:", { parsedPackageJson });
|
||||
|
||||
const buildOptions = {
|
||||
...parsedPackageJson.keycloakify,
|
||||
...resolvedViteConfig?.buildOptions
|
||||
};
|
||||
|
||||
console.log("DEBUG:", { buildOptions });
|
||||
|
||||
const { themeSrcDirPath } = (() => {
|
||||
const srcDirPath = pathJoin(projectDirPath, "src");
|
||||
|
||||
const themeSrcDirPath: string | undefined = crawl({
|
||||
dirPath: srcDirPath,
|
||||
returnedPathsType: "relative to dirPath"
|
||||
})
|
||||
.map(fileRelativePath => {
|
||||
for (const themeSrcDirBasename of ["keycloak-theme", "keycloak_theme"]) {
|
||||
const split = fileRelativePath.split(themeSrcDirBasename);
|
||||
if (split.length === 2) {
|
||||
return pathJoin(srcDirPath, split[0] + themeSrcDirBasename);
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
})
|
||||
.filter(exclude(undefined))[0];
|
||||
|
||||
if (themeSrcDirPath !== undefined) {
|
||||
return { themeSrcDirPath };
|
||||
}
|
||||
|
||||
for (const themeType of [...themeTypes, "email"]) {
|
||||
if (!fs.existsSync(pathJoin(srcDirPath, themeType))) {
|
||||
continue;
|
||||
}
|
||||
return { themeSrcDirPath: srcDirPath };
|
||||
}
|
||||
|
||||
console.log(
|
||||
chalk.red(
|
||||
[
|
||||
"Can't locate your keycloak theme source directory.",
|
||||
"See: https://docs.keycloakify.dev/v/v10/keycloakify-in-my-app/collocation"
|
||||
].join("\n")
|
||||
)
|
||||
);
|
||||
|
||||
process.exit(1);
|
||||
})();
|
||||
|
||||
const recordIsImplementedByThemeType = objectFromEntries(
|
||||
(["login", "account", "email"] as const).map(themeType => [
|
||||
themeType,
|
||||
@ -346,16 +298,16 @@ export function getBuildContext(params: {
|
||||
])
|
||||
);
|
||||
|
||||
console.log("DEBUG:", { themeSrcDirPath });
|
||||
|
||||
const themeNames = ((): [string, ...string[]] => {
|
||||
if (buildOptions.themeName === undefined) {
|
||||
return parsedPackageJson.name === undefined
|
||||
? ["keycloakify"]
|
||||
: [
|
||||
parsedPackageJson.name
|
||||
.replace(/^@(.*)/, "$1")
|
||||
.split("/")
|
||||
.join("-")
|
||||
];
|
||||
return [
|
||||
parsedPackageJson.name
|
||||
.replace(/^@(.*)/, "$1")
|
||||
.split("/")
|
||||
.join("-")
|
||||
];
|
||||
}
|
||||
|
||||
if (typeof buildOptions.themeName === "string") {
|
||||
@ -369,6 +321,8 @@ export function getBuildContext(params: {
|
||||
return [mainThemeName, ...themeVariantNames];
|
||||
})();
|
||||
|
||||
console.log("DEBUG:", { themeNames });
|
||||
|
||||
const projectBuildDirPath = (() => {
|
||||
webpack: {
|
||||
if (resolvedViteConfig !== undefined) {
|
||||
@ -388,31 +342,19 @@ export function getBuildContext(params: {
|
||||
return pathJoin(projectDirPath, resolvedViteConfig.buildDir);
|
||||
})();
|
||||
|
||||
console.log("DEBUG:", { projectBuildDirPath });
|
||||
|
||||
const { npmWorkspaceRootDirPath } = getNpmWorkspaceRootDirPath({
|
||||
projectDirPath,
|
||||
dependencyExpected: "keycloakify"
|
||||
});
|
||||
|
||||
console.log("DEBUG:", { npmWorkspaceRootDirPath });
|
||||
|
||||
const bundler = resolvedViteConfig !== undefined ? "vite" : "webpack";
|
||||
|
||||
const doUseAccountV3 = buildOptions.doUseAccountV3 ?? false;
|
||||
|
||||
return {
|
||||
bundler:
|
||||
resolvedViteConfig !== undefined
|
||||
? { type: "vite" }
|
||||
: (() => {
|
||||
const { scripts } = z
|
||||
.object({
|
||||
scripts: z.record(z.string()).optional()
|
||||
})
|
||||
.parse(
|
||||
JSON.parse(
|
||||
fs.readFileSync(packageJsonFilePath).toString("utf8")
|
||||
)
|
||||
);
|
||||
|
||||
return {
|
||||
type: "webpack",
|
||||
packageJsonDirPath: pathDirname(packageJsonFilePath),
|
||||
packageJsonScripts: scripts ?? {}
|
||||
};
|
||||
})(),
|
||||
const buildContext: BuildContext = {
|
||||
bundler,
|
||||
themeVersion: buildOptions.themeVersion ?? parsedPackageJson.version ?? "0.0.0",
|
||||
themeNames,
|
||||
extraThemeProperties: buildOptions.extraThemeProperties,
|
||||
@ -489,11 +431,7 @@ export function getBuildContext(params: {
|
||||
});
|
||||
}
|
||||
|
||||
return pathJoin(
|
||||
pathDirname(packageJsonFilePath),
|
||||
"node_modules",
|
||||
".cache"
|
||||
);
|
||||
return pathJoin(npmWorkspaceRootDirPath, "node_modules", ".cache");
|
||||
})(),
|
||||
"keycloakify"
|
||||
);
|
||||
@ -542,6 +480,7 @@ export function getBuildContext(params: {
|
||||
|
||||
return pathJoin(projectBuildDirPath, resolvedViteConfig.assetsDir);
|
||||
})(),
|
||||
npmWorkspaceRootDirPath,
|
||||
kcContextExclusionsFtlCode: (() => {
|
||||
if (buildOptions.kcContextExclusionsFtl === undefined) {
|
||||
return undefined;
|
||||
@ -561,33 +500,6 @@ export function getBuildContext(params: {
|
||||
environmentVariables: buildOptions.environmentVariables ?? [],
|
||||
recordIsImplementedByThemeType,
|
||||
themeSrcDirPath,
|
||||
fetchOptions: getProxyFetchOptions({
|
||||
npmConfigGetCwd: (function callee(upCount: number): string {
|
||||
const dirPath = pathResolve(
|
||||
pathJoin(...[projectDirPath, ...Array(upCount).fill("..")])
|
||||
);
|
||||
|
||||
assert(
|
||||
dirPath !== pathSep,
|
||||
"Couldn't find a place to run 'npm config get'"
|
||||
);
|
||||
|
||||
try {
|
||||
child_process.execSync("npm config get", {
|
||||
cwd: dirPath,
|
||||
stdio: "ignore"
|
||||
});
|
||||
} catch (error) {
|
||||
if (String(error).includes("ENOWORKSPACES")) {
|
||||
return callee(upCount + 1);
|
||||
}
|
||||
|
||||
throw error;
|
||||
}
|
||||
|
||||
return dirPath;
|
||||
})(0)
|
||||
}),
|
||||
jarTargets: (() => {
|
||||
const getDefaultJarFileBasename = (range: string) =>
|
||||
`keycloak-theme-for-kc-${range}.jar`;
|
||||
@ -612,10 +524,10 @@ export function getBuildContext(params: {
|
||||
}
|
||||
|
||||
const keycloakVersionRange: KeycloakVersionRange = (() => {
|
||||
const doesImplementAccountV1Theme =
|
||||
!doUseAccountV3 && recordIsImplementedByThemeType.account;
|
||||
const doesImplementAccountTheme =
|
||||
recordIsImplementedByThemeType.account;
|
||||
|
||||
if (doesImplementAccountV1Theme) {
|
||||
if (doesImplementAccountTheme) {
|
||||
const keycloakVersionRange = (() => {
|
||||
if (buildForKeycloakMajorVersionNumber <= 21) {
|
||||
return "21-and-below" as const;
|
||||
@ -637,7 +549,7 @@ export function getBuildContext(params: {
|
||||
assert<
|
||||
Equals<
|
||||
typeof keycloakVersionRange,
|
||||
KeycloakVersionRange.WithAccountV1Theme
|
||||
KeycloakVersionRange.WithAccountTheme
|
||||
>
|
||||
>();
|
||||
|
||||
@ -654,7 +566,7 @@ export function getBuildContext(params: {
|
||||
assert<
|
||||
Equals<
|
||||
typeof keycloakVersionRange,
|
||||
KeycloakVersionRange.WithoutAccountV1Theme
|
||||
KeycloakVersionRange.WithoutAccountTheme
|
||||
>
|
||||
>();
|
||||
|
||||
@ -702,7 +614,7 @@ export function getBuildContext(params: {
|
||||
const jarTargets_default = (() => {
|
||||
const jarTargets: BuildContext["jarTargets"] = [];
|
||||
|
||||
if (!doUseAccountV3 && recordIsImplementedByThemeType.account) {
|
||||
if (recordIsImplementedByThemeType.account) {
|
||||
for (const keycloakVersionRange of [
|
||||
"21-and-below",
|
||||
"23",
|
||||
@ -712,7 +624,7 @@ export function getBuildContext(params: {
|
||||
assert<
|
||||
Equals<
|
||||
typeof keycloakVersionRange,
|
||||
KeycloakVersionRange.WithAccountV1Theme
|
||||
KeycloakVersionRange.WithAccountTheme
|
||||
>
|
||||
>(true);
|
||||
jarTargets.push({
|
||||
@ -729,7 +641,7 @@ export function getBuildContext(params: {
|
||||
assert<
|
||||
Equals<
|
||||
typeof keycloakVersionRange,
|
||||
KeycloakVersionRange.WithoutAccountV1Theme
|
||||
KeycloakVersionRange.WithoutAccountTheme
|
||||
>
|
||||
>(true);
|
||||
jarTargets.push({
|
||||
@ -748,9 +660,8 @@ export function getBuildContext(params: {
|
||||
}
|
||||
|
||||
if (
|
||||
buildOptions.keycloakVersionTargets.hasAccountTheme !== doUseAccountV3
|
||||
? false
|
||||
: recordIsImplementedByThemeType.account
|
||||
buildOptions.keycloakVersionTargets.hasAccountTheme !==
|
||||
recordIsImplementedByThemeType.account
|
||||
) {
|
||||
console.log(
|
||||
chalk.red(
|
||||
@ -870,7 +781,10 @@ export function getBuildContext(params: {
|
||||
}
|
||||
|
||||
return jarTargets;
|
||||
})(),
|
||||
doUseAccountV3
|
||||
})()
|
||||
};
|
||||
|
||||
console.log("DEBUG:", JSON.stringify({ buildContext }, null, 2));
|
||||
|
||||
return buildContext;
|
||||
}
|
||||
|
@ -37,7 +37,10 @@ export async function copyKeycloakResourcesToPublic(params: {
|
||||
buildContext: {
|
||||
loginThemeResourcesFromKeycloakVersion: readThisNpmPackageVersion(),
|
||||
cacheDirPath: pathRelative(destDirPath, buildContext.cacheDirPath),
|
||||
fetchOptions: buildContext.fetchOptions
|
||||
npmWorkspaceRootDirPath: pathRelative(
|
||||
destDirPath,
|
||||
buildContext.npmWorkspaceRootDirPath
|
||||
)
|
||||
}
|
||||
},
|
||||
null,
|
||||
|
@ -6,7 +6,7 @@ import { downloadAndExtractArchive } from "../tools/downloadAndExtractArchive";
|
||||
|
||||
export type BuildContextLike = {
|
||||
cacheDirPath: string;
|
||||
fetchOptions: BuildContext["fetchOptions"];
|
||||
npmWorkspaceRootDirPath: string;
|
||||
};
|
||||
|
||||
assert<BuildContext extends BuildContextLike ? true : false>();
|
||||
@ -23,8 +23,8 @@ export async function downloadKeycloakDefaultTheme(params: {
|
||||
const { extractedDirPath } = await downloadAndExtractArchive({
|
||||
url: `https://repo1.maven.org/maven2/org/keycloak/keycloak-themes/${keycloakVersion}/keycloak-themes-${keycloakVersion}.jar`,
|
||||
cacheDirPath: buildContext.cacheDirPath,
|
||||
fetchOptions: buildContext.fetchOptions,
|
||||
uniqueIdOfOnArchiveFile: "downloadKeycloakDefaultTheme",
|
||||
npmWorkspaceRootDirPath: buildContext.npmWorkspaceRootDirPath,
|
||||
uniqueIdOfOnOnArchiveFile: "downloadKeycloakDefaultTheme",
|
||||
onArchiveFile: async params => {
|
||||
const fileRelativePath = pathRelative("theme", params.fileRelativePath);
|
||||
|
||||
@ -231,7 +231,6 @@ export async function downloadKeycloakDefaultTheme(params: {
|
||||
"fonts",
|
||||
"PatternFlyIcons-webfont.woff"
|
||||
),
|
||||
pathJoin("patternfly", "dist", "img", "bg-login.jpg"),
|
||||
pathJoin("jquery", "dist", "jquery.min.js")
|
||||
];
|
||||
}
|
||||
|
@ -1,15 +1,16 @@
|
||||
import * as child_process from "child_process";
|
||||
import { Deferred } from "evt/tools/Deferred";
|
||||
import { assert } from "tsafe/assert";
|
||||
import { is } from "tsafe/is";
|
||||
import type { BuildContext } from "../shared/buildContext";
|
||||
import chalk from "chalk";
|
||||
import { sep as pathSep, join as pathJoin } from "path";
|
||||
import { getAbsoluteAndInOsFormatPath } from "../tools/getAbsoluteAndInOsFormatPath";
|
||||
import * as fs from "fs";
|
||||
import { join as pathJoin } from "path";
|
||||
|
||||
export type BuildContextLike = {
|
||||
projectDirPath: string;
|
||||
keycloakifyBuildDirPath: string;
|
||||
bundler: BuildContext["bundler"];
|
||||
bundler: "vite" | "webpack";
|
||||
npmWorkspaceRootDirPath: string;
|
||||
projectBuildDirPath: string;
|
||||
};
|
||||
|
||||
@ -20,29 +21,95 @@ export async function appBuild(params: {
|
||||
}): Promise<{ isAppBuildSuccess: boolean }> {
|
||||
const { buildContext } = params;
|
||||
|
||||
switch (buildContext.bundler.type) {
|
||||
case "vite":
|
||||
return appBuild_vite({ buildContext });
|
||||
case "webpack":
|
||||
return appBuild_webpack({ buildContext });
|
||||
}
|
||||
}
|
||||
const { bundler } = buildContext;
|
||||
|
||||
async function appBuild_vite(params: {
|
||||
buildContext: BuildContextLike;
|
||||
}): Promise<{ isAppBuildSuccess: boolean }> {
|
||||
const { buildContext } = params;
|
||||
const { command, args, cwd } = (() => {
|
||||
switch (bundler) {
|
||||
case "vite":
|
||||
return {
|
||||
command: "npx",
|
||||
args: ["vite", "build"],
|
||||
cwd: buildContext.projectDirPath
|
||||
};
|
||||
case "webpack": {
|
||||
for (const dirPath of [
|
||||
buildContext.projectDirPath,
|
||||
buildContext.npmWorkspaceRootDirPath
|
||||
]) {
|
||||
try {
|
||||
const parsedPackageJson = JSON.parse(
|
||||
fs
|
||||
.readFileSync(pathJoin(dirPath, "package.json"))
|
||||
.toString("utf8")
|
||||
);
|
||||
|
||||
assert(buildContext.bundler.type === "vite");
|
||||
const [scriptName] =
|
||||
Object.entries(parsedPackageJson.scripts).find(
|
||||
([, scriptValue]) => {
|
||||
assert(is<string>(scriptValue));
|
||||
if (
|
||||
scriptValue.includes("webpack") &&
|
||||
scriptValue.includes("--mode production")
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const dIsSuccess = new Deferred<boolean>();
|
||||
if (
|
||||
scriptValue.includes("react-scripts") &&
|
||||
scriptValue.includes("build")
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
console.log(chalk.blue("Running: 'npx vite build'"));
|
||||
if (
|
||||
scriptValue.includes("react-app-rewired") &&
|
||||
scriptValue.includes("build")
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const child = child_process.spawn("npx", ["vite", "build"], {
|
||||
cwd: buildContext.projectDirPath,
|
||||
shell: true
|
||||
});
|
||||
if (
|
||||
scriptValue.includes("craco") &&
|
||||
scriptValue.includes("build")
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (
|
||||
scriptValue.includes("ng") &&
|
||||
scriptValue.includes("build")
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
) ?? [];
|
||||
|
||||
if (scriptName === undefined) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return {
|
||||
command: "npm",
|
||||
args: ["run", scriptName],
|
||||
cwd: dirPath
|
||||
};
|
||||
} catch {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
throw new Error(
|
||||
"Keycloakify was unable to determine which script is responsible for building the app."
|
||||
);
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
||||
const dResult = new Deferred<{ isSuccess: boolean }>();
|
||||
|
||||
const child = child_process.spawn(command, args, { cwd, shell: true });
|
||||
|
||||
child.stdout.on("data", data => {
|
||||
if (data.toString("utf8").includes("gzip:")) {
|
||||
@ -54,127 +121,9 @@ async function appBuild_vite(params: {
|
||||
|
||||
child.stderr.on("data", data => process.stderr.write(data));
|
||||
|
||||
child.on("exit", code => dIsSuccess.resolve(code === 0));
|
||||
child.on("exit", code => dResult.resolve({ isSuccess: code === 0 }));
|
||||
|
||||
const isSuccess = await dIsSuccess.pr;
|
||||
const { isSuccess } = await dResult.pr;
|
||||
|
||||
return { isAppBuildSuccess: isSuccess };
|
||||
}
|
||||
|
||||
async function appBuild_webpack(params: {
|
||||
buildContext: BuildContextLike;
|
||||
}): Promise<{ isAppBuildSuccess: boolean }> {
|
||||
const { buildContext } = params;
|
||||
|
||||
assert(buildContext.bundler.type === "webpack");
|
||||
|
||||
const entries = Object.entries(buildContext.bundler.packageJsonScripts).filter(
|
||||
([, scriptCommand]) => scriptCommand.includes("keycloakify build")
|
||||
);
|
||||
|
||||
if (entries.length === 0) {
|
||||
console.log(
|
||||
chalk.red(
|
||||
[
|
||||
`You should have a script in your package.json at ${buildContext.bundler.packageJsonDirPath}`,
|
||||
`that includes the 'keycloakify build' command`
|
||||
].join(" ")
|
||||
)
|
||||
);
|
||||
process.exit(-1);
|
||||
}
|
||||
|
||||
const entry =
|
||||
entries.length === 1
|
||||
? entries[0]
|
||||
: entries.find(([scriptName]) => scriptName === "build-keycloak-theme");
|
||||
|
||||
if (entry === undefined) {
|
||||
console.log(
|
||||
chalk.red(
|
||||
"There's multiple candidate script for building your app, name one 'build-keycloak-theme'"
|
||||
)
|
||||
);
|
||||
process.exit(-1);
|
||||
}
|
||||
|
||||
const [scriptName, scriptCommand] = entry;
|
||||
|
||||
const { appBuildSubCommands } = (() => {
|
||||
const appBuildSubCommands: string[] = [];
|
||||
|
||||
for (const subCmd of scriptCommand.split("&&").map(s => s.trim())) {
|
||||
if (subCmd.includes("keycloakify build")) {
|
||||
break;
|
||||
}
|
||||
|
||||
appBuildSubCommands.push(subCmd);
|
||||
}
|
||||
|
||||
return { appBuildSubCommands };
|
||||
})();
|
||||
|
||||
if (appBuildSubCommands.length === 0) {
|
||||
console.log(
|
||||
chalk.red(
|
||||
`Your ${scriptName} script should look like "... && keycloakify build ..."`
|
||||
)
|
||||
);
|
||||
process.exit(-1);
|
||||
}
|
||||
|
||||
let commandCwd = buildContext.bundler.packageJsonDirPath;
|
||||
|
||||
for (const subCommand of appBuildSubCommands) {
|
||||
const dIsSuccess = new Deferred<boolean>();
|
||||
|
||||
const [command, ...args] = subCommand.split(" ");
|
||||
|
||||
if (command === "cd") {
|
||||
const [pathIsh] = args;
|
||||
|
||||
commandCwd = getAbsoluteAndInOsFormatPath({
|
||||
pathIsh,
|
||||
cwd: commandCwd
|
||||
});
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
console.log(chalk.blue(`Running: '${subCommand}'`));
|
||||
|
||||
const child = child_process.spawn(command, args, {
|
||||
cwd: commandCwd,
|
||||
env: {
|
||||
...process.env,
|
||||
PATH: (() => {
|
||||
const separator = pathSep === "/" ? ":" : ";";
|
||||
|
||||
return [
|
||||
pathJoin(
|
||||
buildContext.bundler.packageJsonDirPath,
|
||||
"node_modules",
|
||||
".bin"
|
||||
),
|
||||
...(process.env.PATH ?? "").split(separator)
|
||||
].join(separator);
|
||||
})()
|
||||
},
|
||||
shell: true
|
||||
});
|
||||
|
||||
child.stdout.on("data", data => process.stdout.write(data));
|
||||
|
||||
child.stderr.on("data", data => process.stderr.write(data));
|
||||
|
||||
child.on("exit", code => dIsSuccess.resolve(code === 0));
|
||||
|
||||
const isSuccess = await dIsSuccess.pr;
|
||||
|
||||
if (!isSuccess) {
|
||||
return { isAppBuildSuccess: false };
|
||||
}
|
||||
}
|
||||
|
||||
return { isAppBuildSuccess: true };
|
||||
}
|
||||
|
@ -3,11 +3,11 @@ import * as child_process from "child_process";
|
||||
import { Deferred } from "evt/tools/Deferred";
|
||||
import { assert } from "tsafe/assert";
|
||||
import type { BuildContext } from "../shared/buildContext";
|
||||
import chalk from "chalk";
|
||||
|
||||
export type BuildContextLike = {
|
||||
projectDirPath: string;
|
||||
keycloakifyBuildDirPath: string;
|
||||
bundler: "vite" | "webpack";
|
||||
};
|
||||
|
||||
assert<BuildContext extends BuildContextLike ? true : false>();
|
||||
@ -20,8 +20,6 @@ export async function keycloakifyBuild(params: {
|
||||
|
||||
const dResult = new Deferred<{ isSuccess: boolean }>();
|
||||
|
||||
console.log(chalk.blue("Running: 'npx keycloakify build'"));
|
||||
|
||||
const child = child_process.spawn("npx", ["keycloakify", "build"], {
|
||||
cwd: buildContext.projectDirPath,
|
||||
env: {
|
||||
|
@ -121,7 +121,7 @@ export async function command(params: { cliCommandOptions: CliCommandOptions })
|
||||
if (!isAppBuildSuccess) {
|
||||
console.log(
|
||||
chalk.red(
|
||||
`App build failed, exiting. Try building your app (e.g 'npm run build') and see what's wrong.`
|
||||
`App build failed, exiting. Try running 'npm run build' and see what's wrong.`
|
||||
)
|
||||
);
|
||||
process.exit(1);
|
||||
|
@ -1,15 +0,0 @@
|
||||
import { sep as pathSep } from "path";
|
||||
import chalk from "chalk";
|
||||
|
||||
export function assertNoPnpmDlx() {
|
||||
if (__dirname.includes(`${pathSep}pnpm${pathSep}dlx${pathSep}`)) {
|
||||
console.log(
|
||||
[
|
||||
chalk.red("Please don't use `pnpm dlx keycloakify`"),
|
||||
"\nUse `npx keycloakify` or `pnpm exec keycloakify` instead since you want to use the keycloakify",
|
||||
"version that is installed in your project and not the latest version on NPM."
|
||||
].join(" ")
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
@ -1,16 +1,16 @@
|
||||
import fetch, { type FetchOptions } from "make-fetch-happen";
|
||||
import fetch from "make-fetch-happen";
|
||||
import { mkdir, unlink, writeFile, readdir, readFile } from "fs/promises";
|
||||
import { dirname as pathDirname, join as pathJoin } from "path";
|
||||
import { assert } from "tsafe/assert";
|
||||
import { extractArchive } from "./extractArchive";
|
||||
import { existsAsync } from "./fs.existsAsync";
|
||||
|
||||
import { extractArchive } from "../extractArchive";
|
||||
import { existsAsync } from "../fs.existsAsync";
|
||||
import { getProxyFetchOptions } from "./fetchProxyOptions";
|
||||
import * as crypto from "crypto";
|
||||
import { rm } from "./fs.rm";
|
||||
import { rm } from "../fs.rm";
|
||||
|
||||
export async function downloadAndExtractArchive(params: {
|
||||
url: string;
|
||||
uniqueIdOfOnArchiveFile: string;
|
||||
uniqueIdOfOnOnArchiveFile: string;
|
||||
onArchiveFile: (params: {
|
||||
fileRelativePath: string;
|
||||
readFile: () => Promise<Buffer>;
|
||||
@ -20,10 +20,15 @@ export async function downloadAndExtractArchive(params: {
|
||||
}) => Promise<void>;
|
||||
}) => Promise<void>;
|
||||
cacheDirPath: string;
|
||||
fetchOptions: FetchOptions | undefined;
|
||||
npmWorkspaceRootDirPath: string;
|
||||
}): Promise<{ extractedDirPath: string }> {
|
||||
const { url, uniqueIdOfOnArchiveFile, onArchiveFile, cacheDirPath, fetchOptions } =
|
||||
params;
|
||||
const {
|
||||
url,
|
||||
uniqueIdOfOnOnArchiveFile,
|
||||
onArchiveFile,
|
||||
cacheDirPath,
|
||||
npmWorkspaceRootDirPath
|
||||
} = params;
|
||||
|
||||
const archiveFileBasename = url.split("?")[0].split("/").reverse()[0];
|
||||
|
||||
@ -50,7 +55,10 @@ export async function downloadAndExtractArchive(params: {
|
||||
|
||||
await mkdir(pathDirname(archiveFilePath), { recursive: true });
|
||||
|
||||
const response = await fetch(url, fetchOptions);
|
||||
const response = await fetch(
|
||||
url,
|
||||
await getProxyFetchOptions({ npmWorkspaceRootDirPath })
|
||||
);
|
||||
|
||||
response.body?.setMaxListeners(Number.MAX_VALUE);
|
||||
assert(typeof response.body !== "undefined" && response.body != null);
|
||||
@ -63,7 +71,7 @@ export async function downloadAndExtractArchive(params: {
|
||||
});
|
||||
}
|
||||
|
||||
const extractDirBasename = `${archiveFileBasename.split(".")[0]}_${uniqueIdOfOnArchiveFile}_${crypto
|
||||
const extractDirBasename = `${archiveFileBasename.split(".")[0]}_${uniqueIdOfOnOnArchiveFile}_${crypto
|
||||
.createHash("sha256")
|
||||
.update(onArchiveFile.toString())
|
||||
.digest("hex")
|
@ -1,40 +1,61 @@
|
||||
import { exec as execCallback } from "child_process";
|
||||
import { readFile } from "fs/promises";
|
||||
import { type FetchOptions } from "make-fetch-happen";
|
||||
import * as child_process from "child_process";
|
||||
import * as fs from "fs";
|
||||
import { promisify } from "util";
|
||||
|
||||
function ensureArray<T>(arg0: T | T[]) {
|
||||
return Array.isArray(arg0) ? arg0 : typeof arg0 === "undefined" ? [] : [arg0];
|
||||
}
|
||||
|
||||
function ensureSingleOrNone<T>(arg0: T | T[]) {
|
||||
if (!Array.isArray(arg0)) return arg0;
|
||||
if (arg0.length === 0) return undefined;
|
||||
if (arg0.length === 1) return arg0[0];
|
||||
throw new Error(
|
||||
"Illegal configuration, expected a single value but found multiple: " +
|
||||
arg0.map(String).join(", ")
|
||||
);
|
||||
}
|
||||
|
||||
type NPMConfig = Record<string, string | string[]>;
|
||||
|
||||
/**
|
||||
* Get npm configuration as map
|
||||
*/
|
||||
async function getNmpConfig(params: { npmWorkspaceRootDirPath: string }) {
|
||||
const { npmWorkspaceRootDirPath } = params;
|
||||
|
||||
const exec = promisify(execCallback);
|
||||
|
||||
const stdout = await exec("npm config get", {
|
||||
encoding: "utf8",
|
||||
cwd: npmWorkspaceRootDirPath
|
||||
}).then(({ stdout }) => stdout);
|
||||
|
||||
const npmConfigReducer = (cfg: NPMConfig, [key, value]: [string, string]) =>
|
||||
key in cfg
|
||||
? { ...cfg, [key]: [...ensureArray(cfg[key]), value] }
|
||||
: { ...cfg, [key]: value };
|
||||
|
||||
return stdout
|
||||
.split("\n")
|
||||
.filter(line => !line.startsWith(";"))
|
||||
.map(line => line.trim())
|
||||
.map(line => line.split("=", 2) as [string, string])
|
||||
.reduce(npmConfigReducer, {} as NPMConfig);
|
||||
}
|
||||
|
||||
export type ProxyFetchOptions = Pick<
|
||||
FetchOptions,
|
||||
"proxy" | "noProxy" | "strictSSL" | "cert" | "ca"
|
||||
>;
|
||||
|
||||
export function getProxyFetchOptions(params: {
|
||||
npmConfigGetCwd: string;
|
||||
}): ProxyFetchOptions {
|
||||
const { npmConfigGetCwd } = params;
|
||||
export async function getProxyFetchOptions(params: {
|
||||
npmWorkspaceRootDirPath: string;
|
||||
}): Promise<ProxyFetchOptions> {
|
||||
const { npmWorkspaceRootDirPath } = params;
|
||||
|
||||
const cfg = (() => {
|
||||
const output = child_process
|
||||
.execSync("npm config get", {
|
||||
cwd: npmConfigGetCwd
|
||||
})
|
||||
.toString("utf8");
|
||||
|
||||
return output
|
||||
.split("\n")
|
||||
.filter(line => !line.startsWith(";"))
|
||||
.map(line => line.trim())
|
||||
.map(line => line.split("=", 2) as [string, string])
|
||||
.reduce(
|
||||
(
|
||||
cfg: Record<string, string | string[]>,
|
||||
[key, value]: [string, string]
|
||||
) =>
|
||||
key in cfg
|
||||
? { ...cfg, [key]: [...ensureArray(cfg[key]), value] }
|
||||
: { ...cfg, [key]: value },
|
||||
{}
|
||||
);
|
||||
})();
|
||||
const cfg = await getNmpConfig({ npmWorkspaceRootDirPath });
|
||||
|
||||
const proxy = ensureSingleOrNone(cfg["https-proxy"] ?? cfg["proxy"]);
|
||||
const noProxy = cfg["noproxy"] ?? cfg["no-proxy"];
|
||||
@ -50,15 +71,16 @@ export function getProxyFetchOptions(params: {
|
||||
|
||||
if (typeof cafile !== "undefined" && cafile !== "null") {
|
||||
ca.push(
|
||||
...(() => {
|
||||
const cafileContent = fs.readFileSync(cafile).toString("utf8");
|
||||
|
||||
const newLinePlaceholder = "NEW_LINE_PLACEHOLDER_xIsPsK23svt";
|
||||
|
||||
const chunks = <T>(arr: T[], size: number = 2) =>
|
||||
arr
|
||||
...(await (async () => {
|
||||
function chunks<T>(arr: T[], size: number = 2) {
|
||||
return arr
|
||||
.map((_, i) => i % size == 0 && arr.slice(i, i + size))
|
||||
.filter(Boolean) as T[][];
|
||||
}
|
||||
|
||||
const cafileContent = await readFile(cafile, "utf-8");
|
||||
|
||||
const newLinePlaceholder = "NEW_LINE_PLACEHOLDER_xIsPsK23svt";
|
||||
|
||||
return chunks(cafileContent.split(/(-----END CERTIFICATE-----)/), 2).map(
|
||||
ca =>
|
||||
@ -68,7 +90,7 @@ export function getProxyFetchOptions(params: {
|
||||
.replace(new RegExp(`^${newLinePlaceholder}`), "")
|
||||
.replace(new RegExp(newLinePlaceholder, "g"), "\\n")
|
||||
);
|
||||
})()
|
||||
})())
|
||||
);
|
||||
}
|
||||
|
||||
@ -80,17 +102,3 @@ export function getProxyFetchOptions(params: {
|
||||
ca: ca.length === 0 ? undefined : ca
|
||||
};
|
||||
}
|
||||
|
||||
function ensureArray<T>(arg0: T | T[]) {
|
||||
return Array.isArray(arg0) ? arg0 : typeof arg0 === "undefined" ? [] : [arg0];
|
||||
}
|
||||
|
||||
function ensureSingleOrNone<T>(arg0: T | T[]) {
|
||||
if (!Array.isArray(arg0)) return arg0;
|
||||
if (arg0.length === 0) return undefined;
|
||||
if (arg0.length === 1) return arg0[0];
|
||||
throw new Error(
|
||||
"Illegal configuration, expected a single value but found multiple: " +
|
||||
arg0.map(String).join(", ")
|
||||
);
|
||||
}
|
1
src/bin/tools/downloadAndExtractArchive/index.ts
Normal file
1
src/bin/tools/downloadAndExtractArchive/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from "./downloadAndExtractArchive";
|
84
src/bin/tools/getNpmWorkspaceRootDirPath.ts
Normal file
84
src/bin/tools/getNpmWorkspaceRootDirPath.ts
Normal file
@ -0,0 +1,84 @@
|
||||
import * as child_process from "child_process";
|
||||
import { join as pathJoin, resolve as pathResolve, sep as pathSep } from "path";
|
||||
import { assert } from "tsafe/assert";
|
||||
import * as fs from "fs";
|
||||
|
||||
export function getNpmWorkspaceRootDirPath(params: {
|
||||
projectDirPath: string;
|
||||
dependencyExpected: string;
|
||||
}) {
|
||||
const { projectDirPath, dependencyExpected } = params;
|
||||
|
||||
console.log("DEBUG getNpmWorkspaceRootDirPath:", {
|
||||
projectDirPath,
|
||||
dependencyExpected
|
||||
});
|
||||
|
||||
const npmWorkspaceRootDirPath = (function callee(depth: number): string {
|
||||
const cwd = pathResolve(
|
||||
pathJoin(...[projectDirPath, ...Array(depth).fill("..")])
|
||||
);
|
||||
|
||||
console.log("DEBUG getNpmWorkspaceRootDirPath:", { cwd });
|
||||
|
||||
assert(cwd !== pathSep, "NPM workspace not found");
|
||||
|
||||
try {
|
||||
child_process.execSync("npm config get", {
|
||||
cwd,
|
||||
stdio: "ignore"
|
||||
});
|
||||
} catch (error) {
|
||||
console.log("DEBUG getNpmWorkspaceRootDirPath: got error npm config get");
|
||||
|
||||
if (String(error).includes("ENOWORKSPACES")) {
|
||||
return callee(depth + 1);
|
||||
}
|
||||
|
||||
throw error;
|
||||
}
|
||||
|
||||
console.log("DEBUG getNpmWorkspaceRootDirPath: npm workspace found");
|
||||
|
||||
const packageJsonFilePath = pathJoin(cwd, "package.json");
|
||||
|
||||
if (!fs.existsSync(packageJsonFilePath)) {
|
||||
return callee(depth + 1);
|
||||
}
|
||||
|
||||
assert(fs.existsSync(packageJsonFilePath));
|
||||
|
||||
const parsedPackageJson = JSON.parse(
|
||||
fs.readFileSync(packageJsonFilePath).toString("utf8")
|
||||
);
|
||||
|
||||
let isExpectedDependencyFound = false;
|
||||
|
||||
for (const dependenciesOrDevDependencies of [
|
||||
"dependencies",
|
||||
"devDependencies"
|
||||
] as const) {
|
||||
const dependencies = parsedPackageJson[dependenciesOrDevDependencies];
|
||||
|
||||
if (dependencies === undefined) {
|
||||
continue;
|
||||
}
|
||||
|
||||
assert(dependencies instanceof Object);
|
||||
|
||||
if (dependencies[dependencyExpected] === undefined) {
|
||||
continue;
|
||||
}
|
||||
|
||||
isExpectedDependencyFound = true;
|
||||
}
|
||||
|
||||
if (!isExpectedDependencyFound && parsedPackageJson.name !== dependencyExpected) {
|
||||
return callee(depth + 1);
|
||||
}
|
||||
|
||||
return cwd;
|
||||
})(0);
|
||||
|
||||
return { npmWorkspaceRootDirPath };
|
||||
}
|
@ -15,6 +15,7 @@ export default function Template(props: TemplateProps<KcContext, I18n>) {
|
||||
displayMessage = true,
|
||||
displayRequiredFields = false,
|
||||
headerNode,
|
||||
showUsernameNode = null,
|
||||
socialProvidersNode = null,
|
||||
infoNode = null,
|
||||
documentTitle,
|
||||
@ -163,10 +164,45 @@ export default function Template(props: TemplateProps<KcContext, I18n>) {
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{(() => {
|
||||
const node = !(auth !== undefined && auth.showUsername && !auth.showResetCredentials) ? (
|
||||
<h1 id="kc-page-title">{headerNode}</h1>
|
||||
{!(auth !== undefined && auth.showUsername && !auth.showResetCredentials) ? (
|
||||
displayRequiredFields ? (
|
||||
<div className={kcClsx("kcContentWrapperClass")}>
|
||||
<div className={clsx(kcClsx("kcLabelWrapperClass"), "subtitle")}>
|
||||
<span className="subtitle">
|
||||
<span className="required">*</span>
|
||||
{msg("requiredFields")}
|
||||
</span>
|
||||
</div>
|
||||
<div className="col-md-10">
|
||||
<h1 id="kc-page-title">{headerNode}</h1>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<h1 id="kc-page-title">{headerNode}</h1>
|
||||
)
|
||||
) : displayRequiredFields ? (
|
||||
<div className={kcClsx("kcContentWrapperClass")}>
|
||||
<div className={clsx(kcClsx("kcLabelWrapperClass"), "subtitle")}>
|
||||
<span className="subtitle">
|
||||
<span className="required">*</span> {msg("requiredFields")}
|
||||
</span>
|
||||
</div>
|
||||
<div className="col-md-10">
|
||||
{showUsernameNode}
|
||||
<div id="kc-username" className={kcClsx("kcFormGroupClass")}>
|
||||
<label id="kc-attempted-username">{auth.attemptedUsername}</label>
|
||||
<a id="reset-login" href={url.loginRestartFlowUrl} aria-label={msgStr("restartLoginTooltip")}>
|
||||
<div className="kc-login-tooltip">
|
||||
<i className={kcClsx("kcResetFlowIcon")}></i>
|
||||
<span className="kc-tooltip-text">{msg("restartLoginTooltip")}</span>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
{showUsernameNode}
|
||||
<div id="kc-username" className={kcClsx("kcFormGroupClass")}>
|
||||
<label id="kc-attempted-username">{auth.attemptedUsername}</label>
|
||||
<a id="reset-login" href={url.loginRestartFlowUrl} aria-label={msgStr("restartLoginTooltip")}>
|
||||
@ -176,24 +212,8 @@ export default function Template(props: TemplateProps<KcContext, I18n>) {
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
);
|
||||
|
||||
if (displayRequiredFields) {
|
||||
return (
|
||||
<div className={kcClsx("kcContentWrapperClass")}>
|
||||
<div className={clsx(kcClsx("kcLabelWrapperClass"), "subtitle")}>
|
||||
<span className="subtitle">
|
||||
<span className="required">*</span>
|
||||
{msg("requiredFields")}
|
||||
</span>
|
||||
</div>
|
||||
<div className="col-md-10">{node}</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return node;
|
||||
})()}
|
||||
</>
|
||||
)}
|
||||
</header>
|
||||
<div id="kc-content">
|
||||
<div id="kc-content-wrapper">
|
||||
|
@ -12,6 +12,7 @@ export type TemplateProps<KcContext, I18n> = {
|
||||
displayRequiredFields?: boolean;
|
||||
showAnotherWayIfPresent?: boolean;
|
||||
headerNode: ReactNode;
|
||||
showUsernameNode?: ReactNode;
|
||||
socialProvidersNode?: ReactNode;
|
||||
infoNode?: ReactNode;
|
||||
documentTitle?: string;
|
||||
|
@ -188,7 +188,7 @@ function FieldErrors(props: { attribute: Attribute; displayableErrors: FormField
|
||||
.filter(error => error.fieldIndex === fieldIndex)
|
||||
.map(({ errorMessage }, i, arr) => (
|
||||
<Fragment key={i}>
|
||||
{errorMessage}
|
||||
<span key={i}>{errorMessage}</span>
|
||||
{arr.length - 1 !== i && <br />}
|
||||
</Fragment>
|
||||
))}
|
||||
|
@ -259,16 +259,8 @@ function createI18nTranslationFunctionsFactory<MessageKey extends string, ExtraM
|
||||
function resolveMsgAdvanced(props: { key: string; args: (string | undefined)[]; doRenderAsHtml: boolean }): JSX.Element | string {
|
||||
const { key, args, doRenderAsHtml } = props;
|
||||
|
||||
user_profile: {
|
||||
if (realmMessageBundleUserProfile === undefined) {
|
||||
break user_profile;
|
||||
}
|
||||
|
||||
const resolvedMessage = realmMessageBundleUserProfile[key] ?? realmMessageBundleUserProfile["${" + key + "}"];
|
||||
|
||||
if (resolvedMessage === undefined) {
|
||||
break user_profile;
|
||||
}
|
||||
if (realmMessageBundleUserProfile !== undefined && key in realmMessageBundleUserProfile) {
|
||||
const resolvedMessage = realmMessageBundleUserProfile[key];
|
||||
|
||||
return doRenderAsHtml ? (
|
||||
<span
|
||||
|
@ -612,14 +612,7 @@ function useGetErrors(params: { kcContext: KcContextLike_useGetErrors; i18n: I18
|
||||
return [
|
||||
{
|
||||
errorMessageStr,
|
||||
errorMessage: (
|
||||
<span
|
||||
key={0}
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: errorMessageStr
|
||||
}}
|
||||
/>
|
||||
),
|
||||
errorMessage: <span key={0}>{errorMessageStr}</span>,
|
||||
fieldIndex: undefined,
|
||||
source: {
|
||||
type: "server"
|
||||
|
@ -19,7 +19,7 @@ export default function Error(props: PageProps<Extract<KcContext, { pageId: "err
|
||||
headerNode={msg("errorTitle")}
|
||||
>
|
||||
<div id="kc-error-message">
|
||||
<p className="instruction" dangerouslySetInnerHTML={{ __html: message.summary }} />
|
||||
<p className="instruction">{message.summary}</p>
|
||||
{!skipLink && client !== undefined && client.baseUrl !== undefined && (
|
||||
<p>
|
||||
<a id="backToApplication" href={client.baseUrl}>
|
||||
|
@ -16,33 +16,13 @@ export default function Info(props: PageProps<Extract<KcContext, { pageId: "info
|
||||
doUseDefaultCss={doUseDefaultCss}
|
||||
classes={classes}
|
||||
displayMessage={false}
|
||||
headerNode={
|
||||
<span
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: messageHeader ?? message.summary
|
||||
}}
|
||||
/>
|
||||
}
|
||||
headerNode={messageHeader !== undefined ? <>{messageHeader}</> : <>{message.summary}</>}
|
||||
>
|
||||
<div id="kc-info-message">
|
||||
<p
|
||||
className="instruction"
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: (() => {
|
||||
let html = message.summary;
|
||||
|
||||
if (requiredActions) {
|
||||
html += "<b>";
|
||||
|
||||
html += requiredActions.map(requiredAction => msgStr(`requiredAction.${requiredAction}` as const)).join(",");
|
||||
|
||||
html += "</b>";
|
||||
}
|
||||
|
||||
return html;
|
||||
})()
|
||||
}}
|
||||
/>
|
||||
<p className="instruction">
|
||||
{message.summary}
|
||||
{requiredActions && <b>{requiredActions.map(requiredAction => msgStr(`requiredAction.${requiredAction}` as const)).join(",")}</b>}
|
||||
</p>
|
||||
{(() => {
|
||||
if (skipLink) {
|
||||
return null;
|
||||
|
@ -60,10 +60,9 @@ export default function Login(props: PageProps<Extract<KcContext, { pageId: "log
|
||||
href={p.loginUrl}
|
||||
>
|
||||
{p.iconClasses && <i className={clsx(kcClsx("kcCommonLogoIdP"), p.iconClasses)} aria-hidden="true"></i>}
|
||||
<span
|
||||
className={clsx(kcClsx("kcFormSocialAccountNameClass"), p.iconClasses && "kc-social-icon-text")}
|
||||
dangerouslySetInnerHTML={{ __html: p.displayName }}
|
||||
></span>
|
||||
<span className={clsx(kcClsx("kcFormSocialAccountNameClass"), p.iconClasses && "kc-social-icon-text")}>
|
||||
{p.displayName}
|
||||
</span>
|
||||
</a>
|
||||
</li>
|
||||
))}
|
||||
@ -106,14 +105,9 @@ export default function Login(props: PageProps<Extract<KcContext, { pageId: "log
|
||||
aria-invalid={messagesPerField.existsError("username", "password")}
|
||||
/>
|
||||
{messagesPerField.existsError("username", "password") && (
|
||||
<span
|
||||
id="input-error"
|
||||
className={kcClsx("kcInputErrorMessageClass")}
|
||||
aria-live="polite"
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: messagesPerField.getFirstError("username", "password")
|
||||
}}
|
||||
/>
|
||||
<span id="input-error" className={kcClsx("kcInputErrorMessageClass")} aria-live="polite">
|
||||
{messagesPerField.getFirstError("username", "password")}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
@ -134,14 +128,9 @@ export default function Login(props: PageProps<Extract<KcContext, { pageId: "log
|
||||
/>
|
||||
</PasswordWrapper>
|
||||
{usernameHidden && messagesPerField.existsError("username", "password") && (
|
||||
<span
|
||||
id="input-error"
|
||||
className={kcClsx("kcInputErrorMessageClass")}
|
||||
aria-live="polite"
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: messagesPerField.getFirstError("username", "password")
|
||||
}}
|
||||
/>
|
||||
<span id="input-error" className={kcClsx("kcInputErrorMessageClass")} aria-live="polite">
|
||||
{messagesPerField.getFirstError("username", "password")}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
|
@ -112,14 +112,9 @@ export default function LoginConfigTotp(props: PageProps<Extract<KcContext, { pa
|
||||
/>
|
||||
|
||||
{messagesPerField.existsError("totp") && (
|
||||
<span
|
||||
id="input-error-otp-code"
|
||||
className={kcClsx("kcInputErrorMessageClass")}
|
||||
aria-live="polite"
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: messagesPerField.get("totp")
|
||||
}}
|
||||
/>
|
||||
<span id="input-error-otp-code" className={kcClsx("kcInputErrorMessageClass")} aria-live="polite">
|
||||
{messagesPerField.get("totp")}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<input type="hidden" id="totpSecret" name="totpSecret" value={totp.totpSecret} />
|
||||
@ -143,14 +138,9 @@ export default function LoginConfigTotp(props: PageProps<Extract<KcContext, { pa
|
||||
aria-invalid={messagesPerField.existsError("userLabel")}
|
||||
/>
|
||||
{messagesPerField.existsError("userLabel") && (
|
||||
<span
|
||||
id="input-error-otp-label"
|
||||
className={kcClsx("kcInputErrorMessageClass")}
|
||||
aria-live="polite"
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: messagesPerField.get("userLabel")
|
||||
}}
|
||||
/>
|
||||
<span id="input-error-otp-label" className={kcClsx("kcInputErrorMessageClass")} aria-live="polite">
|
||||
{messagesPerField.get("userLabel")}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
@ -70,14 +70,9 @@ export default function LoginOtp(props: PageProps<Extract<KcContext, { pageId: "
|
||||
aria-invalid={messagesPerField.existsError("totp")}
|
||||
/>
|
||||
{messagesPerField.existsError("totp") && (
|
||||
<span
|
||||
id="input-error-otp-code"
|
||||
className={kcClsx("kcInputErrorMessageClass")}
|
||||
aria-live="polite"
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: messagesPerField.get("totp")
|
||||
}}
|
||||
/>
|
||||
<span id="input-error-otp-code" className={kcClsx("kcInputErrorMessageClass")} aria-live="polite">
|
||||
{messagesPerField.get("totp")}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
@ -60,14 +60,9 @@ export default function LoginPassword(props: PageProps<Extract<KcContext, { page
|
||||
</PasswordWrapper>
|
||||
|
||||
{messagesPerField.existsError("password") && (
|
||||
<span
|
||||
id="input-error-password"
|
||||
className={kcClsx("kcInputErrorMessageClass")}
|
||||
aria-live="polite"
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: messagesPerField.get("password")
|
||||
}}
|
||||
/>
|
||||
<span id="input-error-password" className={kcClsx("kcInputErrorMessageClass")} aria-live="polite">
|
||||
{messagesPerField.get("password")}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<div className={kcClsx("kcFormGroupClass", "kcFormSettingClass")}>
|
||||
|
@ -43,14 +43,9 @@ export default function LoginRecoveryAuthnCodeInput(props: PageProps<Extract<KcC
|
||||
autoFocus
|
||||
/>
|
||||
{messagesPerField.existsError("recoveryCodeInput") && (
|
||||
<span
|
||||
id="input-error"
|
||||
className={kcClsx("kcInputErrorMessageClass")}
|
||||
aria-live="polite"
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: messagesPerField.get("recoveryCodeInput")
|
||||
}}
|
||||
/>
|
||||
<span id="input-error" className={kcClsx("kcInputErrorMessageClass")} aria-live="polite">
|
||||
{messagesPerField.get("recoveryCodeInput")}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
@ -48,14 +48,9 @@ export default function LoginResetPassword(props: PageProps<Extract<KcContext, {
|
||||
aria-invalid={messagesPerField.existsError("username")}
|
||||
/>
|
||||
{messagesPerField.existsError("username") && (
|
||||
<span
|
||||
id="input-error-username"
|
||||
className={kcClsx("kcInputErrorMessageClass")}
|
||||
aria-live="polite"
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: messagesPerField.get("username")
|
||||
}}
|
||||
/>
|
||||
<span id="input-error-username" className={kcClsx("kcInputErrorMessageClass")} aria-live="polite">
|
||||
{messagesPerField.get("username")}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
@ -46,14 +46,9 @@ export default function LoginUpdatePassword(props: PageProps<Extract<KcContext,
|
||||
</PasswordWrapper>
|
||||
|
||||
{messagesPerField.existsError("password") && (
|
||||
<span
|
||||
id="input-error-password"
|
||||
className={kcClsx("kcInputErrorMessageClass")}
|
||||
aria-live="polite"
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: messagesPerField.get("password")
|
||||
}}
|
||||
/>
|
||||
<span id="input-error-password" className={kcClsx("kcInputErrorMessageClass")} aria-live="polite">
|
||||
{messagesPerField.get("password")}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
@ -79,14 +74,9 @@ export default function LoginUpdatePassword(props: PageProps<Extract<KcContext,
|
||||
</PasswordWrapper>
|
||||
|
||||
{messagesPerField.existsError("password-confirm") && (
|
||||
<span
|
||||
id="input-error-password-confirm"
|
||||
className={kcClsx("kcInputErrorMessageClass")}
|
||||
aria-live="polite"
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: messagesPerField.get("password-confirm")
|
||||
}}
|
||||
/>
|
||||
<span id="input-error-password-confirm" className={kcClsx("kcInputErrorMessageClass")} aria-live="polite">
|
||||
{messagesPerField.get("password-confirm")}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
|
@ -24,7 +24,6 @@ export default function Register(props: RegisterProps) {
|
||||
const { msg, msgStr } = i18n;
|
||||
|
||||
const [isFormSubmittable, setIsFormSubmittable] = useState(false);
|
||||
const [areTermsAccepted, setAreTermsAccepted] = useState(false);
|
||||
|
||||
return (
|
||||
<Template
|
||||
@ -44,15 +43,7 @@ export default function Register(props: RegisterProps) {
|
||||
onIsFormSubmittableValueChange={setIsFormSubmittable}
|
||||
doMakeUserConfirmPassword={doMakeUserConfirmPassword}
|
||||
/>
|
||||
{termsAcceptanceRequired && (
|
||||
<TermsAcceptance
|
||||
i18n={i18n}
|
||||
kcClsx={kcClsx}
|
||||
messagesPerField={messagesPerField}
|
||||
areTermsAccepted={areTermsAccepted}
|
||||
onAreTermsAcceptedValueChange={setAreTermsAccepted}
|
||||
/>
|
||||
)}
|
||||
{termsAcceptanceRequired && <TermsAcceptance i18n={i18n} kcClsx={kcClsx} messagesPerField={messagesPerField} />}
|
||||
{recaptchaRequired && (
|
||||
<div className="form-group">
|
||||
<div className={kcClsx("kcInputWrapperClass")}>
|
||||
@ -70,7 +61,7 @@ export default function Register(props: RegisterProps) {
|
||||
</div>
|
||||
<div id="kc-form-buttons" className={kcClsx("kcFormButtonsClass")}>
|
||||
<input
|
||||
disabled={!isFormSubmittable || (termsAcceptanceRequired && !areTermsAccepted)}
|
||||
disabled={!isFormSubmittable}
|
||||
className={kcClsx("kcButtonClass", "kcButtonPrimaryClass", "kcButtonBlockClass", "kcButtonLargeClass")}
|
||||
type="submit"
|
||||
value={msgStr("doRegister")}
|
||||
@ -82,14 +73,8 @@ export default function Register(props: RegisterProps) {
|
||||
);
|
||||
}
|
||||
|
||||
function TermsAcceptance(props: {
|
||||
i18n: I18n;
|
||||
kcClsx: KcClsx;
|
||||
messagesPerField: Pick<KcContext["messagesPerField"], "existsError" | "get">;
|
||||
areTermsAccepted: boolean;
|
||||
onAreTermsAcceptedValueChange: (areTermsAccepted: boolean) => void;
|
||||
}) {
|
||||
const { i18n, kcClsx, messagesPerField, areTermsAccepted, onAreTermsAcceptedValueChange } = props;
|
||||
function TermsAcceptance(props: { i18n: I18n; kcClsx: KcClsx; messagesPerField: Pick<KcContext["messagesPerField"], "existsError" | "get"> }) {
|
||||
const { i18n, kcClsx, messagesPerField } = props;
|
||||
|
||||
const { msg } = i18n;
|
||||
|
||||
@ -108,8 +93,6 @@ function TermsAcceptance(props: {
|
||||
id="termsAccepted"
|
||||
name="termsAccepted"
|
||||
className={kcClsx("kcCheckboxInputClass")}
|
||||
checked={areTermsAccepted}
|
||||
onChange={e => onAreTermsAcceptedValueChange(e.target.checked)}
|
||||
aria-invalid={messagesPerField.existsError("termsAccepted")}
|
||||
/>
|
||||
<label htmlFor="termsAccepted" className={kcClsx("kcLabelClass")}>
|
||||
@ -118,14 +101,9 @@ function TermsAcceptance(props: {
|
||||
</div>
|
||||
{messagesPerField.existsError("termsAccepted") && (
|
||||
<div className={kcClsx("kcLabelWrapperClass")}>
|
||||
<span
|
||||
id="input-error-terms-accepted"
|
||||
className={kcClsx("kcInputErrorMessageClass")}
|
||||
aria-live="polite"
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: messagesPerField.get("termsAccepted")
|
||||
}}
|
||||
/>
|
||||
<span id="input-error-terms-accepted" className={kcClsx("kcInputErrorMessageClass")} aria-live="polite">
|
||||
{messagesPerField.get("termsAccepted")}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
@ -18,7 +18,7 @@ export default function SamlPostForm(props: PageProps<Extract<KcContext, { pageI
|
||||
}
|
||||
|
||||
// Storybook
|
||||
if (samlPost.url === "#") {
|
||||
if (samlPost.url === "") {
|
||||
alert("In a real Keycloak the user would be redirected immediately");
|
||||
return;
|
||||
}
|
||||
|
@ -1,80 +0,0 @@
|
||||
import React from "react";
|
||||
import type { Meta, StoryObj } from "@storybook/react";
|
||||
import { createKcPageStory } from "../KcPageStory";
|
||||
|
||||
const { KcPageStory } = createKcPageStory({ pageId: "applications.ftl" });
|
||||
|
||||
const meta = {
|
||||
title: "account/applications.ftl",
|
||||
component: KcPageStory
|
||||
} satisfies Meta<typeof KcPageStory>;
|
||||
|
||||
export default meta;
|
||||
|
||||
type Story = StoryObj<typeof meta>;
|
||||
|
||||
export const Default: Story = {
|
||||
render: () => (
|
||||
<KcPageStory
|
||||
kcContext={{
|
||||
pageId: "applications.ftl",
|
||||
applications: {
|
||||
applications: [
|
||||
{
|
||||
realmRolesAvailable: [
|
||||
{
|
||||
name: "realmRoleName1",
|
||||
description: "realm role description 1"
|
||||
},
|
||||
{
|
||||
name: "realmRoleName2",
|
||||
description: "realm role description 2"
|
||||
}
|
||||
],
|
||||
resourceRolesAvailable: {
|
||||
resource1: [
|
||||
{
|
||||
roleName: "Resource Role Name 1",
|
||||
roleDescription: "Resource role 1 description",
|
||||
clientName: "Client Name 1",
|
||||
clientId: "client1"
|
||||
}
|
||||
],
|
||||
resource2: [
|
||||
{
|
||||
roleName: "Resource Role Name 2",
|
||||
clientName: "Client Name 1",
|
||||
clientId: "client1"
|
||||
}
|
||||
]
|
||||
},
|
||||
additionalGrants: ["grant1", "grant2"],
|
||||
clientScopesGranted: ["scope1", "scope2"],
|
||||
effectiveUrl: "#",
|
||||
client: {
|
||||
clientId: "application1",
|
||||
name: "Application 1",
|
||||
consentRequired: true
|
||||
}
|
||||
},
|
||||
{
|
||||
realmRolesAvailable: [
|
||||
{
|
||||
name: "Realm Role Name 1"
|
||||
}
|
||||
],
|
||||
resourceRolesAvailable: {},
|
||||
additionalGrants: [],
|
||||
clientScopesGranted: [],
|
||||
effectiveUrl: "#",
|
||||
client: {
|
||||
clientId: "application2",
|
||||
name: "Application 2"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}}
|
||||
/>
|
||||
)
|
||||
};
|
@ -212,7 +212,7 @@ export const WithErrorMessage: Story = {
|
||||
<KcPageStory
|
||||
kcContext={{
|
||||
message: {
|
||||
summary: "The time allotted for the connection has elapsed.<br/>The login process will restart from the beginning.",
|
||||
summary: "The time allotted for the connection has elapsed. The login process will restart from the beginning.",
|
||||
type: "error"
|
||||
}
|
||||
}}
|
||||
|
@ -1,7 +1,6 @@
|
||||
import React from "react";
|
||||
import type { Meta, StoryObj } from "@storybook/react";
|
||||
import { createKcPageStory } from "../KcPageStory";
|
||||
import type { Attribute } from "../../../dist/login";
|
||||
|
||||
const { KcPageStory } = createKcPageStory({ pageId: "register.ftl" });
|
||||
|
||||
@ -49,89 +48,28 @@ export const WithEmailAlreadyExists: Story = {
|
||||
)
|
||||
};
|
||||
|
||||
export const WithRestrictedToMITStudents: Story = {
|
||||
render: () => (
|
||||
<KcPageStory
|
||||
kcContext={{
|
||||
profile: {
|
||||
attributesByName: {
|
||||
email: {
|
||||
validators: {
|
||||
pattern: {
|
||||
pattern: "^[^@]+@([^.]+\\.)*((mit\\.edu)|(berkeley\\.edu))$",
|
||||
"error-message": "${profile.attributes.email.pattern.error}"
|
||||
}
|
||||
},
|
||||
annotations: {
|
||||
inputHelperTextBefore: "${profile.attributes.email.inputHelperTextBefore}"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"x-keycloakify": {
|
||||
realmMessageBundleUserProfile: {
|
||||
"${profile.attributes.email.inputHelperTextBefore}": "Please use your MIT or Berkeley email.",
|
||||
"${profile.attributes.email.pattern.error}":
|
||||
"This is not an MIT (<strong>@mit.edu</strong>) nor a Berkeley (<strong>@berkeley.edu</strong>) email."
|
||||
}
|
||||
}
|
||||
}}
|
||||
/>
|
||||
)
|
||||
};
|
||||
|
||||
export const WithFavoritePet: Story = {
|
||||
render: () => (
|
||||
<KcPageStory
|
||||
kcContext={{
|
||||
profile: {
|
||||
attributesByName: {
|
||||
favoritePet: {
|
||||
name: "favorite-pet",
|
||||
displayName: "${profile.attributes.favoritePet}",
|
||||
validators: {
|
||||
options: {
|
||||
options: ["cat", "dog", "fish"]
|
||||
}
|
||||
},
|
||||
annotations: {
|
||||
inputOptionLabelsI18nPrefix: "profile.attributes.favoritePet.options"
|
||||
},
|
||||
required: false,
|
||||
readOnly: false
|
||||
} satisfies Attribute
|
||||
}
|
||||
},
|
||||
"x-keycloakify": {
|
||||
realmMessageBundleUserProfile: {
|
||||
"${profile.attributes.favoritePet}": "Favorite Pet",
|
||||
"${profile.attributes.favoritePet.options.cat}": "Fluffy Cat",
|
||||
"${profile.attributes.favoritePet.options.dog}": "Loyal Dog",
|
||||
"${profile.attributes.favoritePet.options.fish}": "Peaceful Fish"
|
||||
}
|
||||
}
|
||||
}}
|
||||
/>
|
||||
)
|
||||
};
|
||||
|
||||
export const WithEmailAsUsername: Story = {
|
||||
render: () => (
|
||||
<KcPageStory
|
||||
kcContext={{
|
||||
realm: {
|
||||
registrationEmailAsUsername: true
|
||||
},
|
||||
profile: {
|
||||
attributesByName: {
|
||||
username: undefined
|
||||
}
|
||||
}
|
||||
}}
|
||||
/>
|
||||
)
|
||||
};
|
||||
|
||||
export const WithoutPassword: Story = {
|
||||
render: () => (
|
||||
<KcPageStory
|
||||
kcContext={{
|
||||
passwordRequired: false
|
||||
}}
|
||||
/>
|
||||
)
|
||||
};
|
||||
|
||||
export const WithRecaptcha: Story = {
|
||||
render: () => (
|
||||
<KcPageStory
|
||||
@ -159,6 +97,31 @@ export const WithRecaptchaFrench: Story = {
|
||||
)
|
||||
};
|
||||
|
||||
export const WithPresets: Story = {
|
||||
render: () => (
|
||||
<KcPageStory
|
||||
kcContext={{
|
||||
profile: {
|
||||
attributesByName: {
|
||||
firstName: {
|
||||
value: "Max"
|
||||
},
|
||||
lastName: {
|
||||
value: "Mustermann"
|
||||
},
|
||||
email: {
|
||||
value: "max.mustermann@gmail.com"
|
||||
},
|
||||
username: {
|
||||
value: "max.mustermann"
|
||||
}
|
||||
}
|
||||
}
|
||||
}}
|
||||
/>
|
||||
)
|
||||
};
|
||||
|
||||
export const WithPasswordMinLength8: Story = {
|
||||
render: () => (
|
||||
<KcPageStory
|
||||
@ -170,16 +133,3 @@ export const WithPasswordMinLength8: Story = {
|
||||
/>
|
||||
)
|
||||
};
|
||||
|
||||
export const WithTermsAcceptance: Story = {
|
||||
render: () => (
|
||||
<KcPageStory
|
||||
kcContext={{
|
||||
termsAcceptanceRequired: true,
|
||||
"x-keycloakify": {
|
||||
realmMessageBundleTermsText: "<a href='https://example.com/terms'>Service Terms of Use</a>"
|
||||
}
|
||||
}}
|
||||
/>
|
||||
)
|
||||
};
|
||||
|
@ -396,7 +396,6 @@ describe("css replacer", () => {
|
||||
}
|
||||
`,
|
||||
cssFileRelativeDirPath: "assets/",
|
||||
isAccountV3: false,
|
||||
buildContext: {
|
||||
urlPathname: undefined
|
||||
}
|
||||
@ -435,7 +434,6 @@ describe("css replacer", () => {
|
||||
}
|
||||
`,
|
||||
cssFileRelativeDirPath: "assets/",
|
||||
isAccountV3: false,
|
||||
buildContext: {
|
||||
urlPathname: "/a/b/"
|
||||
}
|
||||
@ -474,7 +472,6 @@ describe("css replacer", () => {
|
||||
}
|
||||
`,
|
||||
cssFileRelativeDirPath: undefined,
|
||||
isAccountV3: false,
|
||||
buildContext: {
|
||||
urlPathname: "/a/b/"
|
||||
}
|
||||
@ -513,7 +510,6 @@ describe("css replacer", () => {
|
||||
}
|
||||
`,
|
||||
cssFileRelativeDirPath: undefined,
|
||||
isAccountV3: false,
|
||||
buildContext: {
|
||||
urlPathname: undefined
|
||||
}
|
||||
|
Reference in New Issue
Block a user