keycloak_theme/src/bin/keycloakify/generateTheme/downloadKeycloakStaticResources.ts

50 lines
1.6 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";
import { downloadBuiltinKeycloakTheme } from "../../download-builtin-keycloak-theme";
import { resources_common, type ThemeType } from "../../constants";
2024-01-30 06:38:26 +01:00
import { BuildOptions } from "../buildOptions";
2023-10-02 22:49:04 +02:00
import { assert } from "tsafe/assert";
import * as crypto from "crypto";
2024-02-05 08:52:58 +01:00
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(
themeDirPath,
`tmp_suLeKsxId_${crypto.createHash("sha256").update(`${themeType}-${keycloakVersion}`).digest("hex").slice(0, 8)}`
);
await downloadBuiltinKeycloakTheme({
keycloakVersion,
2023-09-03 23:26:34 +02:00
"destDirPath": tmpDirPath,
buildOptions
});
const resourcesPath = pathJoin(themeDirPath, themeType, "resources");
transformCodebase({
"srcDirPath": pathJoin(tmpDirPath, "keycloak", themeType, "resources"),
2023-11-26 15:07:27 +01:00
"destDirPath": resourcesPath
});
transformCodebase({
"srcDirPath": pathJoin(tmpDirPath, "keycloak", "common", "resources"),
2024-02-05 08:52:58 +01:00
"destDirPath": pathJoin(resourcesPath, resources_common)
});
2024-02-05 08:52:58 +01:00
rmSync(tmpDirPath, { "recursive": true, "force": true });
2023-11-26 15:07:27 +01:00
}