import * as fs from "fs"; import { join as pathJoin, dirname as pathDirname } from "path"; import { assert } from "tsafe/assert"; import type { BuildOptions } from "./BuildOptions"; import type { ThemeType } from "./generateFtl"; export type BuildOptionsLike = { themeName: string; extraThemeNames: string[]; groupId: string; artifactId: string; themeVersion: string; }; assert(); export function generateJavaStackFiles(params: { keycloakThemeBuildingDirPath: string; implementedThemeTypes: Record; buildOptions: BuildOptionsLike; }): { jarFilePath: string; } { const { buildOptions: { groupId, themeName, extraThemeNames, themeVersion, artifactId }, keycloakThemeBuildingDirPath, implementedThemeTypes } = params; { const { pomFileCode } = (function generatePomFileCode(): { pomFileCode: string; } { const pomFileCode = [ ``, ``, ` 4.0.0`, ` ${groupId}`, ` ${artifactId}`, ` ${themeVersion}`, ` ${artifactId}`, ` `, `` ].join("\n"); return { pomFileCode }; })(); fs.writeFileSync(pathJoin(keycloakThemeBuildingDirPath, "pom.xml"), Buffer.from(pomFileCode, "utf8")); } { const themeManifestFilePath = pathJoin(keycloakThemeBuildingDirPath, "src", "main", "resources", "META-INF", "keycloak-themes.json"); try { fs.mkdirSync(pathDirname(themeManifestFilePath)); } catch {} fs.writeFileSync( themeManifestFilePath, Buffer.from( JSON.stringify( { "themes": [themeName, ...extraThemeNames].map(themeName => ({ "name": themeName, "types": Object.entries(implementedThemeTypes) .filter(([, isImplemented]) => isImplemented) .map(([themeType]) => themeType) })) }, null, 2 ), "utf8" ) ); } return { "jarFilePath": pathJoin(keycloakThemeBuildingDirPath, "target", `${artifactId}-${themeVersion}.jar`) }; }