keycloak_theme/src/bin/shared/downloadKeycloakDefaultTheme.ts

253 lines
9.2 KiB
TypeScript
Raw Normal View History

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";
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-06-09 09:15:16 +02:00
export type BuildContextLike = {
cacheDirPath: string;
npmWorkspaceRootDirPath: 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 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
let kcNodeModulesKeepFilePaths: string[] | undefined = undefined;
let kcNodeModulesKeepFilePaths_lastAccountV1: string[] | undefined = undefined;
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,
npmWorkspaceRootDirPath: buildContext.npmWorkspaceRootDirPath,
2024-05-24 17:26:38 +02:00
uniqueIdOfOnOnArchiveFile: "downloadKeycloakDefaultTheme",
onArchiveFile: async params => {
const fileRelativePath = pathRelative("theme", params.fileRelativePath);
if (fileRelativePath.startsWith("..")) {
2024-05-24 17:26:38 +02:00
return;
}
2024-05-24 17:26:38 +02:00
const { readFile, writeFile } = params;
2024-05-24 17:26:38 +02:00
skip_keycloak_v2: {
if (!fileRelativePath.startsWith(pathJoin("keycloak.v2"))) {
2024-05-24 17:26:38 +02:00
break skip_keycloak_v2;
}
2024-05-24 17:26:38 +02:00
return;
}
2024-05-24 17:26:38 +02:00
last_account_v1_transformations: {
if (lastKeycloakVersionWithAccountV1 !== keycloakVersion) {
break last_account_v1_transformations;
}
skip_web_modules: {
2024-05-20 15:48:51 +02:00
if (
!fileRelativePath.startsWith(
pathJoin("keycloak", "common", "resources", "web_modules")
)
2024-05-20 15:48:51 +02:00
) {
break skip_web_modules;
}
2024-05-24 17:26:38 +02:00
return;
}
skip_lib: {
if (
!fileRelativePath.startsWith(
pathJoin("keycloak", "common", "resources", "lib")
)
) {
break skip_lib;
}
return;
}
skip_node_modules: {
if (
!fileRelativePath.startsWith(
pathJoin("keycloak", "common", "resources", "node_modules")
)
) {
break skip_node_modules;
}
if (kcNodeModulesKeepFilePaths_lastAccountV1 === undefined) {
kcNodeModulesKeepFilePaths_lastAccountV1 = [
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-Bold-webfont.woff2"
),
pathJoin(
"patternfly",
"dist",
"fonts",
"OpenSans-Light-webfont.woff2"
),
pathJoin(
"patternfly",
"dist",
"fonts",
"OpenSans-Semibold-webfont.woff2"
)
];
}
for (const keepPath of kcNodeModulesKeepFilePaths_lastAccountV1) {
if (fileRelativePath.endsWith(keepPath)) {
break skip_node_modules;
}
}
return;
}
patch_account_css: {
2024-05-24 17:26:38 +02:00
if (
fileRelativePath !==
pathJoin("keycloak", "account", "resources", "css", "account.css")
2024-05-24 17:26:38 +02:00
) {
break patch_account_css;
}
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-24 17:26:38 +02:00
skip_unused_resources: {
if (keycloakVersion !== "24.0.4") {
break skip_unused_resources;
}
skip_node_modules: {
if (
!fileRelativePath.startsWith(
pathJoin("keycloak", "common", "resources", "node_modules")
)
) {
break skip_node_modules;
}
if (kcNodeModulesKeepFilePaths === undefined) {
kcNodeModulesKeepFilePaths = [
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"
),
pathJoin(
"patternfly",
"dist",
"fonts",
"fontawesome-webfont.woff2"
),
pathJoin("jquery", "dist", "jquery.min.js")
];
}
for (const keepPath of kcNodeModulesKeepFilePaths) {
if (fileRelativePath.endsWith(keepPath)) {
break skip_node_modules;
}
}
return;
}
skip_vendor: {
if (
!fileRelativePath.startsWith(
pathJoin("keycloak", "common", "resources", "vendor")
)
) {
break skip_vendor;
}
return;
}
skip_rollup_config: {
if (
fileRelativePath !==
pathJoin("keycloak", "common", "resources", "rollup.config.js")
) {
break skip_rollup_config;
}
return;
}
}
2024-05-24 17:26:38 +02:00
await writeFile({ fileRelativePath });
}
});
2024-05-24 17:26:38 +02:00
return { defaultThemeDirPath: extractedDirPath };
}