92 lines
3.7 KiB
TypeScript
Raw Normal View History

import { assert } from "tsafe/assert";
import { exclude } from "tsafe/exclude";
2024-05-20 15:48:51 +02:00
import {
keycloakAccountV1Versions,
keycloakThemeAdditionalInfoExtensionVersions
} from "./extensionVersions";
import { getKeycloakVersionRangeForJar } from "./getKeycloakVersionRangeForJar";
2024-06-09 09:15:16 +02:00
import { buildJar, BuildContextLike as BuildContextLike_buildJar } from "./buildJar";
import type { BuildContext } from "../../shared/buildContext";
2024-05-17 05:13:41 +02:00
import { getJarFileBasename } from "../../shared/getJarFileBasename";
2024-06-10 07:57:12 +02:00
import { readMetaInfKeycloakThemes_fromResourcesDirPath } from "../../shared/metaInfKeycloakThemes";
import { accountV1ThemeName } from "../../shared/constants";
2024-05-13 00:40:16 +02:00
2024-06-09 09:15:16 +02:00
export type BuildContextLike = BuildContextLike_buildJar & {
2024-05-13 00:40:16 +02:00
keycloakifyBuildDirPath: string;
};
2024-06-09 09:15:16 +02:00
assert<BuildContext extends BuildContextLike ? true : false>();
2024-05-20 15:48:51 +02:00
export async function buildJars(params: {
2024-06-10 07:57:12 +02:00
resourcesDirPath: string;
onlyBuildJarFileBasename: string | undefined;
2024-06-09 09:15:16 +02:00
buildContext: BuildContextLike;
2024-05-20 15:48:51 +02:00
}): Promise<void> {
const { onlyBuildJarFileBasename, resourcesDirPath, buildContext } = params;
2024-06-10 07:57:12 +02:00
const doesImplementAccountTheme = readMetaInfKeycloakThemes_fromResourcesDirPath({
2024-06-10 09:28:31 +02:00
resourcesDirPath
}).themes.some(({ name }) => name === accountV1ThemeName);
await Promise.all(
keycloakAccountV1Versions
.map(keycloakAccountV1Version =>
keycloakThemeAdditionalInfoExtensionVersions
.map(keycloakThemeAdditionalInfoExtensionVersion => {
const keycloakVersionRange = getKeycloakVersionRangeForJar({
2024-05-12 21:23:20 +02:00
doesImplementAccountTheme,
keycloakAccountV1Version,
keycloakThemeAdditionalInfoExtensionVersion
});
if (keycloakVersionRange === undefined) {
return undefined;
}
return {
keycloakThemeAdditionalInfoExtensionVersion,
2024-05-20 15:48:51 +02:00
keycloakVersionRange
};
})
2024-05-20 15:48:51 +02:00
.filter(exclude(undefined))
.map(
({
keycloakThemeAdditionalInfoExtensionVersion,
2024-05-20 15:48:51 +02:00
keycloakVersionRange
}) => {
const { jarFileBasename } = getJarFileBasename({
keycloakVersionRange
});
if (
onlyBuildJarFileBasename !== undefined &&
onlyBuildJarFileBasename !== jarFileBasename
) {
return undefined;
}
2024-05-20 15:48:51 +02:00
return {
keycloakThemeAdditionalInfoExtensionVersion,
jarFileBasename
};
}
)
.filter(exclude(undefined))
2024-05-20 15:48:51 +02:00
.map(
({
keycloakThemeAdditionalInfoExtensionVersion,
jarFileBasename
}) =>
buildJar({
jarFileBasename,
keycloakAccountV1Version,
keycloakThemeAdditionalInfoExtensionVersion,
2024-06-10 07:57:12 +02:00
resourcesDirPath,
2024-06-09 09:15:16 +02:00
buildContext
2024-05-20 15:48:51 +02:00
})
)
)
.flat()
);
}