2024-05-17 02:05:14 +02:00
|
|
|
import { join as pathJoin, dirname as pathDirname } from "path";
|
|
|
|
import type { ThemeType } from "./constants";
|
|
|
|
import * as fs from "fs";
|
|
|
|
|
|
|
|
export type MetaInfKeycloakTheme = {
|
|
|
|
themes: { name: string; types: (ThemeType | "email")[] }[];
|
|
|
|
};
|
|
|
|
|
2024-05-20 15:48:51 +02:00
|
|
|
export function getMetaInfKeycloakThemesJsonFilePath(params: {
|
|
|
|
keycloakifyBuildDirPath: string;
|
|
|
|
}) {
|
2024-05-17 02:05:14 +02:00
|
|
|
const { keycloakifyBuildDirPath } = params;
|
|
|
|
|
2024-05-20 15:48:51 +02:00
|
|
|
return pathJoin(
|
|
|
|
keycloakifyBuildDirPath,
|
|
|
|
"src",
|
|
|
|
"main",
|
|
|
|
"resources",
|
|
|
|
"META-INF",
|
|
|
|
"keycloak-themes.json"
|
|
|
|
);
|
2024-05-17 02:05:14 +02:00
|
|
|
}
|
|
|
|
|
2024-05-20 15:48:51 +02:00
|
|
|
export function readMetaInfKeycloakThemes(params: {
|
|
|
|
keycloakifyBuildDirPath: string;
|
|
|
|
}): MetaInfKeycloakTheme {
|
2024-05-17 02:05:14 +02:00
|
|
|
const { keycloakifyBuildDirPath } = params;
|
|
|
|
|
2024-05-20 15:48:51 +02:00
|
|
|
return JSON.parse(
|
|
|
|
fs
|
|
|
|
.readFileSync(
|
|
|
|
getMetaInfKeycloakThemesJsonFilePath({
|
|
|
|
keycloakifyBuildDirPath
|
|
|
|
})
|
|
|
|
)
|
|
|
|
.toString("utf8")
|
|
|
|
) as MetaInfKeycloakTheme;
|
2024-05-17 02:05:14 +02:00
|
|
|
}
|
|
|
|
|
2024-05-20 15:48:51 +02:00
|
|
|
export function writeMetaInfKeycloakThemes(params: {
|
|
|
|
keycloakifyBuildDirPath: string;
|
|
|
|
metaInfKeycloakThemes: MetaInfKeycloakTheme;
|
|
|
|
}) {
|
2024-05-17 02:05:14 +02:00
|
|
|
const { keycloakifyBuildDirPath, metaInfKeycloakThemes } = params;
|
|
|
|
|
2024-05-20 15:48:51 +02:00
|
|
|
const metaInfKeycloakThemesJsonPath = getMetaInfKeycloakThemesJsonFilePath({
|
|
|
|
keycloakifyBuildDirPath
|
|
|
|
});
|
2024-05-17 02:05:14 +02:00
|
|
|
|
|
|
|
{
|
|
|
|
const dirPath = pathDirname(metaInfKeycloakThemesJsonPath);
|
|
|
|
if (!fs.existsSync(dirPath)) {
|
2024-05-20 15:48:51 +02:00
|
|
|
fs.mkdirSync(dirPath, { recursive: true });
|
2024-05-17 02:05:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-20 15:48:51 +02:00
|
|
|
fs.writeFileSync(
|
|
|
|
metaInfKeycloakThemesJsonPath,
|
|
|
|
Buffer.from(JSON.stringify(metaInfKeycloakThemes, null, 2), "utf8")
|
|
|
|
);
|
2024-05-17 02:05:14 +02:00
|
|
|
}
|