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 } from "../../constants"; import { bringInAccountV1, accountV1 } from "./bringInAccountV1"; export type BuildOptionsLike = { groupId: string; artifactId: string; themeVersion: string; cacheDirPath: string; keycloakifyBuildDirPath: string; themeNames: string[]; }; { 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`, ` `, ` 17`, ` UTF-8`, ` 999.0.0-SNAPSHOT`, ` 32.0.0-jre`, ` 1.18.28`, ` 1.1.1`, ` `, ` `, ` `, ` `, ` maven-compiler-plugin`, ` 3.11.0`, ` `, ` \${java.version}`, ` \${java.version}`, ` -Xlint:unchecked`, ` -Xlint:deprecation`, ` false`, ` `, ` `, ` com.google.auto.service`, ` auto-service`, ` \${auto-service.version}`, ` `, ` `, ` org.projectlombok`, ` lombok`, ` \${lombok.version}`, ` `, ` `, ` `, ` `, ` `, ` org.apache.maven.plugins`, ` maven-jar-plugin`, ` 3.2.0`, ` `, ` `, ` `, ` `, ` `, ` `, ` `, ` `, ` `, ` `, ` `, ` com.spotify.fmt`, ` fmt-maven-plugin`, ` 2.20`, ` `, ` `, ` `, ` `, ` `, ` org.projectlombok`, ` lombok`, ` \${lombok.version}`, ` provided`, ` `, ` `, ` com.google.auto.service`, ` auto-service`, ` \${auto-service.version}`, ` provided`, ` `, ` `, ` org.keycloak`, ` keycloak-server-spi`, ` \${keycloak.version}`, ` provided`, ` `, ` `, ` org.keycloak`, ` keycloak-server-spi-private`, ` \${keycloak.version}`, ` provided`, ` `, ` `, ` org.keycloak`, ` keycloak-services`, ` \${keycloak.version}`, ` provided`, ` `, ` `, ` jakarta.ws.rs`, ` jakarta.ws.rs-api`, ` 3.1.0`, ` provided`, ` `, ` `, ` com.google.guava`, ` guava`, ` \${guava.version}`, ` provided`, ` `, ` `, `` ].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 ? [] : [ { "name": `${themeName}_retrocompat`, "types": ["account"] } ]) ]) .flat() ] }, null, 2 ), "utf8" ) ); } return { "jarFilePath": pathJoin(buildOptions.keycloakifyBuildDirPath, "target", `${buildOptions.artifactId}-${buildOptions.themeVersion}.jar`) }; }