2024-05-24 17:26:38 +02:00
|
|
|
import { join as pathJoin, relative as pathRelative } from "path";
|
2024-06-09 09:15:16 +02:00
|
|
|
import { type BuildContext } from "./buildContext";
|
2024-05-15 05:14:01 +02:00
|
|
|
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";
|
2024-05-15 05:14:01 +02:00
|
|
|
|
2024-06-09 09:15:16 +02:00
|
|
|
export type BuildContextLike = {
|
2024-05-15 05:14:01 +02:00
|
|
|
cacheDirPath: string;
|
2024-06-23 21:23:06 +02:00
|
|
|
fetchOptions: BuildContext["fetchOptions"];
|
2024-05-15 05:14:01 +02:00
|
|
|
};
|
|
|
|
|
2024-06-09 09:15:16 +02:00
|
|
|
assert<BuildContext extends BuildContextLike ? true : false>();
|
2024-05-15 05:14:01 +02:00
|
|
|
|
2024-05-20 15:48:51 +02:00
|
|
|
export async function downloadKeycloakDefaultTheme(params: {
|
|
|
|
keycloakVersion: string;
|
2024-06-09 09:15:16 +02:00
|
|
|
buildContext: BuildContextLike;
|
2024-05-24 17:26:38 +02:00
|
|
|
}): Promise<{ defaultThemeDirPath: string }> {
|
2024-06-09 09:15:16 +02:00
|
|
|
const { keycloakVersion, buildContext } = params;
|
2024-05-24 17:26:38 +02:00
|
|
|
|
2024-07-11 17:49:58 +02:00
|
|
|
let kcNodeModulesKeepFilePaths: Set<string> | undefined = undefined;
|
|
|
|
let kcNodeModulesKeepFilePaths_lastAccountV1: Set<string> | undefined = undefined;
|
2024-06-15 17:32:58 +02:00
|
|
|
|
2024-05-24 17:26:38 +02:00
|
|
|
const { extractedDirPath } = await downloadAndExtractArchive({
|
|
|
|
url: `https://repo1.maven.org/maven2/org/keycloak/keycloak-themes/${keycloakVersion}/keycloak-themes-${keycloakVersion}.jar`,
|
2024-06-09 09:15:16 +02:00
|
|
|
cacheDirPath: buildContext.cacheDirPath,
|
2024-06-23 21:23:06 +02:00
|
|
|
fetchOptions: buildContext.fetchOptions,
|
2024-07-08 00:21:40 +02:00
|
|
|
uniqueIdOfOnArchiveFile: "downloadKeycloakDefaultTheme",
|
2024-05-24 17:26:38 +02:00
|
|
|
onArchiveFile: async params => {
|
2024-06-15 17:32:58 +02:00
|
|
|
const fileRelativePath = pathRelative("theme", params.fileRelativePath);
|
|
|
|
|
|
|
|
if (fileRelativePath.startsWith("..")) {
|
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
|
|
|
const { readFile, writeFile } = params;
|
2024-05-15 05:14:01 +02:00
|
|
|
|
2024-05-24 17:26:38 +02:00
|
|
|
skip_keycloak_v2: {
|
2024-06-15 17:32:58 +02:00
|
|
|
if (!fileRelativePath.startsWith(pathJoin("keycloak.v2"))) {
|
2024-05-24 17:26:38 +02:00
|
|
|
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-06-15 17:32:58 +02:00
|
|
|
skip_web_modules: {
|
2024-05-20 15:48:51 +02:00
|
|
|
if (
|
2024-06-15 17:32:58 +02:00
|
|
|
!fileRelativePath.startsWith(
|
|
|
|
pathJoin("keycloak", "common", "resources", "web_modules")
|
|
|
|
)
|
2024-05-20 15:48:51 +02:00
|
|
|
) {
|
2024-06-15 17:32:58 +02:00
|
|
|
break skip_web_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-06-15 17:32:58 +02:00
|
|
|
skip_lib: {
|
2024-05-25 20:01:59 +02:00
|
|
|
if (
|
2024-06-15 17:32:58 +02:00
|
|
|
!fileRelativePath.startsWith(
|
|
|
|
pathJoin("keycloak", "common", "resources", "lib")
|
|
|
|
)
|
2024-05-25 20:01:59 +02:00
|
|
|
) {
|
2024-06-15 17:32:58 +02:00
|
|
|
break skip_lib;
|
2024-05-25 20:01:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-06-15 17:32:58 +02:00
|
|
|
skip_node_modules: {
|
2024-07-11 17:49:58 +02:00
|
|
|
const nodeModulesRelativeDirPath = pathJoin(
|
|
|
|
"keycloak",
|
|
|
|
"common",
|
|
|
|
"resources",
|
|
|
|
"node_modules"
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!fileRelativePath.startsWith(nodeModulesRelativeDirPath)) {
|
2024-06-15 17:32:58 +02:00
|
|
|
break skip_node_modules;
|
2024-05-15 05:14:01 +02:00
|
|
|
}
|
|
|
|
|
2024-06-15 17:32:58 +02:00
|
|
|
if (kcNodeModulesKeepFilePaths_lastAccountV1 === undefined) {
|
2024-07-11 17:49:58 +02:00
|
|
|
kcNodeModulesKeepFilePaths_lastAccountV1 = new Set([
|
2024-06-15 17:32:58 +02:00
|
|
|
pathJoin("patternfly", "dist", "css", "patternfly.min.css"),
|
2024-05-25 12:19:03 +02:00
|
|
|
pathJoin(
|
|
|
|
"patternfly",
|
|
|
|
"dist",
|
|
|
|
"css",
|
2024-06-15 17:32:58 +02:00
|
|
|
"patternfly-additions.min.css"
|
|
|
|
),
|
|
|
|
pathJoin(
|
|
|
|
"patternfly",
|
|
|
|
"dist",
|
|
|
|
"fonts",
|
|
|
|
"OpenSans-Regular-webfont.woff2"
|
|
|
|
),
|
|
|
|
pathJoin(
|
|
|
|
"patternfly",
|
|
|
|
"dist",
|
|
|
|
"fonts",
|
|
|
|
"OpenSans-Bold-webfont.woff2"
|
|
|
|
),
|
|
|
|
pathJoin(
|
|
|
|
"patternfly",
|
|
|
|
"dist",
|
|
|
|
"fonts",
|
|
|
|
"OpenSans-Light-webfont.woff2"
|
|
|
|
),
|
|
|
|
pathJoin(
|
|
|
|
"patternfly",
|
|
|
|
"dist",
|
|
|
|
"fonts",
|
|
|
|
"OpenSans-Semibold-webfont.woff2"
|
2024-06-18 16:41:09 +02:00
|
|
|
),
|
|
|
|
pathJoin(
|
|
|
|
"patternfly",
|
|
|
|
"dist",
|
|
|
|
"fonts",
|
|
|
|
"PatternFlyIcons-webfont.ttf"
|
|
|
|
),
|
|
|
|
pathJoin(
|
|
|
|
"patternfly",
|
|
|
|
"dist",
|
|
|
|
"fonts",
|
|
|
|
"PatternFlyIcons-webfont.woff"
|
2024-05-25 12:19:03 +02:00
|
|
|
)
|
2024-07-11 17:49:58 +02:00
|
|
|
]);
|
2024-06-15 17:32:58 +02:00
|
|
|
}
|
|
|
|
|
2024-07-11 17:49:58 +02:00
|
|
|
const fileRelativeToNodeModulesPath = fileRelativePath.substring(
|
|
|
|
nodeModulesRelativeDirPath.length + 1
|
|
|
|
);
|
|
|
|
|
|
|
|
if (
|
|
|
|
kcNodeModulesKeepFilePaths_lastAccountV1.has(
|
|
|
|
fileRelativeToNodeModulesPath
|
|
|
|
)
|
|
|
|
) {
|
|
|
|
break skip_node_modules;
|
2024-06-15 17:32:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2024-05-15 05:14:01 +02:00
|
|
|
|
2024-06-15 17:32:58 +02:00
|
|
|
patch_account_css: {
|
2024-05-24 17:26:38 +02:00
|
|
|
if (
|
2024-06-15 17:32:58 +02:00
|
|
|
fileRelativePath !==
|
|
|
|
pathJoin("keycloak", "account", "resources", "css", "account.css")
|
2024-05-24 17:26:38 +02:00
|
|
|
) {
|
2024-06-15 17:32:58 +02:00
|
|
|
break patch_account_css;
|
2024-05-15 05:14:01 +02:00
|
|
|
}
|
|
|
|
|
2024-06-15 17:32:58 +02:00
|
|
|
await writeFile({
|
|
|
|
fileRelativePath,
|
|
|
|
modifiedData: Buffer.from(
|
|
|
|
(await readFile())
|
|
|
|
.toString("utf8")
|
|
|
|
.replace("top: -34px;", "top: -34px !important;"),
|
|
|
|
"utf8"
|
|
|
|
)
|
|
|
|
});
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2024-06-15 17:32:58 +02:00
|
|
|
skip_node_modules: {
|
2024-07-11 17:49:58 +02:00
|
|
|
const nodeModulesRelativeDirPath = pathJoin(
|
|
|
|
"keycloak",
|
|
|
|
"common",
|
|
|
|
"resources",
|
|
|
|
"node_modules"
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!fileRelativePath.startsWith(nodeModulesRelativeDirPath)) {
|
2024-06-15 17:32:58 +02:00
|
|
|
break skip_node_modules;
|
2024-05-25 12:19:03 +02:00
|
|
|
}
|
2024-06-15 17:32:58 +02:00
|
|
|
|
|
|
|
if (kcNodeModulesKeepFilePaths === undefined) {
|
2024-07-11 17:49:58 +02:00
|
|
|
kcNodeModulesKeepFilePaths = new Set([
|
2024-06-15 17:32:58 +02:00
|
|
|
pathJoin("@patternfly", "patternfly", "patternfly.min.css"),
|
|
|
|
pathJoin("patternfly", "dist", "css", "patternfly.min.css"),
|
|
|
|
pathJoin(
|
|
|
|
"patternfly",
|
|
|
|
"dist",
|
|
|
|
"css",
|
|
|
|
"patternfly-additions.min.css"
|
|
|
|
),
|
|
|
|
pathJoin(
|
|
|
|
"patternfly",
|
|
|
|
"dist",
|
|
|
|
"fonts",
|
|
|
|
"OpenSans-Regular-webfont.woff2"
|
|
|
|
),
|
|
|
|
pathJoin(
|
|
|
|
"patternfly",
|
|
|
|
"dist",
|
|
|
|
"fonts",
|
|
|
|
"OpenSans-Light-webfont.woff2"
|
|
|
|
),
|
2024-06-17 00:07:38 +02:00
|
|
|
pathJoin(
|
|
|
|
"patternfly",
|
|
|
|
"dist",
|
|
|
|
"fonts",
|
|
|
|
"OpenSans-Bold-webfont.woff2"
|
|
|
|
),
|
|
|
|
pathJoin(
|
|
|
|
"patternfly",
|
|
|
|
"dist",
|
|
|
|
"fonts",
|
|
|
|
"OpenSans-Bold-webfont.woff"
|
|
|
|
),
|
|
|
|
pathJoin(
|
|
|
|
"patternfly",
|
|
|
|
"dist",
|
|
|
|
"fonts",
|
|
|
|
"OpenSans-Bold-webfont.ttf"
|
|
|
|
),
|
2024-06-15 17:32:58 +02:00
|
|
|
pathJoin(
|
|
|
|
"patternfly",
|
|
|
|
"dist",
|
|
|
|
"fonts",
|
|
|
|
"fontawesome-webfont.woff2"
|
|
|
|
),
|
2024-06-17 13:26:32 +02:00
|
|
|
pathJoin(
|
|
|
|
"patternfly",
|
|
|
|
"dist",
|
|
|
|
"fonts",
|
|
|
|
"PatternFlyIcons-webfont.ttf"
|
|
|
|
),
|
|
|
|
pathJoin(
|
|
|
|
"patternfly",
|
|
|
|
"dist",
|
|
|
|
"fonts",
|
|
|
|
"PatternFlyIcons-webfont.woff"
|
|
|
|
),
|
2024-07-11 17:49:58 +02:00
|
|
|
pathJoin(
|
|
|
|
"patternfly",
|
|
|
|
"dist",
|
|
|
|
"fonts",
|
|
|
|
"OpenSans-Semibold-webfont.woff2"
|
|
|
|
),
|
2024-07-04 19:26:48 +02:00
|
|
|
pathJoin("patternfly", "dist", "img", "bg-login.jpg"),
|
2024-06-15 17:32:58 +02:00
|
|
|
pathJoin("jquery", "dist", "jquery.min.js")
|
2024-07-11 17:49:58 +02:00
|
|
|
]);
|
2024-06-15 17:32:58 +02:00
|
|
|
}
|
|
|
|
|
2024-07-11 17:49:58 +02:00
|
|
|
const fileRelativeToNodeModulesPath = fileRelativePath.substring(
|
|
|
|
nodeModulesRelativeDirPath.length + 1
|
|
|
|
);
|
|
|
|
|
|
|
|
if (kcNodeModulesKeepFilePaths.has(fileRelativeToNodeModulesPath)) {
|
|
|
|
break skip_node_modules;
|
2024-06-15 17:32:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
2024-05-25 12:19:03 +02:00
|
|
|
}
|
|
|
|
|
2024-06-15 17:32:58 +02:00
|
|
|
skip_vendor: {
|
2024-05-25 12:19:03 +02:00
|
|
|
if (
|
2024-06-15 17:32:58 +02:00
|
|
|
!fileRelativePath.startsWith(
|
|
|
|
pathJoin("keycloak", "common", "resources", "vendor")
|
|
|
|
)
|
2024-05-25 12:19:03 +02:00
|
|
|
) {
|
2024-06-15 17:32:58 +02:00
|
|
|
break skip_vendor;
|
2024-05-25 12:19:03 +02:00
|
|
|
}
|
2024-06-15 17:32:58 +02:00
|
|
|
|
|
|
|
return;
|
2024-05-25 12:19:03 +02:00
|
|
|
}
|
|
|
|
|
2024-06-15 17:32:58 +02:00
|
|
|
skip_rollup_config: {
|
|
|
|
if (
|
|
|
|
fileRelativePath !==
|
|
|
|
pathJoin("keycloak", "common", "resources", "rollup.config.js")
|
|
|
|
) {
|
|
|
|
break skip_rollup_config;
|
|
|
|
}
|
|
|
|
|
2024-05-25 12:19:03 +02:00
|
|
|
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
|
|
|
}
|