Cherrypick what resource from the default theme we keep
This commit is contained in:
@ -3,7 +3,6 @@ import { type BuildContext } from "./buildContext";
|
|||||||
import { assert } from "tsafe/assert";
|
import { assert } from "tsafe/assert";
|
||||||
import { lastKeycloakVersionWithAccountV1 } from "./constants";
|
import { lastKeycloakVersionWithAccountV1 } from "./constants";
|
||||||
import { downloadAndExtractArchive } from "../tools/downloadAndExtractArchive";
|
import { downloadAndExtractArchive } from "../tools/downloadAndExtractArchive";
|
||||||
import { isInside } from "../tools/isInside";
|
|
||||||
|
|
||||||
export type BuildContextLike = {
|
export type BuildContextLike = {
|
||||||
cacheDirPath: string;
|
cacheDirPath: string;
|
||||||
@ -18,27 +17,25 @@ export async function downloadKeycloakDefaultTheme(params: {
|
|||||||
}): Promise<{ defaultThemeDirPath: string }> {
|
}): Promise<{ defaultThemeDirPath: string }> {
|
||||||
const { keycloakVersion, buildContext } = params;
|
const { keycloakVersion, buildContext } = params;
|
||||||
|
|
||||||
|
let kcNodeModulesKeepFilePaths: string[] | undefined = undefined;
|
||||||
|
let kcNodeModulesKeepFilePaths_lastAccountV1: string[] | undefined = undefined;
|
||||||
|
|
||||||
const { extractedDirPath } = await downloadAndExtractArchive({
|
const { extractedDirPath } = await downloadAndExtractArchive({
|
||||||
url: `https://repo1.maven.org/maven2/org/keycloak/keycloak-themes/${keycloakVersion}/keycloak-themes-${keycloakVersion}.jar`,
|
url: `https://repo1.maven.org/maven2/org/keycloak/keycloak-themes/${keycloakVersion}/keycloak-themes-${keycloakVersion}.jar`,
|
||||||
cacheDirPath: buildContext.cacheDirPath,
|
cacheDirPath: buildContext.cacheDirPath,
|
||||||
npmWorkspaceRootDirPath: buildContext.npmWorkspaceRootDirPath,
|
npmWorkspaceRootDirPath: buildContext.npmWorkspaceRootDirPath,
|
||||||
uniqueIdOfOnOnArchiveFile: "downloadKeycloakDefaultTheme",
|
uniqueIdOfOnOnArchiveFile: "downloadKeycloakDefaultTheme",
|
||||||
onArchiveFile: async params => {
|
onArchiveFile: async params => {
|
||||||
if (!isInside({ dirPath: "theme", filePath: params.fileRelativePath })) {
|
const fileRelativePath = pathRelative("theme", params.fileRelativePath);
|
||||||
|
|
||||||
|
if (fileRelativePath.startsWith("..")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { readFile, writeFile } = params;
|
const { readFile, writeFile } = params;
|
||||||
|
|
||||||
const fileRelativePath = pathRelative("theme", params.fileRelativePath);
|
|
||||||
|
|
||||||
skip_keycloak_v2: {
|
skip_keycloak_v2: {
|
||||||
if (
|
if (!fileRelativePath.startsWith(pathJoin("keycloak.v2"))) {
|
||||||
!isInside({
|
|
||||||
dirPath: pathJoin("keycloak.v2"),
|
|
||||||
filePath: fileRelativePath
|
|
||||||
})
|
|
||||||
) {
|
|
||||||
break skip_keycloak_v2;
|
break skip_keycloak_v2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,6 +47,84 @@ export async function downloadKeycloakDefaultTheme(params: {
|
|||||||
break last_account_v1_transformations;
|
break last_account_v1_transformations;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
skip_web_modules: {
|
||||||
|
if (
|
||||||
|
!fileRelativePath.startsWith(
|
||||||
|
pathJoin("keycloak", "common", "resources", "web_modules")
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
break skip_web_modules;
|
||||||
|
}
|
||||||
|
|
||||||
|
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: {
|
patch_account_css: {
|
||||||
if (
|
if (
|
||||||
fileRelativePath !==
|
fileRelativePath !==
|
||||||
@ -70,69 +145,6 @@ export async function downloadKeycloakDefaultTheme(params: {
|
|||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
skip_web_modules: {
|
|
||||||
if (
|
|
||||||
!isInside({
|
|
||||||
dirPath: pathJoin(
|
|
||||||
"keycloak",
|
|
||||||
"common",
|
|
||||||
"resources",
|
|
||||||
"web_modules"
|
|
||||||
),
|
|
||||||
filePath: fileRelativePath
|
|
||||||
})
|
|
||||||
) {
|
|
||||||
break skip_web_modules;
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
skip_unused_node_modules: {
|
|
||||||
const nodeModulesDirPath = pathJoin(
|
|
||||||
"keycloak",
|
|
||||||
"common",
|
|
||||||
"resources",
|
|
||||||
"node_modules"
|
|
||||||
);
|
|
||||||
|
|
||||||
if (
|
|
||||||
!isInside({
|
|
||||||
dirPath: nodeModulesDirPath,
|
|
||||||
filePath: fileRelativePath
|
|
||||||
})
|
|
||||||
) {
|
|
||||||
break skip_unused_node_modules;
|
|
||||||
}
|
|
||||||
|
|
||||||
const toKeepPrefixes = [
|
|
||||||
...[
|
|
||||||
"patternfly.min.css",
|
|
||||||
"patternfly-additions.min.css",
|
|
||||||
"patternfly-additions.min.css"
|
|
||||||
].map(fileBasename =>
|
|
||||||
pathJoin(
|
|
||||||
nodeModulesDirPath,
|
|
||||||
"patternfly",
|
|
||||||
"dist",
|
|
||||||
"css",
|
|
||||||
fileBasename
|
|
||||||
)
|
|
||||||
),
|
|
||||||
pathJoin(nodeModulesDirPath, "patternfly", "dist", "fonts")
|
|
||||||
];
|
|
||||||
|
|
||||||
if (
|
|
||||||
toKeepPrefixes.find(prefix =>
|
|
||||||
fileRelativePath.startsWith(prefix)
|
|
||||||
) !== undefined
|
|
||||||
) {
|
|
||||||
break skip_unused_node_modules;
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
skip_unused_resources: {
|
skip_unused_resources: {
|
||||||
@ -140,61 +152,76 @@ export async function downloadKeycloakDefaultTheme(params: {
|
|||||||
break skip_unused_resources;
|
break skip_unused_resources;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const dirBasename of [
|
skip_node_modules: {
|
||||||
"@patternfly-v5",
|
|
||||||
"@rollup",
|
|
||||||
"rollup",
|
|
||||||
"react",
|
|
||||||
"react-dom",
|
|
||||||
"shx",
|
|
||||||
".pnpm"
|
|
||||||
]) {
|
|
||||||
if (
|
if (
|
||||||
isInside({
|
!fileRelativePath.startsWith(
|
||||||
dirPath: pathJoin(
|
pathJoin("keycloak", "common", "resources", "node_modules")
|
||||||
"keycloak",
|
)
|
||||||
"common",
|
|
||||||
"resources",
|
|
||||||
"node_modules",
|
|
||||||
dirBasename
|
|
||||||
),
|
|
||||||
filePath: fileRelativePath
|
|
||||||
})
|
|
||||||
) {
|
) {
|
||||||
return;
|
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"
|
||||||
|
),
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const dirBasename of ["react", "react-dom"]) {
|
|
||||||
if (
|
|
||||||
isInside({
|
|
||||||
dirPath: pathJoin(
|
|
||||||
"keycloak",
|
|
||||||
"common",
|
|
||||||
"resources",
|
|
||||||
"vendor",
|
|
||||||
dirBasename
|
|
||||||
),
|
|
||||||
filePath: fileRelativePath
|
|
||||||
})
|
|
||||||
) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
skip_vendor: {
|
||||||
|
if (
|
||||||
|
!fileRelativePath.startsWith(
|
||||||
|
pathJoin("keycloak", "common", "resources", "vendor")
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
break skip_vendor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
skip_rollup_config: {
|
||||||
if (
|
if (
|
||||||
isInside({
|
fileRelativePath !==
|
||||||
dirPath: pathJoin(
|
pathJoin("keycloak", "common", "resources", "rollup.config.js")
|
||||||
"keycloak",
|
|
||||||
"common",
|
|
||||||
"resources",
|
|
||||||
"node_modules",
|
|
||||||
"@patternfly",
|
|
||||||
"react-core"
|
|
||||||
),
|
|
||||||
filePath: fileRelativePath
|
|
||||||
})
|
|
||||||
) {
|
) {
|
||||||
|
break skip_rollup_config;
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user