import * as fs from "fs"; import { join as pathJoin, dirname as pathDirname } from "path"; import { assert } from "tsafe/assert"; import { Reflect } from "tsafe/Reflect"; import type { BuildOptions } from "../BuildOptions"; import { type ThemeType, retrocompatPostfix, accountV1 } from "../../constants"; import { bringInAccountV1 } from "./bringInAccountV1"; export type BuildOptionsLike = { groupId: string; artifactId: string; themeVersion: string; cacheDirPath: string; keycloakifyBuildDirPath: string; themeNames: string[]; doBuildRetrocompatAccountTheme: boolean; }; { const buildOptions = Reflect(); assert(); } export async function generateJavaStackFiles(params: { implementedThemeTypes: Record; buildOptions: BuildOptionsLike; }): Promise<{ jarFilePath: string; }> { const { implementedThemeTypes, buildOptions } = params; { const { pomFileCode } = (function generatePomFileCode(): { pomFileCode: string; } { const pomFileCode = [ ``, ``, ` 4.0.0`, ` ${buildOptions.groupId}`, ` ${buildOptions.artifactId}`, ` ${buildOptions.themeVersion}`, ` ${buildOptions.artifactId}`, ` `, ` jar`, ` `, ` UTF-8`, ` `, ` `, ` `, ` `, ` org.apache.maven.plugins`, ` maven-shade-plugin`, ` 3.5.1`, ` `, ` `, ` package`, ` `, ` shade`, ` `, ` `, ` `, ` `, ` `, ` `, ` `, ` `, ` io.phasetwo.keycloak`, ` keycloak-account-v1`, ` 0.1`, ` `, ` `, `` ].join("\n"); return { pomFileCode }; })(); fs.writeFileSync(pathJoin(buildOptions.keycloakifyBuildDirPath, "pom.xml"), Buffer.from(pomFileCode, "utf8")); } if (implementedThemeTypes.account) { await bringInAccountV1({ buildOptions }); } { const themeManifestFilePath = pathJoin(buildOptions.keycloakifyBuildDirPath, "src", "main", "resources", "META-INF", "keycloak-themes.json"); try { fs.mkdirSync(pathDirname(themeManifestFilePath)); } catch {} fs.writeFileSync( themeManifestFilePath, Buffer.from( JSON.stringify( { "themes": [ ...(!implementedThemeTypes.account ? [] : [ { "name": accountV1, "types": ["account"] } ]), ...buildOptions.themeNames .map(themeName => [ { "name": themeName, "types": Object.entries(implementedThemeTypes) .filter(([, isImplemented]) => isImplemented) .map(([themeType]) => themeType) }, ...(!implementedThemeTypes.account || !buildOptions.doBuildRetrocompatAccountTheme ? [] : [ { "name": `${themeName}${retrocompatPostfix}`, "types": ["account"] } ]) ]) .flat() ] }, null, 2 ), "utf8" ) ); } return { "jarFilePath": pathJoin(buildOptions.keycloakifyBuildDirPath, "target", `${buildOptions.artifactId}-${buildOptions.themeVersion}.jar`) }; }