2024-05-15 05:14:01 +02:00
|
|
|
import { transformCodebase } from "../tools/transformCodebase";
|
2024-02-05 08:52:58 +01:00
|
|
|
import { join as pathJoin } from "path";
|
2024-05-19 10:46:26 +02:00
|
|
|
import { downloadKeycloakDefaultTheme } from "./downloadKeycloakDefaultTheme";
|
2024-05-15 05:14:01 +02:00
|
|
|
import { resources_common, type ThemeType } from "./constants";
|
|
|
|
import type { BuildOptions } from "./buildOptions";
|
2023-10-02 22:49:04 +02:00
|
|
|
import { assert } from "tsafe/assert";
|
2023-04-19 05:04:11 +02:00
|
|
|
import * as crypto from "crypto";
|
2024-05-15 05:14:01 +02:00
|
|
|
import { rmSync } from "../tools/fs.rmSync";
|
2023-04-18 03:10:29 +02:00
|
|
|
|
2023-09-03 23:26:34 +02:00
|
|
|
export type BuildOptionsLike = {
|
|
|
|
cacheDirPath: string;
|
2024-02-11 18:28:58 +01:00
|
|
|
npmWorkspaceRootDirPath: string;
|
2023-09-03 23:26:34 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
assert<BuildOptions extends BuildOptionsLike ? true : false>();
|
2023-04-18 03:10:29 +02:00
|
|
|
|
2024-02-05 08:52:58 +01:00
|
|
|
export async function downloadKeycloakStaticResources(params: {
|
|
|
|
themeType: ThemeType;
|
|
|
|
themeDirPath: string;
|
|
|
|
keycloakVersion: string;
|
|
|
|
buildOptions: BuildOptionsLike;
|
|
|
|
}) {
|
2023-11-26 15:07:27 +01:00
|
|
|
const { themeType, themeDirPath, keycloakVersion, buildOptions } = params;
|
|
|
|
|
2023-04-19 05:04:11 +02:00
|
|
|
const tmpDirPath = pathJoin(
|
2024-05-17 00:54:54 +02:00
|
|
|
buildOptions.cacheDirPath,
|
2024-05-20 15:48:51 +02:00
|
|
|
`downloadKeycloakStaticResources_tmp_${crypto
|
|
|
|
.createHash("sha256")
|
|
|
|
.update(`${themeType}-${keycloakVersion}`)
|
|
|
|
.digest("hex")
|
|
|
|
.slice(0, 8)}`
|
2023-04-19 05:04:11 +02:00
|
|
|
);
|
2023-04-18 03:10:29 +02:00
|
|
|
|
2024-05-19 10:46:26 +02:00
|
|
|
await downloadKeycloakDefaultTheme({
|
2023-04-18 03:10:29 +02:00
|
|
|
keycloakVersion,
|
2024-05-20 15:48:51 +02:00
|
|
|
destDirPath: tmpDirPath,
|
2023-09-03 23:26:34 +02:00
|
|
|
buildOptions
|
2023-04-18 03:10:29 +02:00
|
|
|
});
|
|
|
|
|
2023-09-03 07:14:57 +02:00
|
|
|
const resourcesPath = pathJoin(themeDirPath, themeType, "resources");
|
|
|
|
|
2023-04-18 03:10:29 +02:00
|
|
|
transformCodebase({
|
2024-05-20 15:48:51 +02:00
|
|
|
srcDirPath: pathJoin(tmpDirPath, "keycloak", themeType, "resources"),
|
|
|
|
destDirPath: resourcesPath
|
2023-04-18 03:10:29 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
transformCodebase({
|
2024-05-20 15:48:51 +02:00
|
|
|
srcDirPath: pathJoin(tmpDirPath, "keycloak", "common", "resources"),
|
|
|
|
destDirPath: pathJoin(resourcesPath, resources_common)
|
2023-04-18 03:10:29 +02:00
|
|
|
});
|
|
|
|
|
2024-05-20 15:48:51 +02:00
|
|
|
rmSync(tmpDirPath, { recursive: true });
|
2023-11-26 15:07:27 +01:00
|
|
|
}
|