keycloak_theme/src/bin/shared/downloadKeycloakStaticResources.ts

54 lines
1.7 KiB
TypeScript
Raw Normal View History

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";
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";
import * as crypto from "crypto";
import { rmSync } from "../tools/fs.rmSync";
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>();
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;
const tmpDirPath = pathJoin(
buildOptions.cacheDirPath,
2024-05-20 15:48:51 +02:00
`downloadKeycloakStaticResources_tmp_${crypto
.createHash("sha256")
.update(`${themeType}-${keycloakVersion}`)
.digest("hex")
.slice(0, 8)}`
);
2024-05-19 10:46:26 +02:00
await downloadKeycloakDefaultTheme({
keycloakVersion,
2024-05-20 15:48:51 +02:00
destDirPath: tmpDirPath,
2023-09-03 23:26:34 +02:00
buildOptions
});
const resourcesPath = pathJoin(themeDirPath, themeType, "resources");
transformCodebase({
2024-05-20 15:48:51 +02:00
srcDirPath: pathJoin(tmpDirPath, "keycloak", themeType, "resources"),
destDirPath: resourcesPath
});
transformCodebase({
2024-05-20 15:48:51 +02:00
srcDirPath: pathJoin(tmpDirPath, "keycloak", "common", "resources"),
destDirPath: pathJoin(resourcesPath, resources_common)
});
2024-05-20 15:48:51 +02:00
rmSync(tmpDirPath, { recursive: true });
2023-11-26 15:07:27 +01:00
}