keycloakify 11.8.0 → 11.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,7 +4,8 @@ import {
4
4
  CONTAINER_NAME,
5
5
  KEYCLOAKIFY_SPA_DEV_SERVER_PORT,
6
6
  KEYCLOAKIFY_LOGIN_JAR_BASENAME,
7
- TEST_APP_URL
7
+ TEST_APP_URL,
8
+ ThemeType
8
9
  } from "../shared/constants";
9
10
  import { SemVer } from "../tools/SemVer";
10
11
  import { assert, type Equals } from "tsafe/assert";
@@ -34,6 +35,7 @@ import { startViteDevServer } from "./startViteDevServer";
34
35
  import { getSupportedKeycloakMajorVersions } from "./realmConfig/defaultConfig";
35
36
  import { getSupportedDockerImageTags } from "./getSupportedDockerImageTags";
36
37
  import { getRealmConfig } from "./realmConfig";
38
+ import { id } from "tsafe/id";
37
39
 
38
40
  export async function command(params: {
39
41
  buildContext: BuildContext;
@@ -270,32 +272,6 @@ export async function command(params: {
270
272
  return wrap.majorVersionNumber;
271
273
  })();
272
274
 
273
- const { clientName, onRealmConfigChange, realmJsonFilePath, realmName, username } =
274
- await getRealmConfig({
275
- keycloakMajorVersionNumber,
276
- realmJsonFilePath_userProvided: await (async () => {
277
- if (cliCommandOptions.realmJsonFilePath !== undefined) {
278
- return getAbsoluteAndInOsFormatPath({
279
- pathIsh: cliCommandOptions.realmJsonFilePath,
280
- cwd: process.cwd()
281
- });
282
- }
283
-
284
- if (buildContext.startKeycloakOptions.realmJsonFilePath !== undefined) {
285
- assert(
286
- await existsAsync(
287
- buildContext.startKeycloakOptions.realmJsonFilePath
288
- ),
289
- `${pathRelative(process.cwd(), buildContext.startKeycloakOptions.realmJsonFilePath)} does not exist`
290
- );
291
- return buildContext.startKeycloakOptions.realmJsonFilePath;
292
- }
293
-
294
- return undefined;
295
- })(),
296
- buildContext
297
- });
298
-
299
275
  {
300
276
  const { isAppBuildSuccess } = await appBuild({
301
277
  buildContext
@@ -376,10 +352,24 @@ export async function command(params: {
376
352
  ))
377
353
  ];
378
354
 
355
+ let parsedKeycloakThemesJson = id<
356
+ { themes: { name: string; types: (ThemeType | "email")[] }[] } | undefined
357
+ >(undefined);
358
+
379
359
  async function extractThemeResourcesFromJar() {
380
360
  await extractArchive({
381
361
  archiveFilePath: jarFilePath,
382
- onArchiveFile: async ({ relativeFilePathInArchive, writeFile }) => {
362
+ onArchiveFile: async ({ relativeFilePathInArchive, writeFile, readFile }) => {
363
+ if (
364
+ relativeFilePathInArchive ===
365
+ pathJoin("META-INF", "keycloak-themes.json") &&
366
+ parsedKeycloakThemesJson === undefined
367
+ ) {
368
+ parsedKeycloakThemesJson = JSON.parse(
369
+ (await readFile()).toString("utf8")
370
+ );
371
+ }
372
+
383
373
  if (isInside({ dirPath: "theme", filePath: relativeFilePathInArchive })) {
384
374
  await writeFile({
385
375
  filePath: pathJoin(
@@ -401,6 +391,43 @@ export async function command(params: {
401
391
 
402
392
  await extractThemeResourcesFromJar();
403
393
 
394
+ assert(parsedKeycloakThemesJson !== undefined);
395
+
396
+ const { clientName, onRealmConfigChange, realmJsonFilePath, realmName, username } =
397
+ await getRealmConfig({
398
+ keycloakMajorVersionNumber,
399
+ parsedKeycloakThemesJsonEntry: (() => {
400
+ const entry = parsedKeycloakThemesJson.themes.find(
401
+ ({ name }) => name === buildContext.themeNames[0]
402
+ );
403
+
404
+ assert(entry !== undefined);
405
+
406
+ return entry;
407
+ })(),
408
+ realmJsonFilePath_userProvided: await (async () => {
409
+ if (cliCommandOptions.realmJsonFilePath !== undefined) {
410
+ return getAbsoluteAndInOsFormatPath({
411
+ pathIsh: cliCommandOptions.realmJsonFilePath,
412
+ cwd: process.cwd()
413
+ });
414
+ }
415
+
416
+ if (buildContext.startKeycloakOptions.realmJsonFilePath !== undefined) {
417
+ assert(
418
+ await existsAsync(
419
+ buildContext.startKeycloakOptions.realmJsonFilePath
420
+ ),
421
+ `${pathRelative(process.cwd(), buildContext.startKeycloakOptions.realmJsonFilePath)} does not exist`
422
+ );
423
+ return buildContext.startKeycloakOptions.realmJsonFilePath;
424
+ }
425
+
426
+ return undefined;
427
+ })(),
428
+ buildContext
429
+ });
430
+
404
431
  const jarFilePath_cacheDir = pathJoin(
405
432
  buildContext.cacheDirPath,
406
433
  pathBasename(jarFilePath)
@@ -1,13 +0,0 @@
1
- import type { ThemeType } from "./constants";
2
- export type MetaInfKeycloakTheme = {
3
- themes: {
4
- name: string;
5
- types: (ThemeType | "email")[];
6
- }[];
7
- };
8
- export declare function writeMetaInfKeycloakThemes(params: {
9
- resourcesDirPath: string;
10
- getNewMetaInfKeycloakTheme: (params: {
11
- metaInfKeycloakTheme: MetaInfKeycloakTheme | undefined;
12
- }) => MetaInfKeycloakTheme;
13
- }): void;
@@ -1,40 +0,0 @@
1
- import { join as pathJoin, dirname as pathDirname } from "path";
2
- import type { ThemeType } from "./constants";
3
- import * as fs from "fs";
4
-
5
- export type MetaInfKeycloakTheme = {
6
- themes: { name: string; types: (ThemeType | "email")[] }[];
7
- };
8
-
9
- export function writeMetaInfKeycloakThemes(params: {
10
- resourcesDirPath: string;
11
- getNewMetaInfKeycloakTheme: (params: {
12
- metaInfKeycloakTheme: MetaInfKeycloakTheme | undefined;
13
- }) => MetaInfKeycloakTheme;
14
- }) {
15
- const { resourcesDirPath, getNewMetaInfKeycloakTheme } = params;
16
-
17
- const filePath = pathJoin(resourcesDirPath, "META-INF", "keycloak-themes.json");
18
-
19
- const currentMetaInfKeycloakTheme = !fs.existsSync(filePath)
20
- ? undefined
21
- : (JSON.parse(
22
- fs.readFileSync(filePath).toString("utf8")
23
- ) as MetaInfKeycloakTheme);
24
-
25
- const newMetaInfKeycloakThemes = getNewMetaInfKeycloakTheme({
26
- metaInfKeycloakTheme: currentMetaInfKeycloakTheme
27
- });
28
-
29
- {
30
- const dirPath = pathDirname(filePath);
31
- if (!fs.existsSync(dirPath)) {
32
- fs.mkdirSync(dirPath, { recursive: true });
33
- }
34
- }
35
-
36
- fs.writeFileSync(
37
- filePath,
38
- Buffer.from(JSON.stringify(newMetaInfKeycloakThemes, null, 2), "utf8")
39
- );
40
- }