110 lines
3.5 KiB
TypeScript
Raw Normal View History

2023-09-04 00:25:36 +02:00
import * as fs from "fs";
2024-02-05 08:52:58 +01:00
import { join as pathJoin } from "path";
2023-09-04 00:25:36 +02:00
import { assert } from "tsafe/assert";
import type { BuildOptions } from "../../shared/buildOptions";
2024-05-20 15:48:51 +02:00
import {
resources_common,
lastKeycloakVersionWithAccountV1,
accountV1ThemeName
} from "../../shared/constants";
2024-05-19 10:46:26 +02:00
import { downloadKeycloakDefaultTheme } from "../../shared/downloadKeycloakDefaultTheme";
2023-09-04 00:25:36 +02:00
import { transformCodebase } from "../../tools/transformCodebase";
2024-02-05 08:52:58 +01:00
import { rmSync } from "../../tools/fs.rmSync";
2023-09-04 00:25:36 +02:00
2024-01-30 07:10:53 +01:00
type BuildOptionsLike = {
2023-09-04 00:25:36 +02:00
cacheDirPath: string;
2024-02-11 18:28:58 +01:00
npmWorkspaceRootDirPath: string;
keycloakifyBuildDirPath: string;
2023-09-04 00:25:36 +02:00
};
2024-05-13 00:40:16 +02:00
assert<BuildOptions extends BuildOptionsLike ? true : false>();
2023-09-04 00:25:36 +02:00
export async function bringInAccountV1(params: { buildOptions: BuildOptionsLike }) {
const { buildOptions } = params;
2023-09-04 00:25:36 +02:00
2024-05-20 15:48:51 +02:00
const builtinKeycloakThemeTmpDirPath = pathJoin(
buildOptions.cacheDirPath,
"bringInAccountV1_tmp"
);
2023-09-04 00:25:36 +02:00
2024-05-19 10:46:26 +02:00
await downloadKeycloakDefaultTheme({
2024-05-20 15:48:51 +02:00
destDirPath: builtinKeycloakThemeTmpDirPath,
keycloakVersion: lastKeycloakVersionWithAccountV1,
2023-09-04 00:25:36 +02:00
buildOptions
});
2024-05-20 15:48:51 +02:00
const accountV1DirPath = pathJoin(
buildOptions.keycloakifyBuildDirPath,
"src",
"main",
"resources",
"theme",
accountV1ThemeName,
"account"
);
2023-09-04 00:25:36 +02:00
transformCodebase({
2024-05-20 15:48:51 +02:00
srcDirPath: pathJoin(builtinKeycloakThemeTmpDirPath, "base", "account"),
destDirPath: accountV1DirPath
2023-09-04 00:25:36 +02:00
});
2024-02-05 08:52:58 +01:00
transformCodebase({
2024-05-20 15:48:51 +02:00
srcDirPath: pathJoin(
builtinKeycloakThemeTmpDirPath,
"keycloak",
"account",
"resources"
),
destDirPath: pathJoin(accountV1DirPath, "resources")
2024-02-05 08:52:58 +01:00
});
2023-09-04 00:25:36 +02:00
2024-02-05 08:52:58 +01:00
transformCodebase({
2024-05-20 15:48:51 +02:00
srcDirPath: pathJoin(
builtinKeycloakThemeTmpDirPath,
"keycloak",
"common",
"resources"
),
destDirPath: pathJoin(accountV1DirPath, "resources", resources_common)
2024-02-05 08:52:58 +01:00
});
2023-09-04 00:25:36 +02:00
2024-05-20 15:48:51 +02:00
rmSync(builtinKeycloakThemeTmpDirPath, { recursive: true });
2023-09-04 00:25:36 +02:00
fs.writeFileSync(
pathJoin(accountV1DirPath, "theme.properties"),
Buffer.from(
[
"accountResourceProvider=account-v1",
2023-09-04 00:25:36 +02:00
"",
"locales=ar,ca,cs,da,de,en,es,fr,fi,hu,it,ja,lt,nl,no,pl,pt-BR,ru,sk,sv,tr,zh-CN",
"",
2024-02-05 08:52:58 +01:00
"styles=" +
[
"css/account.css",
"img/icon-sidebar-active.png",
"img/logo.png",
2024-05-20 15:48:51 +02:00
...[
"patternfly.min.css",
"patternfly-additions.min.css",
"patternfly-additions.min.css"
].map(
fileBasename =>
`${resources_common}/node_modules/patternfly/dist/css/${fileBasename}`
2024-02-05 08:52:58 +01:00
)
].join(" "),
2023-09-04 00:25:36 +02:00
"",
"##### css classes for form buttons",
"# main class used for all buttons",
"kcButtonClass=btn",
"# classes defining priority of the button - primary or default (there is typically only one priority button for the form)",
"kcButtonPrimaryClass=btn-primary",
"kcButtonDefaultClass=btn-default",
"# classes defining size of the button",
"kcButtonLargeClass=btn-lg",
""
].join("\n"),
"utf8"
)
);
}