No need to handle non react environement with custom handler support
This commit is contained in:
parent
fed6af4dfe
commit
2dfb4eda9d
@ -1,10 +1,8 @@
|
|||||||
import { assert, type Equals } from "tsafe/assert";
|
import { assert } from "tsafe/assert";
|
||||||
import { id } from "tsafe/id";
|
|
||||||
import type { BuildContext } from "./buildContext";
|
import type { BuildContext } from "./buildContext";
|
||||||
import * as fs from "fs/promises";
|
import * as fs from "fs/promises";
|
||||||
import { join as pathJoin } from "path";
|
import { join as pathJoin } from "path";
|
||||||
import { existsAsync } from "../tools/fs.existsAsync";
|
import { existsAsync } from "../tools/fs.existsAsync";
|
||||||
import { z } from "zod";
|
|
||||||
|
|
||||||
export type BuildContextLike = {
|
export type BuildContextLike = {
|
||||||
projectDirPath: string;
|
projectDirPath: string;
|
||||||
@ -25,45 +23,7 @@ export async function generateKcGenTs(params: {
|
|||||||
}): Promise<void> {
|
}): Promise<void> {
|
||||||
const { buildContext } = params;
|
const { buildContext } = params;
|
||||||
|
|
||||||
const isReactProject: boolean = await (async () => {
|
const filePath = pathJoin(buildContext.themeSrcDirPath, `kc.gen.tsx`);
|
||||||
const parsedPackageJson = await (async () => {
|
|
||||||
type ParsedPackageJson = {
|
|
||||||
dependencies?: Record<string, string>;
|
|
||||||
devDependencies?: Record<string, string>;
|
|
||||||
};
|
|
||||||
|
|
||||||
const zParsedPackageJson = (() => {
|
|
||||||
type TargetType = ParsedPackageJson;
|
|
||||||
|
|
||||||
const zTargetType = z.object({
|
|
||||||
dependencies: z.record(z.string()).optional(),
|
|
||||||
devDependencies: z.record(z.string()).optional()
|
|
||||||
});
|
|
||||||
|
|
||||||
assert<Equals<z.infer<typeof zTargetType>, TargetType>>();
|
|
||||||
|
|
||||||
return id<z.ZodType<TargetType>>(zTargetType);
|
|
||||||
})();
|
|
||||||
|
|
||||||
return zParsedPackageJson.parse(
|
|
||||||
JSON.parse(
|
|
||||||
(await fs.readFile(buildContext.packageJsonFilePath)).toString("utf8")
|
|
||||||
)
|
|
||||||
);
|
|
||||||
})();
|
|
||||||
|
|
||||||
return (
|
|
||||||
{
|
|
||||||
...parsedPackageJson.dependencies,
|
|
||||||
...parsedPackageJson.devDependencies
|
|
||||||
}.react !== undefined
|
|
||||||
);
|
|
||||||
})();
|
|
||||||
|
|
||||||
const filePath = pathJoin(
|
|
||||||
buildContext.themeSrcDirPath,
|
|
||||||
`kc.gen.ts${isReactProject ? "x" : ""}`
|
|
||||||
);
|
|
||||||
|
|
||||||
const currentContent = (await existsAsync(filePath))
|
const currentContent = (await existsAsync(filePath))
|
||||||
? await fs.readFile(filePath)
|
? await fs.readFile(filePath)
|
||||||
@ -84,7 +44,7 @@ export async function generateKcGenTs(params: {
|
|||||||
``,
|
``,
|
||||||
`// This file is auto-generated by Keycloakify`,
|
`// This file is auto-generated by Keycloakify`,
|
||||||
``,
|
``,
|
||||||
isReactProject && `import { lazy, Suspense, type ReactNode } from "react";`,
|
`import { lazy, Suspense, type ReactNode } from "react";`,
|
||||||
``,
|
``,
|
||||||
`export type ThemeName = ${buildContext.themeNames.map(themeName => `"${themeName}"`).join(" | ")};`,
|
`export type ThemeName = ${buildContext.themeNames.map(themeName => `"${themeName}"`).join(" | ")};`,
|
||||||
``,
|
``,
|
||||||
@ -115,9 +75,6 @@ export async function generateKcGenTs(params: {
|
|||||||
` }`,
|
` }`,
|
||||||
`}`,
|
`}`,
|
||||||
``,
|
``,
|
||||||
...(!isReactProject
|
|
||||||
? []
|
|
||||||
: [
|
|
||||||
hasLoginTheme &&
|
hasLoginTheme &&
|
||||||
`export const KcLoginPage = lazy(() => import("./login/KcPage"));`,
|
`export const KcLoginPage = lazy(() => import("./login/KcPage"));`,
|
||||||
hasAccountTheme &&
|
hasAccountTheme &&
|
||||||
@ -142,8 +99,7 @@ export async function generateKcGenTs(params: {
|
|||||||
` })()}`,
|
` })()}`,
|
||||||
` </Suspense>`,
|
` </Suspense>`,
|
||||||
` );`,
|
` );`,
|
||||||
`}`
|
`}`,
|
||||||
]),
|
|
||||||
``,
|
``,
|
||||||
`/* prettier-ignore-end */`,
|
`/* prettier-ignore-end */`,
|
||||||
``
|
``
|
||||||
@ -160,10 +116,6 @@ export async function generateKcGenTs(params: {
|
|||||||
await fs.writeFile(filePath, newContent);
|
await fs.writeFile(filePath, newContent);
|
||||||
|
|
||||||
delete_legacy_file: {
|
delete_legacy_file: {
|
||||||
if (!isReactProject) {
|
|
||||||
break delete_legacy_file;
|
|
||||||
}
|
|
||||||
|
|
||||||
const legacyFilePath = filePath.replace(/tsx$/, "ts");
|
const legacyFilePath = filePath.replace(/tsx$/, "ts");
|
||||||
|
|
||||||
if (!(await existsAsync(legacyFilePath))) {
|
if (!(await existsAsync(legacyFilePath))) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user