Compare commits
12 Commits
Author | SHA1 | Date | |
---|---|---|---|
5357626317 | |||
552c95c59e | |||
50590697ca | |||
e261736fa3 | |||
263f55fdd3 | |||
2b7f8a24a3 | |||
dc4eac1a04 | |||
53a427d190 | |||
ae969f91ac | |||
c83319d6f3 | |||
329b4cb0fb | |||
533f5992d1 |
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "keycloakify",
|
"name": "keycloakify",
|
||||||
"version": "11.3.10",
|
"version": "11.3.15",
|
||||||
"description": "Framework to create custom Keycloak UIs",
|
"description": "Framework to create custom Keycloak UIs",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
@ -16,7 +16,7 @@ import { startRebuildOnSrcChange } from "./shared/startRebuildOnSrcChange";
|
|||||||
.filter(
|
.filter(
|
||||||
basename =>
|
basename =>
|
||||||
basename.includes("starter") &&
|
basename.includes("starter") &&
|
||||||
basename.includes("angular") &&
|
basename.includes("keycloakify") &&
|
||||||
fs.statSync(pathJoin(parentDirPath, basename)).isDirectory()
|
fs.statSync(pathJoin(parentDirPath, basename)).isDirectory()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -16,10 +16,20 @@ import { assert, Equals } from "tsafe/assert";
|
|||||||
import type { BuildContext } from "./shared/buildContext";
|
import type { BuildContext } from "./shared/buildContext";
|
||||||
import chalk from "chalk";
|
import chalk from "chalk";
|
||||||
import { runFormat } from "./tools/runFormat";
|
import { runFormat } from "./tools/runFormat";
|
||||||
|
import { maybeDelegateCommandToCustomHandler } from "./shared/customHandler_delegate";
|
||||||
|
|
||||||
export async function command(params: { buildContext: BuildContext }) {
|
export async function command(params: { buildContext: BuildContext }) {
|
||||||
const { buildContext } = params;
|
const { buildContext } = params;
|
||||||
|
|
||||||
|
const { hasBeenHandled } = maybeDelegateCommandToCustomHandler({
|
||||||
|
commandName: "add-story",
|
||||||
|
buildContext
|
||||||
|
});
|
||||||
|
|
||||||
|
if (hasBeenHandled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
console.log(chalk.cyan("Theme type:"));
|
console.log(chalk.cyan("Theme type:"));
|
||||||
|
|
||||||
const themeType = await (async () => {
|
const themeType = await (async () => {
|
||||||
|
@ -4,6 +4,7 @@ import { join as pathJoin } from "path";
|
|||||||
import { existsAsync } from "./tools/fs.existsAsync";
|
import { existsAsync } from "./tools/fs.existsAsync";
|
||||||
import { maybeDelegateCommandToCustomHandler } from "./shared/customHandler_delegate";
|
import { maybeDelegateCommandToCustomHandler } from "./shared/customHandler_delegate";
|
||||||
import { runFormat } from "./tools/runFormat";
|
import { runFormat } from "./tools/runFormat";
|
||||||
|
import * as crypto from "crypto";
|
||||||
|
|
||||||
export async function command(params: { buildContext: BuildContext }) {
|
export async function command(params: { buildContext: BuildContext }) {
|
||||||
const { buildContext } = params;
|
const { buildContext } = params;
|
||||||
@ -19,86 +20,106 @@ export async function command(params: { buildContext: BuildContext }) {
|
|||||||
|
|
||||||
const filePath = pathJoin(buildContext.themeSrcDirPath, `kc.gen.tsx`);
|
const filePath = pathJoin(buildContext.themeSrcDirPath, `kc.gen.tsx`);
|
||||||
|
|
||||||
const currentContent = (await existsAsync(filePath))
|
|
||||||
? await fs.readFile(filePath)
|
|
||||||
: undefined;
|
|
||||||
|
|
||||||
const hasLoginTheme = buildContext.implementedThemeTypes.login.isImplemented;
|
const hasLoginTheme = buildContext.implementedThemeTypes.login.isImplemented;
|
||||||
const hasAccountTheme = buildContext.implementedThemeTypes.account.isImplemented;
|
const hasAccountTheme = buildContext.implementedThemeTypes.account.isImplemented;
|
||||||
|
|
||||||
const newContent = Buffer.from(
|
const newContent = [
|
||||||
[
|
``,
|
||||||
``,
|
`/* eslint-disable */`,
|
||||||
`// This file is auto-generated by Keycloakify, do not modify it manually.`,
|
``,
|
||||||
``,
|
`// @ts-nocheck`,
|
||||||
`import { lazy, Suspense, type ReactNode } from "react";`,
|
``,
|
||||||
``,
|
`// noinspection JSUnusedGlobalSymbols`,
|
||||||
`export type ThemeName = ${buildContext.themeNames.map(themeName => `"${themeName}"`).join(" | ")};`,
|
``,
|
||||||
``,
|
`import { lazy, Suspense, type ReactNode } from "react";`,
|
||||||
`export const themeNames: ThemeName[] = [${buildContext.themeNames.map(themeName => `"${themeName}"`).join(", ")}];`,
|
``,
|
||||||
``,
|
`export type ThemeName = ${buildContext.themeNames.map(themeName => `"${themeName}"`).join(" | ")};`,
|
||||||
`export type KcEnvName = ${buildContext.environmentVariables.length === 0 ? "never" : buildContext.environmentVariables.map(({ name }) => `"${name}"`).join(" | ")};`,
|
``,
|
||||||
``,
|
`export const themeNames: ThemeName[] = [${buildContext.themeNames.map(themeName => `"${themeName}"`).join(", ")}];`,
|
||||||
`export const kcEnvNames: KcEnvName[] = [${buildContext.environmentVariables.map(({ name }) => `"${name}"`).join(", ")}];`,
|
``,
|
||||||
``,
|
`export type KcEnvName = ${buildContext.environmentVariables.length === 0 ? "never" : buildContext.environmentVariables.map(({ name }) => `"${name}"`).join(" | ")};`,
|
||||||
`export const kcEnvDefaults: Record<KcEnvName, string> = ${JSON.stringify(
|
``,
|
||||||
Object.fromEntries(
|
`export const kcEnvNames: KcEnvName[] = [${buildContext.environmentVariables.map(({ name }) => `"${name}"`).join(", ")}];`,
|
||||||
buildContext.environmentVariables.map(
|
``,
|
||||||
({ name, default: defaultValue }) => [name, defaultValue]
|
`export const kcEnvDefaults: Record<KcEnvName, string> = ${JSON.stringify(
|
||||||
)
|
Object.fromEntries(
|
||||||
),
|
buildContext.environmentVariables.map(
|
||||||
null,
|
({ name, default: defaultValue }) => [name, defaultValue]
|
||||||
2
|
)
|
||||||
)};`,
|
),
|
||||||
``,
|
null,
|
||||||
`export type KcContext =`,
|
2
|
||||||
hasLoginTheme && ` | import("./login/KcContext").KcContext`,
|
)};`,
|
||||||
hasAccountTheme && ` | import("./account/KcContext").KcContext`,
|
``,
|
||||||
` ;`,
|
`type KcContext =`,
|
||||||
``,
|
hasLoginTheme && ` | import("./login/KcContext").KcContext`,
|
||||||
`declare global {`,
|
hasAccountTheme && ` | import("./account/KcContext").KcContext`,
|
||||||
` interface Window {`,
|
` ;`,
|
||||||
` kcContext?: KcContext;`,
|
``,
|
||||||
` }`,
|
`declare global {`,
|
||||||
`}`,
|
` interface Window {`,
|
||||||
``,
|
` kcContext?: KcContext;`,
|
||||||
hasLoginTheme &&
|
` }`,
|
||||||
`export const KcLoginPage = lazy(() => import("./login/KcPage"));`,
|
`}`,
|
||||||
hasAccountTheme &&
|
``,
|
||||||
`export const KcAccountPage = lazy(() => import("./account/KcPage"));`,
|
hasLoginTheme &&
|
||||||
``,
|
`export const KcLoginPage = lazy(() => import("./login/KcPage"));`,
|
||||||
`export function KcPage(`,
|
hasAccountTheme &&
|
||||||
` props: {`,
|
`export const KcAccountPage = lazy(() => import("./account/KcPage"));`,
|
||||||
` kcContext: KcContext;`,
|
``,
|
||||||
` fallback?: ReactNode;`,
|
`export function KcPage(`,
|
||||||
` }`,
|
` props: {`,
|
||||||
`) {`,
|
` kcContext: KcContext;`,
|
||||||
` const { kcContext, fallback } = props;`,
|
` fallback?: ReactNode;`,
|
||||||
` return (`,
|
` }`,
|
||||||
` <Suspense fallback={fallback}>`,
|
`) {`,
|
||||||
` {(() => {`,
|
` const { kcContext, fallback } = props;`,
|
||||||
` switch (kcContext.themeType) {`,
|
` return (`,
|
||||||
hasLoginTheme &&
|
` <Suspense fallback={fallback}>`,
|
||||||
` case "login": return <KcLoginPage kcContext={kcContext} />;`,
|
` {(() => {`,
|
||||||
hasAccountTheme &&
|
` switch (kcContext.themeType) {`,
|
||||||
` case "account": return <KcAccountPage kcContext={kcContext} />;`,
|
hasLoginTheme &&
|
||||||
` }`,
|
` case "login": return <KcLoginPage kcContext={kcContext} />;`,
|
||||||
` })()}`,
|
hasAccountTheme &&
|
||||||
` </Suspense>`,
|
` case "account": return <KcAccountPage kcContext={kcContext} />;`,
|
||||||
` );`,
|
` }`,
|
||||||
`}`,
|
` })()}`,
|
||||||
``
|
` </Suspense>`,
|
||||||
]
|
` );`,
|
||||||
.filter(item => typeof item === "string")
|
`}`,
|
||||||
.join("\n"),
|
``
|
||||||
"utf8"
|
]
|
||||||
);
|
.filter(item => typeof item === "string")
|
||||||
|
.join("\n");
|
||||||
|
|
||||||
|
const hash = crypto.createHash("sha256").update(newContent).digest("hex");
|
||||||
|
|
||||||
|
skip_if_no_changes: {
|
||||||
|
if (!(await existsAsync(filePath))) {
|
||||||
|
break skip_if_no_changes;
|
||||||
|
}
|
||||||
|
|
||||||
|
const currentContent = (await fs.readFile(filePath)).toString("utf8");
|
||||||
|
|
||||||
|
if (!currentContent.includes(hash)) {
|
||||||
|
break skip_if_no_changes;
|
||||||
|
}
|
||||||
|
|
||||||
if (currentContent !== undefined && currentContent.equals(newContent)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await fs.writeFile(filePath, newContent);
|
await fs.writeFile(
|
||||||
|
filePath,
|
||||||
|
Buffer.from(
|
||||||
|
[
|
||||||
|
`// This file is auto-generated by the \`update-kc-gen\` command. Do not edit it manually.`,
|
||||||
|
`// Hash: ${hash}`,
|
||||||
|
``,
|
||||||
|
newContent
|
||||||
|
].join("\n"),
|
||||||
|
"utf8"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
runFormat({ packageJsonFilePath: buildContext.packageJsonFilePath });
|
runFormat({ packageJsonFilePath: buildContext.packageJsonFilePath });
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ export declare namespace KcContext {
|
|||||||
showTryAnotherWayLink?: boolean;
|
showTryAnotherWayLink?: boolean;
|
||||||
attemptedUsername?: string;
|
attemptedUsername?: string;
|
||||||
};
|
};
|
||||||
scripts: string[];
|
scripts?: string[];
|
||||||
message?: {
|
message?: {
|
||||||
type: "success" | "warning" | "error" | "info";
|
type: "success" | "warning" | "error" | "info";
|
||||||
summary: string;
|
summary: string;
|
||||||
|
@ -10,7 +10,7 @@ export type KcContextLike = {
|
|||||||
resourcesPath: string;
|
resourcesPath: string;
|
||||||
ssoLoginInOtherTabsUrl: string;
|
ssoLoginInOtherTabsUrl: string;
|
||||||
};
|
};
|
||||||
scripts: string[];
|
scripts?: string[];
|
||||||
};
|
};
|
||||||
|
|
||||||
assert<keyof KcContextLike extends keyof KcContext ? true : false>();
|
assert<keyof KcContextLike extends keyof KcContext ? true : false>();
|
||||||
@ -45,10 +45,12 @@ export function useInitialize(params: {
|
|||||||
type: "module",
|
type: "module",
|
||||||
src: `${url.resourcesPath}/js/menu-button-links.js`
|
src: `${url.resourcesPath}/js/menu-button-links.js`
|
||||||
},
|
},
|
||||||
...scripts.map(src => ({
|
...(scripts === undefined
|
||||||
type: "text/javascript" as const,
|
? []
|
||||||
src
|
: scripts.map(src => ({
|
||||||
})),
|
type: "text/javascript" as const,
|
||||||
|
src
|
||||||
|
}))),
|
||||||
{
|
{
|
||||||
type: "module",
|
type: "module",
|
||||||
textContent: `
|
textContent: `
|
||||||
|
@ -92,7 +92,8 @@ export function createUseI18n<
|
|||||||
|
|
||||||
const styleElement = document.createElement("style");
|
const styleElement = document.createElement("style");
|
||||||
styleElement.attributes.setNamedItem(document.createAttribute(attributeName));
|
styleElement.attributes.setNamedItem(document.createAttribute(attributeName));
|
||||||
(styleElement.textContent = `[data-kc-msg] { display: inline-block; }`), document.head.prepend(styleElement);
|
styleElement.textContent = `[data-kc-msg] { display: inline-block; }`;
|
||||||
|
document.head.prepend(styleElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
const { getI18n } = createGetI18n({ extraLanguageTranslations, messagesByLanguageTag_themeDefined });
|
const { getI18n } = createGetI18n({ extraLanguageTranslations, messagesByLanguageTag_themeDefined });
|
||||||
|
@ -16,6 +16,7 @@ import {
|
|||||||
} from "../bin/shared/buildContext";
|
} from "../bin/shared/buildContext";
|
||||||
import MagicString from "magic-string";
|
import MagicString from "magic-string";
|
||||||
import { command as updateKcGenCommand } from "../bin/update-kc-gen";
|
import { command as updateKcGenCommand } from "../bin/update-kc-gen";
|
||||||
|
import { replaceAll } from "../bin/tools/String.prototype.replaceAll";
|
||||||
|
|
||||||
export namespace keycloakify {
|
export namespace keycloakify {
|
||||||
export type Params = BuildOptions & {
|
export type Params = BuildOptions & {
|
||||||
@ -130,6 +131,8 @@ export function keycloakify(params: keycloakify.Params) {
|
|||||||
await updateKcGenCommand({ buildContext });
|
await updateKcGenCommand({ buildContext });
|
||||||
},
|
},
|
||||||
transform: (code, id) => {
|
transform: (code, id) => {
|
||||||
|
id = replaceAll(id, "/", pathSep);
|
||||||
|
|
||||||
assert(command !== undefined);
|
assert(command !== undefined);
|
||||||
assert(shouldGenerateSourcemap !== undefined);
|
assert(shouldGenerateSourcemap !== undefined);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user