2024-05-24 17:26:38 +02:00
|
|
|
import { join as pathJoin, relative as pathRelative } from "path";
|
2024-05-15 05:14:01 +02:00
|
|
|
import { type BuildOptions } from "./buildOptions";
|
|
|
|
import { assert } from "tsafe/assert";
|
2024-05-19 10:46:26 +02:00
|
|
|
import { lastKeycloakVersionWithAccountV1 } from "./constants";
|
2024-05-24 17:26:38 +02:00
|
|
|
import { downloadAndExtractArchive } from "../tools/downloadAndExtractArchive";
|
|
|
|
import { isInside } from "../tools/isInside";
|
2024-05-15 05:14:01 +02:00
|
|
|
|
|
|
|
export type BuildOptionsLike = {
|
|
|
|
cacheDirPath: string;
|
|
|
|
npmWorkspaceRootDirPath: string;
|
|
|
|
};
|
|
|
|
|
|
|
|
assert<BuildOptions extends BuildOptionsLike ? true : false>();
|
|
|
|
|
2024-05-20 15:48:51 +02:00
|
|
|
export async function downloadKeycloakDefaultTheme(params: {
|
|
|
|
keycloakVersion: string;
|
|
|
|
buildOptions: BuildOptionsLike;
|
2024-05-24 17:26:38 +02:00
|
|
|
}): Promise<{ defaultThemeDirPath: string }> {
|
|
|
|
const { keycloakVersion, buildOptions } = params;
|
|
|
|
|
|
|
|
const { extractedDirPath } = await downloadAndExtractArchive({
|
|
|
|
url: `https://repo1.maven.org/maven2/org/keycloak/keycloak-themes/${keycloakVersion}/keycloak-themes-${keycloakVersion}.jar`,
|
|
|
|
cacheDirPath: buildOptions.cacheDirPath,
|
|
|
|
npmWorkspaceRootDirPath: buildOptions.npmWorkspaceRootDirPath,
|
|
|
|
uniqueIdOfOnOnArchiveFile: "downloadKeycloakDefaultTheme",
|
|
|
|
onArchiveFile: async params => {
|
|
|
|
if (!isInside({ dirPath: "theme", filePath: params.fileRelativePath })) {
|
|
|
|
return;
|
|
|
|
}
|
2024-05-15 05:14:01 +02:00
|
|
|
|
2024-05-24 17:26:38 +02:00
|
|
|
const { readFile, writeFile } = params;
|
2024-05-15 05:14:01 +02:00
|
|
|
|
2024-05-24 17:26:38 +02:00
|
|
|
const fileRelativePath = pathRelative("theme", params.fileRelativePath);
|
2024-05-15 05:14:01 +02:00
|
|
|
|
2024-05-24 17:26:38 +02:00
|
|
|
skip_keycloak_v2: {
|
|
|
|
if (
|
|
|
|
!isInside({
|
|
|
|
dirPath: pathJoin("keycloak.v2"),
|
|
|
|
filePath: fileRelativePath
|
|
|
|
})
|
|
|
|
) {
|
|
|
|
break skip_keycloak_v2;
|
2024-05-15 05:14:01 +02:00
|
|
|
}
|
|
|
|
|
2024-05-24 17:26:38 +02:00
|
|
|
return;
|
|
|
|
}
|
2024-05-15 05:14:01 +02:00
|
|
|
|
2024-05-24 17:26:38 +02:00
|
|
|
last_account_v1_transformations: {
|
|
|
|
if (lastKeycloakVersionWithAccountV1 !== keycloakVersion) {
|
|
|
|
break last_account_v1_transformations;
|
2024-05-15 05:14:01 +02:00
|
|
|
}
|
|
|
|
|
2024-05-24 17:26:38 +02:00
|
|
|
patch_account_css: {
|
2024-05-20 15:48:51 +02:00
|
|
|
if (
|
2024-05-24 17:26:38 +02:00
|
|
|
fileRelativePath !==
|
|
|
|
pathJoin("keycloak", "account", "resources", "css", "account.css")
|
2024-05-20 15:48:51 +02:00
|
|
|
) {
|
2024-05-24 17:26:38 +02:00
|
|
|
break patch_account_css;
|
2024-05-15 05:14:01 +02:00
|
|
|
}
|
|
|
|
|
2024-05-24 17:26:38 +02:00
|
|
|
await writeFile({
|
|
|
|
fileRelativePath,
|
|
|
|
modifiedData: Buffer.from(
|
|
|
|
(await readFile())
|
|
|
|
.toString("utf8")
|
|
|
|
.replace("top: -34px;", "top: -34px !important;"),
|
|
|
|
"utf8"
|
|
|
|
)
|
2024-05-20 15:48:51 +02:00
|
|
|
});
|
2024-05-15 05:14:01 +02:00
|
|
|
|
2024-05-24 17:26:38 +02:00
|
|
|
return;
|
2024-05-15 05:14:01 +02:00
|
|
|
}
|
|
|
|
|
2024-05-24 17:26:38 +02:00
|
|
|
skip_unused_node_modules: {
|
2024-05-25 12:19:03 +02:00
|
|
|
const nodeModulesDirPath = pathJoin(
|
2024-05-20 15:48:51 +02:00
|
|
|
"keycloak",
|
|
|
|
"common",
|
|
|
|
"resources",
|
|
|
|
"node_modules"
|
|
|
|
);
|
2024-05-15 05:14:01 +02:00
|
|
|
|
2024-05-25 12:19:03 +02:00
|
|
|
if (
|
|
|
|
!isInside({
|
|
|
|
dirPath: nodeModulesDirPath,
|
|
|
|
filePath: fileRelativePath
|
|
|
|
})
|
|
|
|
) {
|
2024-05-24 17:26:38 +02:00
|
|
|
break skip_unused_node_modules;
|
2024-05-15 05:14:01 +02:00
|
|
|
}
|
|
|
|
|
2024-05-24 17:26:38 +02:00
|
|
|
const toKeepPrefixes = [
|
|
|
|
...[
|
|
|
|
"patternfly.min.css",
|
|
|
|
"patternfly-additions.min.css",
|
|
|
|
"patternfly-additions.min.css"
|
|
|
|
].map(fileBasename =>
|
2024-05-25 12:19:03 +02:00
|
|
|
pathJoin(
|
|
|
|
nodeModulesDirPath,
|
|
|
|
"patternfly",
|
|
|
|
"dist",
|
|
|
|
"css",
|
|
|
|
fileBasename
|
|
|
|
)
|
2024-05-24 17:26:38 +02:00
|
|
|
),
|
2024-05-25 12:19:03 +02:00
|
|
|
pathJoin(nodeModulesDirPath, "patternfly", "dist", "fonts")
|
2024-05-20 15:48:51 +02:00
|
|
|
];
|
2024-05-15 05:14:01 +02:00
|
|
|
|
2024-05-24 17:26:38 +02:00
|
|
|
if (
|
|
|
|
toKeepPrefixes.find(prefix =>
|
|
|
|
fileRelativePath.startsWith(prefix)
|
|
|
|
) !== undefined
|
|
|
|
) {
|
|
|
|
break skip_unused_node_modules;
|
2024-05-15 05:14:01 +02:00
|
|
|
}
|
|
|
|
|
2024-05-24 17:26:38 +02:00
|
|
|
return;
|
2024-05-15 05:14:01 +02:00
|
|
|
}
|
|
|
|
}
|
2024-05-24 17:26:38 +02:00
|
|
|
|
2024-05-25 12:19:03 +02:00
|
|
|
skip_unused_resources: {
|
|
|
|
if (keycloakVersion !== "24.0.4") {
|
|
|
|
break skip_unused_resources;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const dirBasename of [
|
|
|
|
"@patternfly-v5",
|
|
|
|
"@rollup",
|
|
|
|
"rollup",
|
|
|
|
"react",
|
|
|
|
"react-dom",
|
|
|
|
"shx",
|
|
|
|
".pnpm"
|
|
|
|
]) {
|
|
|
|
if (
|
|
|
|
isInside({
|
|
|
|
dirPath: pathJoin(
|
|
|
|
"keycloak",
|
|
|
|
"common",
|
|
|
|
"resources",
|
|
|
|
"node_modules",
|
|
|
|
dirBasename
|
|
|
|
),
|
|
|
|
filePath: fileRelativePath
|
|
|
|
})
|
|
|
|
) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const dirBasename of ["react", "react-dom"]) {
|
|
|
|
if (
|
|
|
|
isInside({
|
|
|
|
dirPath: pathJoin(
|
|
|
|
"keycloak",
|
|
|
|
"common",
|
|
|
|
"resources",
|
|
|
|
"vendor",
|
|
|
|
dirBasename
|
|
|
|
),
|
|
|
|
filePath: fileRelativePath
|
|
|
|
})
|
|
|
|
) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
|
|
|
isInside({
|
|
|
|
dirPath: pathJoin(
|
|
|
|
"keycloak",
|
|
|
|
"common",
|
|
|
|
"resources",
|
|
|
|
"node_modules",
|
|
|
|
"@patternfly",
|
|
|
|
"react-core"
|
|
|
|
),
|
|
|
|
filePath: fileRelativePath
|
|
|
|
})
|
|
|
|
) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-24 17:26:38 +02:00
|
|
|
await writeFile({ fileRelativePath });
|
2024-05-15 05:14:01 +02:00
|
|
|
}
|
|
|
|
});
|
2024-05-24 17:26:38 +02:00
|
|
|
|
|
|
|
return { defaultThemeDirPath: extractedDirPath };
|
2024-05-15 05:14:01 +02:00
|
|
|
}
|