keycloak_theme/scripts/build/createPublicDotKeycloakifyDir.ts

74 lines
2.5 KiB
TypeScript
Raw Normal View History

2024-09-08 00:06:47 +02:00
import { join as pathJoin } from "path";
2024-09-08 12:00:07 +02:00
import { downloadKeycloakDefaultTheme } from "../shared/downloadKeycloakDefaultTheme";
2024-09-08 00:06:47 +02:00
import { transformCodebase } from "../../src/bin/tools/transformCodebase";
import { existsAsync } from "../../src/bin/tools/fs.existsAsync";
import { getThisCodebaseRootDirPath } from "../../src/bin/tools/getThisCodebaseRootDirPath";
import { WELL_KNOWN_DIRECTORY_BASE_NAME } from "../../src/bin/shared/constants";
import { assert, type Equals } from "tsafe/assert";
2024-09-08 12:00:07 +02:00
import * as fsPr from "fs/promises";
2024-09-08 00:06:47 +02:00
2024-09-08 12:00:07 +02:00
export async function createPublicDotKeycloakifyDir() {
2024-09-08 00:06:47 +02:00
await Promise.all(
(["login", "account"] as const).map(async themeType => {
const { extractedDirPath } = await downloadKeycloakDefaultTheme({
2024-09-08 12:40:28 +02:00
keycloakVersionId: (() => {
switch (themeType) {
case "login":
return "FOR_LOGIN_THEME";
case "account":
return "FOR_ACCOUNT_MULTI_PAGE";
}
assert<Equals<typeof themeType, never>>();
})()
2024-09-08 00:06:47 +02:00
});
const destDirPath = pathJoin(
getThisCodebaseRootDirPath(),
2024-09-08 12:00:07 +02:00
"dist",
"res",
2024-09-08 12:00:07 +02:00
"public",
WELL_KNOWN_DIRECTORY_BASE_NAME.DOT_KEYCLOAKIFY,
2024-09-08 00:06:47 +02:00
themeType
);
2024-09-08 12:00:07 +02:00
await fsPr.rm(destDirPath, { recursive: true, force: true });
2024-09-08 00:06:47 +02:00
base_resources: {
const srcDirPath = pathJoin(
extractedDirPath,
"base",
themeType,
"resources"
);
if (!(await existsAsync(srcDirPath))) {
break base_resources;
}
transformCodebase({
srcDirPath,
destDirPath
});
}
transformCodebase({
srcDirPath: pathJoin(
extractedDirPath,
"keycloak",
themeType,
"resources"
),
destDirPath
});
transformCodebase({
srcDirPath: pathJoin(extractedDirPath, "keycloak", "common", "resources"),
destDirPath: pathJoin(
destDirPath,
WELL_KNOWN_DIRECTORY_BASE_NAME.RESOURCES_COMMON
)
});
})
);
}