import * as url from "url"; import * as fs from "fs"; import { join as pathJoin, dirname as pathDirname } from "path"; export function generateJavaStackFiles(params: { version: string; themeName: string; homepage?: string; keycloakThemeBuildingDirPath: string; doBundleEmailTemplate: boolean; }): { jarFilePath: string; } { const { themeName, version, homepage, keycloakThemeBuildingDirPath, doBundleEmailTemplate } = params; { const { pomFileCode } = (function generatePomFileCode(): { pomFileCode: string; } { const groupId = (() => { const fallbackGroupId = `there.was.no.homepage.field.in.the.package.json.${themeName}`; return ( (!homepage ? fallbackGroupId : url .parse(homepage) .host?.replace(/:[0-9]+$/, "") ?.split(".") .reverse() .join(".") ?? fallbackGroupId) + ".keycloak" ); })(); const artefactId = `${themeName}-keycloak-theme`; const pomFileCode = [ ``, ``, ` 4.0.0`, ` ${groupId}`, ` ${artefactId}`, ` ${version}`, ` ${artefactId}`, ` `, ``, ].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", ...(doBundleEmailTemplate ? ["email"] : [])], }, ], }, null, 2, ), "utf8", ), ); } return { "jarFilePath": pathJoin(keycloakThemeBuildingDirPath, "target", `${themeName}-${version}.jar`), }; }