54 lines
1.8 KiB
TypeScript
Raw Normal View History

2024-05-12 20:47:03 +02:00
import { type ThemeType } from "../../constants";
import { join as pathJoin } from "path";
2024-01-30 06:38:26 +01:00
import type { BuildOptions } from "../buildOptions";
2024-05-12 20:47:03 +02:00
import { assert } from "tsafe/assert";
import { generateSrcMainResources } from "./generateSrcMainResources";
import { generateThemeVariations } from "./generateThemeVariants";
2022-08-16 14:41:06 +07:00
2023-08-21 05:54:17 +02:00
export type BuildOptionsLike = {
2024-01-30 07:10:53 +01:00
bundler: "vite" | "webpack";
2024-05-12 20:47:03 +02:00
themeNames: string[];
2023-08-21 05:54:17 +02:00
extraThemeProperties: string[] | undefined;
themeVersion: string;
2023-09-03 21:02:51 +02:00
loginThemeResourcesFromKeycloakVersion: string;
2023-09-03 23:26:34 +02:00
keycloakifyBuildDirPath: string;
reactAppBuildDirPath: string;
cacheDirPath: string;
2024-01-30 07:10:53 +01:00
assetsDirPath: string;
urlPathname: string | undefined;
2024-02-11 18:28:58 +01:00
npmWorkspaceRootDirPath: string;
2023-08-21 05:54:17 +02:00
};
2022-08-16 14:41:06 +07:00
2023-04-01 13:31:35 +02:00
assert<BuildOptions extends BuildOptionsLike ? true : false>();
2021-03-22 20:54:28 +01:00
export async function generateTheme(params: {
2023-06-21 18:06:12 +02:00
themeSrcDirPath: string;
keycloakifySrcDirPath: string;
2022-08-16 14:41:06 +07:00
buildOptions: BuildOptionsLike;
keycloakifyVersion: string;
}): Promise<{ implementedThemeTypes: Record<ThemeType | "email", boolean> }> {
2024-05-12 20:47:03 +02:00
const { themeSrcDirPath, keycloakifySrcDirPath, buildOptions, keycloakifyVersion } = params;
2024-05-12 20:47:03 +02:00
const [themeName, ...themeVariantNames] = buildOptions.themeNames;
2021-02-21 18:55:06 +01:00
2024-05-12 20:47:03 +02:00
const { implementedThemeTypes } = await generateSrcMainResources({
themeName,
"srcMainResourcesDirPath": pathJoin(buildOptions.keycloakifyBuildDirPath, "src", "main", "resources"),
themeSrcDirPath,
keycloakifySrcDirPath,
keycloakifyVersion,
buildOptions
});
2022-08-16 14:41:06 +07:00
2024-05-12 20:47:03 +02:00
for (const themeVariantName of themeVariantNames) {
generateThemeVariations({
2024-01-31 21:56:46 +01:00
themeName,
2024-05-12 20:47:03 +02:00
themeVariantName,
implementedThemeTypes,
2023-09-03 23:26:34 +02:00
buildOptions
});
2024-02-05 08:52:58 +01:00
}
return { implementedThemeTypes };
2021-02-21 18:55:06 +01:00
}