keycloakify 11.8.38-rc.1 → 11.8.39

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.
package/bin/375.index.js CHANGED
@@ -2489,13 +2489,15 @@ async function runPrettier(params) {
2489
2489
  return sourceCode;
2490
2490
  }
2491
2491
  const config = await prettier.resolveConfig(filePath);
2492
- formattedSourceCode = await prettier.format(sourceCode, Object.assign(Object.assign({}, config), { filePath, parser: inferredParser }));
2492
+ formattedSourceCode = await prettier.format(typeof sourceCode === "string" ? sourceCode : sourceCode.toString("utf8"), Object.assign(Object.assign({}, config), { filePath, parser: inferredParser }));
2493
2493
  }
2494
2494
  catch (error) {
2495
2495
  console.log(chalk__WEBPACK_IMPORTED_MODULE_4___default().red(`You probably need to upgrade the version of prettier in your project`));
2496
2496
  throw error;
2497
2497
  }
2498
- return formattedSourceCode;
2498
+ return typeof sourceCode === "string"
2499
+ ? formattedSourceCode
2500
+ : Buffer.from(formattedSourceCode, "utf8");
2499
2501
  }
2500
2502
  //# sourceMappingURL=runPrettier.js.map
2501
2503
 
package/bin/786.index.js CHANGED
@@ -413,13 +413,15 @@ async function runPrettier(params) {
413
413
  return sourceCode;
414
414
  }
415
415
  const config = await prettier.resolveConfig(filePath);
416
- formattedSourceCode = await prettier.format(sourceCode, Object.assign(Object.assign({}, config), { filePath, parser: inferredParser }));
416
+ formattedSourceCode = await prettier.format(typeof sourceCode === "string" ? sourceCode : sourceCode.toString("utf8"), Object.assign(Object.assign({}, config), { filePath, parser: inferredParser }));
417
417
  }
418
418
  catch (error) {
419
419
  console.log(chalk__WEBPACK_IMPORTED_MODULE_4___default().red(`You probably need to upgrade the version of prettier in your project`));
420
420
  throw error;
421
421
  }
422
- return formattedSourceCode;
422
+ return typeof sourceCode === "string"
423
+ ? formattedSourceCode
424
+ : Buffer.from(formattedSourceCode, "utf8");
423
425
  }
424
426
  //# sourceMappingURL=runPrettier.js.map
425
427
 
package/bin/84.index.js CHANGED
@@ -605,13 +605,15 @@ async function runPrettier(params) {
605
605
  return sourceCode;
606
606
  }
607
607
  const config = await prettier.resolveConfig(filePath);
608
- formattedSourceCode = await prettier.format(sourceCode, Object.assign(Object.assign({}, config), { filePath, parser: inferredParser }));
608
+ formattedSourceCode = await prettier.format(typeof sourceCode === "string" ? sourceCode : sourceCode.toString("utf8"), Object.assign(Object.assign({}, config), { filePath, parser: inferredParser }));
609
609
  }
610
610
  catch (error) {
611
611
  console.log(chalk__WEBPACK_IMPORTED_MODULE_4___default().red(`You probably need to upgrade the version of prettier in your project`));
612
612
  throw error;
613
613
  }
614
- return formattedSourceCode;
614
+ return typeof sourceCode === "string"
615
+ ? formattedSourceCode
616
+ : Buffer.from(formattedSourceCode, "utf8");
615
617
  }
616
618
  //# sourceMappingURL=runPrettier.js.map
617
619
 
package/bin/949.index.js CHANGED
@@ -429,13 +429,15 @@ async function runPrettier(params) {
429
429
  return sourceCode;
430
430
  }
431
431
  const config = await prettier.resolveConfig(filePath);
432
- formattedSourceCode = await prettier.format(sourceCode, Object.assign(Object.assign({}, config), { filePath, parser: inferredParser }));
432
+ formattedSourceCode = await prettier.format(typeof sourceCode === "string" ? sourceCode : sourceCode.toString("utf8"), Object.assign(Object.assign({}, config), { filePath, parser: inferredParser }));
433
433
  }
434
434
  catch (error) {
435
435
  console.log(chalk__WEBPACK_IMPORTED_MODULE_4___default().red(`You probably need to upgrade the version of prettier in your project`));
436
436
  throw error;
437
437
  }
438
- return formattedSourceCode;
438
+ return typeof sourceCode === "string"
439
+ ? formattedSourceCode
440
+ : Buffer.from(formattedSourceCode, "utf8");
439
441
  }
440
442
  //# sourceMappingURL=runPrettier.js.map
441
443
 
package/bin/97.index.js CHANGED
@@ -293,22 +293,22 @@ async function getExtensionModuleMetas(params) {
293
293
  await crawlAsync({
294
294
  dirPath: (0,external_path_.join)(dirPath, constants/* KEYCLOAK_THEME */.PC),
295
295
  returnedPathsType: "relative to dirPath",
296
- onFileFound: async (fileRelativePath) => {
297
- const isPublic = fileRelativePath.startsWith(`public${external_path_.sep}`);
298
- const fileRelativePath_contextual = isPublic
299
- ? (0,external_path_.relative)("public", fileRelativePath)
300
- : fileRelativePath;
296
+ onFileFound: async (fileRelativePath_fromReservedDir) => {
297
+ const isPublic = fileRelativePath_fromReservedDir.startsWith(`public${external_path_.sep}`);
298
+ const fileRelativePath = isPublic
299
+ ? (0,external_path_.relative)("public", fileRelativePath_fromReservedDir)
300
+ : fileRelativePath_fromReservedDir;
301
301
  const sourceCode = await (0,getExtensionModuleFileSourceCodeReadyToBeCopied/* getExtensionModuleFileSourceCodeReadyToBeCopied */.p)({
302
302
  buildContext,
303
303
  isPublic,
304
- fileRelativePath: fileRelativePath_contextual,
304
+ fileRelativePath,
305
305
  isOwnershipAction: false,
306
306
  extensionModuleDirPath: dirPath,
307
307
  extensionModuleName: moduleName,
308
308
  extensionModuleVersion: version
309
309
  });
310
310
  const hash = computeHash(sourceCode);
311
- const copyableFilePath = (0,external_path_.join)((0,external_path_.dirname)(cacheFilePath), constants/* KEYCLOAK_THEME */.PC, fileRelativePath);
311
+ const copyableFilePath = (0,external_path_.join)((0,external_path_.dirname)(cacheFilePath), constants/* KEYCLOAK_THEME */.PC, fileRelativePath_fromReservedDir);
312
312
  {
313
313
  const dirPath = (0,external_path_.dirname)(copyableFilePath);
314
314
  if (!(await (0,fs_existsAsync/* existsAsync */.o)(dirPath))) {
@@ -318,7 +318,7 @@ async function getExtensionModuleMetas(params) {
318
318
  promises_.writeFile(copyableFilePath, sourceCode);
319
319
  files.push({
320
320
  isPublic,
321
- fileRelativePath: fileRelativePath_contextual,
321
+ fileRelativePath,
322
322
  hash,
323
323
  copyableFilePath
324
324
  });
@@ -381,7 +381,30 @@ function computeHash(data) {
381
381
  (0,tsafe_assert__WEBPACK_IMPORTED_MODULE_3__/* .assert */ .h)();
382
382
  async function getExtensionModuleFileSourceCodeReadyToBeCopied(params) {
383
383
  const { buildContext, extensionModuleDirPath, isPublic, fileRelativePath, isOwnershipAction, extensionModuleName, extensionModuleVersion } = params;
384
- let sourceCode = (await fs_promises__WEBPACK_IMPORTED_MODULE_1__.readFile((0,path__WEBPACK_IMPORTED_MODULE_2__.join)(extensionModuleDirPath, _shared_constants__WEBPACK_IMPORTED_MODULE_4__/* .KEYCLOAK_THEME */ .PC, fileRelativePath))).toString("utf8");
384
+ const { refSourceCode } = await (async () => {
385
+ let sourceCode = undefined;
386
+ const sourceCode_originalBuffer = await fs_promises__WEBPACK_IMPORTED_MODULE_1__.readFile((0,path__WEBPACK_IMPORTED_MODULE_2__.join)(extensionModuleDirPath, _shared_constants__WEBPACK_IMPORTED_MODULE_4__/* .KEYCLOAK_THEME */ .PC, isPublic ? "public" : ".", fileRelativePath));
387
+ let hasBeenUpdated = false;
388
+ const refSourceCode = {
389
+ get current() {
390
+ if (sourceCode === undefined) {
391
+ sourceCode = sourceCode_originalBuffer.toString("utf8");
392
+ }
393
+ return sourceCode;
394
+ },
395
+ set current(value) {
396
+ hasBeenUpdated = true;
397
+ sourceCode = value;
398
+ },
399
+ getAsBuffer: () => {
400
+ if (!hasBeenUpdated) {
401
+ return sourceCode_originalBuffer;
402
+ }
403
+ return Buffer.from(refSourceCode.current, "utf8");
404
+ }
405
+ };
406
+ return { refSourceCode };
407
+ })();
385
408
  add_eslint_disable: {
386
409
  if (isOwnershipAction) {
387
410
  break add_eslint_disable;
@@ -389,13 +412,13 @@ async function getExtensionModuleFileSourceCodeReadyToBeCopied(params) {
389
412
  if (!fileRelativePath.endsWith(".ts") && !fileRelativePath.endsWith(".tsx")) {
390
413
  break add_eslint_disable;
391
414
  }
392
- if (sourceCode.includes("/* eslint-disable */")) {
415
+ if (refSourceCode.current.includes("/* eslint-disable */")) {
393
416
  break add_eslint_disable;
394
417
  }
395
- sourceCode = ["/* eslint-disable */", "", sourceCode].join("\n");
418
+ refSourceCode.current = ["/* eslint-disable */", "", refSourceCode.current].join("\n");
396
419
  }
397
- sourceCode = addCommentToSourceCode({
398
- sourceCode,
420
+ addCommentToSourceCode({
421
+ refSourceCode,
399
422
  fileRelativePath,
400
423
  commentLines: (() => {
401
424
  const path = fileRelativePath.split(path__WEBPACK_IMPORTED_MODULE_2__.sep).join("/");
@@ -416,42 +439,50 @@ async function getExtensionModuleFileSourceCodeReadyToBeCopied(params) {
416
439
  ];
417
440
  })()
418
441
  });
419
- const destFilePath = (0,path__WEBPACK_IMPORTED_MODULE_2__.join)(isPublic
420
- ? (0,path__WEBPACK_IMPORTED_MODULE_2__.join)(buildContext.publicDirPath, _shared_constants__WEBPACK_IMPORTED_MODULE_4__/* .KEYCLOAK_THEME */ .PC)
421
- : buildContext.themeSrcDirPath, fileRelativePath);
422
442
  format: {
423
443
  if (!(await (0,_tools_runPrettier__WEBPACK_IMPORTED_MODULE_0__/* .getIsPrettierAvailable */ .MT)())) {
424
444
  break format;
425
445
  }
426
- sourceCode = await (0,_tools_runPrettier__WEBPACK_IMPORTED_MODULE_0__/* .runPrettier */ .eY)({
427
- filePath: destFilePath,
428
- sourceCode
446
+ const sourceCode_buffer_before = refSourceCode.getAsBuffer();
447
+ const sourceCode_buffer_after = await (0,_tools_runPrettier__WEBPACK_IMPORTED_MODULE_0__/* .runPrettier */ .eY)({
448
+ filePath: (0,path__WEBPACK_IMPORTED_MODULE_2__.join)(isPublic
449
+ ? (0,path__WEBPACK_IMPORTED_MODULE_2__.join)(buildContext.publicDirPath, _shared_constants__WEBPACK_IMPORTED_MODULE_4__/* .KEYCLOAK_THEME */ .PC)
450
+ : buildContext.themeSrcDirPath, fileRelativePath),
451
+ sourceCode: sourceCode_buffer_before
429
452
  });
453
+ if (sourceCode_buffer_before.compare(sourceCode_buffer_after) === 0) {
454
+ break format;
455
+ }
456
+ refSourceCode.current = sourceCode_buffer_after.toString("utf8");
430
457
  }
431
- return Buffer.from(sourceCode, "utf8");
458
+ return refSourceCode.getAsBuffer();
432
459
  }
433
460
  function addCommentToSourceCode(params) {
434
- const { sourceCode, fileRelativePath, commentLines } = params;
435
- const toResult = (comment) => {
436
- return [comment, ``, sourceCode].join("\n");
461
+ const { refSourceCode, fileRelativePath, commentLines } = params;
462
+ const updateRef = (comment) => {
463
+ refSourceCode.current = [comment, ``, refSourceCode.current].join("\n");
437
464
  };
438
465
  for (const ext of [".ts", ".tsx", ".css", ".less", ".sass", ".js", ".jsx"]) {
439
466
  if (!fileRelativePath.endsWith(ext)) {
440
467
  continue;
441
468
  }
442
- return toResult([`/**`, ...commentLines.map(line => ` * ${line}`), ` */`].join("\n"));
469
+ updateRef([`/**`, ...commentLines.map(line => ` * ${line}`), ` */`].join("\n"));
470
+ return;
443
471
  }
444
472
  if (fileRelativePath.endsWith(".properties")) {
445
- return toResult(commentLines.map(line => `# ${line}`).join("\n"));
473
+ updateRef(commentLines.map(line => `# ${line}`).join("\n"));
474
+ return;
446
475
  }
447
476
  if (fileRelativePath.endsWith(".ftl")) {
448
477
  const comment = [`<#--`, ...commentLines.map(line => ` ${line}`), `-->`].join("\n");
449
- if (sourceCode.trim().startsWith("<#ftl")) {
450
- const [first, ...rest] = sourceCode.split(">");
478
+ if (refSourceCode.current.trim().startsWith("<#ftl")) {
479
+ const [first, ...rest] = refSourceCode.current.split(">");
451
480
  const last = rest.join(">");
452
- return [`${first}>`, comment, last].join("\n");
481
+ refSourceCode.current = [`${first}>`, comment, last].join("\n");
482
+ return;
453
483
  }
454
- return toResult(comment);
484
+ updateRef(comment);
485
+ return;
455
486
  }
456
487
  if (fileRelativePath.endsWith(".html") || fileRelativePath.endsWith(".svg")) {
457
488
  const comment = [
@@ -462,19 +493,23 @@ function addCommentToSourceCode(params) {
462
493
  .replace("Before modifying", "Before modifying or replacing")}`),
463
494
  `-->`
464
495
  ].join("\n");
465
- if (fileRelativePath.endsWith(".html") && sourceCode.trim().startsWith("<!")) {
466
- const [first, ...rest] = sourceCode.split(">");
496
+ if (fileRelativePath.endsWith(".html") &&
497
+ refSourceCode.current.trim().startsWith("<!")) {
498
+ const [first, ...rest] = refSourceCode.current.split(">");
467
499
  const last = rest.join(">");
468
- return [`${first}>`, comment, last].join("\n");
500
+ refSourceCode.current = [`${first}>`, comment, last].join("\n");
501
+ return;
469
502
  }
470
- if (fileRelativePath.endsWith(".svg") && sourceCode.trim().startsWith("<?")) {
471
- const [first, ...rest] = sourceCode.split("?>");
503
+ if (fileRelativePath.endsWith(".svg") &&
504
+ refSourceCode.current.trim().startsWith("<?")) {
505
+ const [first, ...rest] = refSourceCode.current.split("?>");
472
506
  const last = rest.join("?>");
473
- return [`${first}?>`, comment, last].join("\n");
507
+ refSourceCode.current = [`${first}?>`, comment, last].join("\n");
508
+ return;
474
509
  }
475
- return toResult(comment);
510
+ updateRef(comment);
511
+ return;
476
512
  }
477
- return sourceCode;
478
513
  }
479
514
  //# sourceMappingURL=getExtensionModuleFileSourceCodeReadyToBeCopied.js.map
480
515
 
package/bin/main.js CHANGED
@@ -206,6 +206,12 @@ function getBuildContext(params) {
206
206
  }
207
207
  }
208
208
  }
209
+ for (const themeType of [...constants/* THEME_TYPES */.Jh, "email"]) {
210
+ if (!external_fs_.existsSync((0,external_path_.join)(srcDirPath, themeType))) {
211
+ continue;
212
+ }
213
+ return { themeSrcDirPath: srcDirPath };
214
+ }
209
215
  console.log(source_default().red([
210
216
  `Can't locate your Keycloak theme source directory in .${external_path_.sep}${(0,external_path_.relative)(process.cwd(), srcDirPath)}`,
211
217
  `Make sure to either use the Keycloakify CLI in the root of your Keycloakify project or use the --project CLI option`,
@@ -1,3 +1,4 @@
1
+ /// <reference types="node" />
1
2
  export declare function getIsPrettierAvailable(): Promise<boolean>;
2
3
  export declare namespace getIsPrettierAvailable {
3
4
  var cache: boolean | undefined;
@@ -14,4 +15,8 @@ export declare function runPrettier(params: {
14
15
  sourceCode: string;
15
16
  filePath: string;
16
17
  }): Promise<string>;
18
+ export declare function runPrettier(params: {
19
+ sourceCode: Buffer;
20
+ filePath: string;
21
+ }): Promise<Buffer>;
17
22
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "keycloakify",
3
- "version": "11.8.38-rc.1",
3
+ "version": "11.8.39",
4
4
  "description": "Framework to create custom Keycloak UIs",
5
5
  "repository": {
6
6
  "type": "git",
@@ -13,7 +13,8 @@ import { assert, type Equals, is } from "tsafe/assert";
13
13
  import * as child_process from "child_process";
14
14
  import {
15
15
  VITE_PLUGIN_SUB_SCRIPTS_ENV_NAMES,
16
- BUILD_FOR_KEYCLOAK_MAJOR_VERSION_ENV_NAME
16
+ BUILD_FOR_KEYCLOAK_MAJOR_VERSION_ENV_NAME,
17
+ THEME_TYPES
17
18
  } from "./constants";
18
19
  import type { KeycloakVersionRange } from "./KeycloakVersionRange";
19
20
  import { exclude } from "tsafe";
@@ -182,6 +183,13 @@ export function getBuildContext(params: {
182
183
  }
183
184
  }
184
185
 
186
+ for (const themeType of [...THEME_TYPES, "email"]) {
187
+ if (!fs.existsSync(pathJoin(srcDirPath, themeType))) {
188
+ continue;
189
+ }
190
+ return { themeSrcDirPath: srcDirPath };
191
+ }
192
+
185
193
  console.log(
186
194
  chalk.red(
187
195
  [
@@ -232,18 +232,20 @@ export async function getExtensionModuleMetas(params: {
232
232
  await crawlAsync({
233
233
  dirPath: pathJoin(dirPath, KEYCLOAK_THEME),
234
234
  returnedPathsType: "relative to dirPath",
235
- onFileFound: async fileRelativePath => {
236
- const isPublic = fileRelativePath.startsWith(`public${pathSep}`);
235
+ onFileFound: async fileRelativePath_fromReservedDir => {
236
+ const isPublic = fileRelativePath_fromReservedDir.startsWith(
237
+ `public${pathSep}`
238
+ );
237
239
 
238
- const fileRelativePath_contextual = isPublic
239
- ? pathRelative("public", fileRelativePath)
240
- : fileRelativePath;
240
+ const fileRelativePath = isPublic
241
+ ? pathRelative("public", fileRelativePath_fromReservedDir)
242
+ : fileRelativePath_fromReservedDir;
241
243
 
242
244
  const sourceCode =
243
245
  await getExtensionModuleFileSourceCodeReadyToBeCopied({
244
246
  buildContext,
245
247
  isPublic,
246
- fileRelativePath: fileRelativePath_contextual,
248
+ fileRelativePath,
247
249
  isOwnershipAction: false,
248
250
  extensionModuleDirPath: dirPath,
249
251
  extensionModuleName: moduleName,
@@ -255,7 +257,7 @@ export async function getExtensionModuleMetas(params: {
255
257
  const copyableFilePath = pathJoin(
256
258
  pathDirname(cacheFilePath),
257
259
  KEYCLOAK_THEME,
258
- fileRelativePath
260
+ fileRelativePath_fromReservedDir
259
261
  );
260
262
 
261
263
  {
@@ -270,7 +272,7 @@ export async function getExtensionModuleMetas(params: {
270
272
 
271
273
  files.push({
272
274
  isPublic,
273
- fileRelativePath: fileRelativePath_contextual,
275
+ fileRelativePath,
274
276
  hash,
275
277
  copyableFilePath
276
278
  });
@@ -31,11 +31,43 @@ export async function getExtensionModuleFileSourceCodeReadyToBeCopied(params: {
31
31
  extensionModuleVersion
32
32
  } = params;
33
33
 
34
- let sourceCode = (
35
- await fsPr.readFile(
36
- pathJoin(extensionModuleDirPath, KEYCLOAK_THEME, fileRelativePath)
37
- )
38
- ).toString("utf8");
34
+ const { refSourceCode } = await (async () => {
35
+ let sourceCode: string | undefined = undefined;
36
+
37
+ const sourceCode_originalBuffer = await fsPr.readFile(
38
+ pathJoin(
39
+ extensionModuleDirPath,
40
+ KEYCLOAK_THEME,
41
+ isPublic ? "public" : ".",
42
+ fileRelativePath
43
+ )
44
+ );
45
+
46
+ let hasBeenUpdated = false;
47
+
48
+ const refSourceCode = {
49
+ get current(): string {
50
+ if (sourceCode === undefined) {
51
+ sourceCode = sourceCode_originalBuffer.toString("utf8");
52
+ }
53
+
54
+ return sourceCode;
55
+ },
56
+ set current(value: string) {
57
+ hasBeenUpdated = true;
58
+ sourceCode = value;
59
+ },
60
+ getAsBuffer: () => {
61
+ if (!hasBeenUpdated) {
62
+ return sourceCode_originalBuffer;
63
+ }
64
+
65
+ return Buffer.from(refSourceCode.current, "utf8");
66
+ }
67
+ };
68
+
69
+ return { refSourceCode };
70
+ })();
39
71
 
40
72
  add_eslint_disable: {
41
73
  if (isOwnershipAction) {
@@ -46,15 +78,17 @@ export async function getExtensionModuleFileSourceCodeReadyToBeCopied(params: {
46
78
  break add_eslint_disable;
47
79
  }
48
80
 
49
- if (sourceCode.includes("/* eslint-disable */")) {
81
+ if (refSourceCode.current.includes("/* eslint-disable */")) {
50
82
  break add_eslint_disable;
51
83
  }
52
84
 
53
- sourceCode = ["/* eslint-disable */", "", sourceCode].join("\n");
85
+ refSourceCode.current = ["/* eslint-disable */", "", refSourceCode.current].join(
86
+ "\n"
87
+ );
54
88
  }
55
89
 
56
- sourceCode = addCommentToSourceCode({
57
- sourceCode,
90
+ addCommentToSourceCode({
91
+ refSourceCode,
58
92
  fileRelativePath,
59
93
  commentLines: (() => {
60
94
  const path = fileRelativePath.split(pathSep).join("/");
@@ -77,36 +111,41 @@ export async function getExtensionModuleFileSourceCodeReadyToBeCopied(params: {
77
111
  })()
78
112
  });
79
113
 
80
- const destFilePath = pathJoin(
81
- isPublic
82
- ? pathJoin(buildContext.publicDirPath, KEYCLOAK_THEME)
83
- : buildContext.themeSrcDirPath,
84
- fileRelativePath
85
- );
86
-
87
114
  format: {
88
115
  if (!(await getIsPrettierAvailable())) {
89
116
  break format;
90
117
  }
91
118
 
92
- sourceCode = await runPrettier({
93
- filePath: destFilePath,
94
- sourceCode
119
+ const sourceCode_buffer_before = refSourceCode.getAsBuffer();
120
+ const sourceCode_buffer_after = await runPrettier({
121
+ filePath: pathJoin(
122
+ isPublic
123
+ ? pathJoin(buildContext.publicDirPath, KEYCLOAK_THEME)
124
+ : buildContext.themeSrcDirPath,
125
+ fileRelativePath
126
+ ),
127
+ sourceCode: sourceCode_buffer_before
95
128
  });
129
+
130
+ if (sourceCode_buffer_before.compare(sourceCode_buffer_after) === 0) {
131
+ break format;
132
+ }
133
+
134
+ refSourceCode.current = sourceCode_buffer_after.toString("utf8");
96
135
  }
97
136
 
98
- return Buffer.from(sourceCode, "utf8");
137
+ return refSourceCode.getAsBuffer();
99
138
  }
100
139
 
101
140
  function addCommentToSourceCode(params: {
102
- sourceCode: string;
141
+ refSourceCode: { current: string };
103
142
  fileRelativePath: string;
104
143
  commentLines: string[];
105
- }): string {
106
- const { sourceCode, fileRelativePath, commentLines } = params;
144
+ }): void {
145
+ const { refSourceCode, fileRelativePath, commentLines } = params;
107
146
 
108
- const toResult = (comment: string) => {
109
- return [comment, ``, sourceCode].join("\n");
147
+ const updateRef = (comment: string) => {
148
+ refSourceCode.current = [comment, ``, refSourceCode.current].join("\n");
110
149
  };
111
150
 
112
151
  for (const ext of [".ts", ".tsx", ".css", ".less", ".sass", ".js", ".jsx"]) {
@@ -114,13 +153,13 @@ function addCommentToSourceCode(params: {
114
153
  continue;
115
154
  }
116
155
 
117
- return toResult(
118
- [`/**`, ...commentLines.map(line => ` * ${line}`), ` */`].join("\n")
119
- );
156
+ updateRef([`/**`, ...commentLines.map(line => ` * ${line}`), ` */`].join("\n"));
157
+ return;
120
158
  }
121
159
 
122
160
  if (fileRelativePath.endsWith(".properties")) {
123
- return toResult(commentLines.map(line => `# ${line}`).join("\n"));
161
+ updateRef(commentLines.map(line => `# ${line}`).join("\n"));
162
+ return;
124
163
  }
125
164
 
126
165
  if (fileRelativePath.endsWith(".ftl")) {
@@ -128,15 +167,17 @@ function addCommentToSourceCode(params: {
128
167
  "\n"
129
168
  );
130
169
 
131
- if (sourceCode.trim().startsWith("<#ftl")) {
132
- const [first, ...rest] = sourceCode.split(">");
170
+ if (refSourceCode.current.trim().startsWith("<#ftl")) {
171
+ const [first, ...rest] = refSourceCode.current.split(">");
133
172
 
134
173
  const last = rest.join(">");
135
174
 
136
- return [`${first}>`, comment, last].join("\n");
175
+ refSourceCode.current = [`${first}>`, comment, last].join("\n");
176
+ return;
137
177
  }
138
178
 
139
- return toResult(comment);
179
+ updateRef(comment);
180
+ return;
140
181
  }
141
182
 
142
183
  if (fileRelativePath.endsWith(".html") || fileRelativePath.endsWith(".svg")) {
@@ -152,24 +193,31 @@ function addCommentToSourceCode(params: {
152
193
  `-->`
153
194
  ].join("\n");
154
195
 
155
- if (fileRelativePath.endsWith(".html") && sourceCode.trim().startsWith("<!")) {
156
- const [first, ...rest] = sourceCode.split(">");
196
+ if (
197
+ fileRelativePath.endsWith(".html") &&
198
+ refSourceCode.current.trim().startsWith("<!")
199
+ ) {
200
+ const [first, ...rest] = refSourceCode.current.split(">");
157
201
 
158
202
  const last = rest.join(">");
159
203
 
160
- return [`${first}>`, comment, last].join("\n");
204
+ refSourceCode.current = [`${first}>`, comment, last].join("\n");
205
+ return;
161
206
  }
162
207
 
163
- if (fileRelativePath.endsWith(".svg") && sourceCode.trim().startsWith("<?")) {
164
- const [first, ...rest] = sourceCode.split("?>");
208
+ if (
209
+ fileRelativePath.endsWith(".svg") &&
210
+ refSourceCode.current.trim().startsWith("<?")
211
+ ) {
212
+ const [first, ...rest] = refSourceCode.current.split("?>");
165
213
 
166
214
  const last = rest.join("?>");
167
215
 
168
- return [`${first}?>`, comment, last].join("\n");
216
+ refSourceCode.current = [`${first}?>`, comment, last].join("\n");
217
+ return;
169
218
  }
170
219
 
171
- return toResult(comment);
220
+ updateRef(comment);
221
+ return;
172
222
  }
173
-
174
- return sourceCode;
175
223
  }
@@ -111,7 +111,15 @@ export async function getPrettier(): Promise<PrettierAndConfigHash> {
111
111
  export async function runPrettier(params: {
112
112
  sourceCode: string;
113
113
  filePath: string;
114
- }): Promise<string> {
114
+ }): Promise<string>;
115
+ export async function runPrettier(params: {
116
+ sourceCode: Buffer;
117
+ filePath: string;
118
+ }): Promise<Buffer>;
119
+ export async function runPrettier(params: {
120
+ sourceCode: string | Buffer;
121
+ filePath: string;
122
+ }): Promise<string | Buffer> {
115
123
  const { sourceCode, filePath } = params;
116
124
 
117
125
  let formattedSourceCode: string;
@@ -129,11 +137,14 @@ export async function runPrettier(params: {
129
137
 
130
138
  const config = await prettier.resolveConfig(filePath);
131
139
 
132
- formattedSourceCode = await prettier.format(sourceCode, {
133
- ...config,
134
- filePath,
135
- parser: inferredParser
136
- });
140
+ formattedSourceCode = await prettier.format(
141
+ typeof sourceCode === "string" ? sourceCode : sourceCode.toString("utf8"),
142
+ {
143
+ ...config,
144
+ filePath,
145
+ parser: inferredParser
146
+ }
147
+ );
137
148
  } catch (error) {
138
149
  console.log(
139
150
  chalk.red(
@@ -144,5 +155,7 @@ export async function runPrettier(params: {
144
155
  throw error;
145
156
  }
146
157
 
147
- return formattedSourceCode;
158
+ return typeof sourceCode === "string"
159
+ ? formattedSourceCode
160
+ : Buffer.from(formattedSourceCode, "utf8");
148
161
  }
@@ -420,6 +420,12 @@ function getBuildContext(params) {
420
420
  }
421
421
  }
422
422
  }
423
+ for (const themeType of [...constants.THEME_TYPES, "email"]) {
424
+ if (!external_fs_.existsSync((0,external_path_.join)(srcDirPath, themeType))) {
425
+ continue;
426
+ }
427
+ return { themeSrcDirPath: srcDirPath };
428
+ }
423
429
  console.log(source_default().red([
424
430
  `Can't locate your Keycloak theme source directory in .${external_path_.sep}${(0,external_path_.relative)(process.cwd(), srcDirPath)}`,
425
431
  `Make sure to either use the Keycloakify CLI in the root of your Keycloakify project or use the --project CLI option`,
@@ -1790,13 +1796,15 @@ async function runPrettier(params) {
1790
1796
  return sourceCode;
1791
1797
  }
1792
1798
  const config = await prettier.resolveConfig(filePath);
1793
- formattedSourceCode = await prettier.format(sourceCode, Object.assign(Object.assign({}, config), { filePath, parser: inferredParser }));
1799
+ formattedSourceCode = await prettier.format(typeof sourceCode === "string" ? sourceCode : sourceCode.toString("utf8"), Object.assign(Object.assign({}, config), { filePath, parser: inferredParser }));
1794
1800
  }
1795
1801
  catch (error) {
1796
1802
  console.log(chalk__WEBPACK_IMPORTED_MODULE_4___default().red(`You probably need to upgrade the version of prettier in your project`));
1797
1803
  throw error;
1798
1804
  }
1799
- return formattedSourceCode;
1805
+ return typeof sourceCode === "string"
1806
+ ? formattedSourceCode
1807
+ : Buffer.from(formattedSourceCode, "utf8");
1800
1808
  }
1801
1809
  //# sourceMappingURL=runPrettier.js.map
1802
1810