96 lines
2.6 KiB
TypeScript
96 lines
2.6 KiB
TypeScript
|
|
||
|
import * as url from "url";
|
||
|
import * as fs from "fs";
|
||
|
import { join as pathJoin, dirname as pathDirname } from "path";
|
||
|
|
||
|
export type ParsedPackageJson = {
|
||
|
name: string;
|
||
|
version: string;
|
||
|
homepage?: string;
|
||
|
};
|
||
|
|
||
|
export function generateJavaStackFiles(
|
||
|
params: {
|
||
|
parsedPackageJson: ParsedPackageJson;
|
||
|
keycloakThemeBuildingDirPath: string;
|
||
|
}
|
||
|
): void {
|
||
|
|
||
|
const { parsedPackageJson, keycloakThemeBuildingDirPath } = params;
|
||
|
|
||
|
{
|
||
|
|
||
|
const { pomFileCode } = (function generatePomFileCode(): { pomFileCode: string; } {
|
||
|
|
||
|
const { name, version, homepage } = parsedPackageJson;
|
||
|
|
||
|
const groupId = (() => {
|
||
|
|
||
|
const fallbackGroupId = `there.was.no.homepage.field.in.the.package.json.${name}.keycloak`;
|
||
|
|
||
|
return !homepage ?
|
||
|
fallbackGroupId :
|
||
|
url.parse(homepage).host?.split(".").reverse().join(".") ?? fallbackGroupId;
|
||
|
|
||
|
})();
|
||
|
|
||
|
const artefactId = `${name}-keycloak-theme`;
|
||
|
|
||
|
const pomFileCode = [
|
||
|
`<?xml version="1.0"?>`,
|
||
|
`<project xmlns="http://maven.apache.org/POM/4.0.0"`,
|
||
|
` xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"`,
|
||
|
` xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">`,
|
||
|
` <modelVersion>4.0.0</modelVersion>`,
|
||
|
` <groupId>${groupId}</groupId>`,
|
||
|
` <artifactId>${artefactId}</artifactId>`,
|
||
|
` <version>${version}</version>`,
|
||
|
` <name>${artefactId}</name>`,
|
||
|
` <description />`,
|
||
|
`</project>`
|
||
|
].join("\n");
|
||
|
|
||
|
return { pomFileCode };
|
||
|
|
||
|
})();
|
||
|
|
||
|
fs.writeFileSync(
|
||
|
keycloakThemeBuildingDirPath,
|
||
|
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": "onyxia",
|
||
|
"types": ["login", "email", "account", "welcome"]
|
||
|
}
|
||
|
]
|
||
|
}, null, 2),
|
||
|
"utf8"
|
||
|
)
|
||
|
);
|
||
|
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|