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"; export type BuildOptionsLike = { themeName: string; groupId: string; artifactId?: string; version: string; }; { const buildOptions = Reflect(); assert(); } export function generateJavaStackFiles(params: { keycloakThemeBuildingDirPath: string; doBundlesEmailTemplate: boolean; buildOptions: BuildOptionsLike; }): { jarFilePath: string; } { const { buildOptions: { groupId, themeName, version, artifactId }, keycloakThemeBuildingDirPath, doBundlesEmailTemplate } = params; { const { pomFileCode } = (function generatePomFileCode(): { pomFileCode: string; } { const pomFileCode = [ ``, ``, ` 4.0.0`, ` ${groupId}`, ` ${artifactId}`, ` ${version}`, ` ${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": [ { "name": themeName, "types": ["login", ...(doBundlesEmailTemplate ? ["email"] : [])] } ] }, null, 2 ), "utf8" ) ); } return { "jarFilePath": pathJoin(keycloakThemeBuildingDirPath, "target", `${artifactId}-${version}.jar`) }; }