keycloakify 11.3.0-rc.4 → 11.3.0-rc.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,15 +0,0 @@
1
- import type { BuildContext } from "./buildContext";
2
- export type BuildContextLike = {
3
- projectDirPath: string;
4
- themeNames: string[];
5
- environmentVariables: {
6
- name: string;
7
- default: string;
8
- }[];
9
- themeSrcDirPath: string;
10
- implementedThemeTypes: Pick<BuildContext["implementedThemeTypes"], "login" | "account">;
11
- packageJsonFilePath: string;
12
- };
13
- export declare function generateKcGenTs(params: {
14
- buildContext: BuildContextLike;
15
- }): Promise<void>;
@@ -1,175 +0,0 @@
1
- import { assert, type Equals } from "tsafe/assert";
2
- import { id } from "tsafe/id";
3
- import type { BuildContext } from "./buildContext";
4
- import * as fs from "fs/promises";
5
- import { join as pathJoin } from "path";
6
- import { existsAsync } from "../tools/fs.existsAsync";
7
- import { z } from "zod";
8
-
9
- export type BuildContextLike = {
10
- projectDirPath: string;
11
- themeNames: string[];
12
- environmentVariables: { name: string; default: string }[];
13
- themeSrcDirPath: string;
14
- implementedThemeTypes: Pick<
15
- BuildContext["implementedThemeTypes"],
16
- "login" | "account"
17
- >;
18
- packageJsonFilePath: string;
19
- };
20
-
21
- assert<BuildContext extends BuildContextLike ? true : false>();
22
-
23
- export async function generateKcGenTs(params: {
24
- buildContext: BuildContextLike;
25
- }): Promise<void> {
26
- const { buildContext } = params;
27
-
28
- const isReactProject: boolean = await (async () => {
29
- const parsedPackageJson = await (async () => {
30
- type ParsedPackageJson = {
31
- dependencies?: Record<string, string>;
32
- devDependencies?: Record<string, string>;
33
- };
34
-
35
- const zParsedPackageJson = (() => {
36
- type TargetType = ParsedPackageJson;
37
-
38
- const zTargetType = z.object({
39
- dependencies: z.record(z.string()).optional(),
40
- devDependencies: z.record(z.string()).optional()
41
- });
42
-
43
- assert<Equals<z.infer<typeof zTargetType>, TargetType>>();
44
-
45
- return id<z.ZodType<TargetType>>(zTargetType);
46
- })();
47
-
48
- return zParsedPackageJson.parse(
49
- JSON.parse(
50
- (await fs.readFile(buildContext.packageJsonFilePath)).toString("utf8")
51
- )
52
- );
53
- })();
54
-
55
- return (
56
- {
57
- ...parsedPackageJson.dependencies,
58
- ...parsedPackageJson.devDependencies
59
- }.react !== undefined
60
- );
61
- })();
62
-
63
- const filePath = pathJoin(
64
- buildContext.themeSrcDirPath,
65
- `kc.gen.ts${isReactProject ? "x" : ""}`
66
- );
67
-
68
- const currentContent = (await existsAsync(filePath))
69
- ? await fs.readFile(filePath)
70
- : undefined;
71
-
72
- const hasLoginTheme = buildContext.implementedThemeTypes.login.isImplemented;
73
- const hasAccountTheme = buildContext.implementedThemeTypes.account.isImplemented;
74
-
75
- const newContent = Buffer.from(
76
- [
77
- `/* prettier-ignore-start */`,
78
- ``,
79
- `/* eslint-disable */`,
80
- ``,
81
- `// @ts-nocheck`,
82
- ``,
83
- `// noinspection JSUnusedGlobalSymbols`,
84
- ``,
85
- `// This file is auto-generated by Keycloakify`,
86
- ``,
87
- isReactProject && `import { lazy, Suspense, type ReactNode } from "react";`,
88
- ``,
89
- `export type ThemeName = ${buildContext.themeNames.map(themeName => `"${themeName}"`).join(" | ")};`,
90
- ``,
91
- `export const themeNames: ThemeName[] = [${buildContext.themeNames.map(themeName => `"${themeName}"`).join(", ")}];`,
92
- ``,
93
- `export type KcEnvName = ${buildContext.environmentVariables.length === 0 ? "never" : buildContext.environmentVariables.map(({ name }) => `"${name}"`).join(" | ")};`,
94
- ``,
95
- `export const kcEnvNames: KcEnvName[] = [${buildContext.environmentVariables.map(({ name }) => `"${name}"`).join(", ")}];`,
96
- ``,
97
- `export const kcEnvDefaults: Record<KcEnvName, string> = ${JSON.stringify(
98
- Object.fromEntries(
99
- buildContext.environmentVariables.map(
100
- ({ name, default: defaultValue }) => [name, defaultValue]
101
- )
102
- ),
103
- null,
104
- 2
105
- )};`,
106
- ``,
107
- `export type KcContext =`,
108
- hasLoginTheme && ` | import("./login/KcContext").KcContext`,
109
- hasAccountTheme && ` | import("./account/KcContext").KcContext`,
110
- ` ;`,
111
- ``,
112
- `declare global {`,
113
- ` interface Window {`,
114
- ` kcContext?: KcContext;`,
115
- ` }`,
116
- `}`,
117
- ``,
118
- ...(!isReactProject
119
- ? []
120
- : [
121
- hasLoginTheme &&
122
- `export const KcLoginPage = lazy(() => import("./login/KcPage"));`,
123
- hasAccountTheme &&
124
- `export const KcAccountPage = lazy(() => import("./account/KcPage"));`,
125
- ``,
126
- `export function KcPage(`,
127
- ` props: {`,
128
- ` kcContext: KcContext;`,
129
- ` fallback?: ReactNode;`,
130
- ` }`,
131
- `) {`,
132
- ` const { kcContext, fallback } = props;`,
133
- ` return (`,
134
- ` <Suspense fallback={fallback}>`,
135
- ` {(() => {`,
136
- ` switch (kcContext.themeType) {`,
137
- hasLoginTheme &&
138
- ` case "login": return <KcLoginPage kcContext={kcContext} />;`,
139
- hasAccountTheme &&
140
- ` case "account": return <KcAccountPage kcContext={kcContext} />;`,
141
- ` }`,
142
- ` })()}`,
143
- ` </Suspense>`,
144
- ` );`,
145
- `}`
146
- ]),
147
- ``,
148
- `/* prettier-ignore-end */`,
149
- ``
150
- ]
151
- .filter(item => typeof item === "string")
152
- .join("\n"),
153
- "utf8"
154
- );
155
-
156
- if (currentContent !== undefined && currentContent.equals(newContent)) {
157
- return;
158
- }
159
-
160
- await fs.writeFile(filePath, newContent);
161
-
162
- delete_legacy_file: {
163
- if (!isReactProject) {
164
- break delete_legacy_file;
165
- }
166
-
167
- const legacyFilePath = filePath.replace(/tsx$/, "ts");
168
-
169
- if (!(await existsAsync(legacyFilePath))) {
170
- break delete_legacy_file;
171
- }
172
-
173
- await fs.unlink(legacyFilePath);
174
- }
175
- }