keycloakify 11.2.10 → 11.3.0-rc.0

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.
Files changed (37) hide show
  1. package/bin/193.index.js +1 -5
  2. package/bin/453.index.js +21 -26
  3. package/bin/526.index.js +1 -5
  4. package/bin/573.index.js +1 -5
  5. package/bin/780.index.js +1 -5
  6. package/bin/786.index.js +3 -8
  7. package/bin/932.index.js +9 -12
  8. package/bin/97.index.js +11 -16
  9. package/bin/main.js +5289 -277
  10. package/bin/shared/buildContext.d.ts +1 -2
  11. package/bin/shared/buildContext.js.map +1 -1
  12. package/bin/shared/constants.d.ts +4 -0
  13. package/bin/shared/constants.js +4 -0
  14. package/bin/shared/constants.js.map +1 -1
  15. package/bin/shared/customHandler.d.ts +11 -0
  16. package/bin/shared/customHandler.js +20 -0
  17. package/bin/shared/customHandler.js.map +1 -0
  18. package/bin/shared/customHandler_caller.d.ts +6 -0
  19. package/bin/shared/customHandler_caller.js.map +1 -0
  20. package/package.json +8 -3
  21. package/src/bin/add-story.ts +3 -8
  22. package/src/bin/copy-keycloak-resources-to-public.ts +3 -6
  23. package/src/bin/eject-page.ts +3 -8
  24. package/src/bin/initialize-account-theme/initialize-account-theme.ts +3 -6
  25. package/src/bin/initialize-email-theme.ts +3 -6
  26. package/src/bin/keycloakify/keycloakify.ts +3 -6
  27. package/src/bin/main.ts +181 -124
  28. package/src/bin/shared/buildContext.ts +3 -6
  29. package/src/bin/shared/constants.ts +5 -0
  30. package/src/bin/shared/customHandler.ts +35 -0
  31. package/src/bin/shared/customHandler_caller.ts +47 -0
  32. package/src/bin/start-keycloak/start-keycloak.ts +10 -12
  33. package/src/bin/update-kc-gen.ts +3 -8
  34. package/src/vite-plugin/vite-plugin.ts +1 -3
  35. package/vite-plugin/index.js +8 -6
  36. package/bin/31.index.js +0 -883
  37. package/bin/347.index.js +0 -4081
package/src/bin/main.ts CHANGED
@@ -4,8 +4,10 @@ import { termost } from "termost";
4
4
  import { readThisNpmPackageVersion } from "./tools/readThisNpmPackageVersion";
5
5
  import * as child_process from "child_process";
6
6
  import { assertNoPnpmDlx } from "./tools/assertNoPnpmDlx";
7
+ import { callHandlerIfAny } from "./shared/customHandler_caller";
8
+ import { getBuildContext } from "./shared/buildContext";
7
9
 
8
- export type CliCommandOptions = {
10
+ type CliCommandOptions = {
9
11
  projectDirPath: string | undefined;
10
12
  };
11
13
 
@@ -69,115 +71,154 @@ program
69
71
  })
70
72
  .task({
71
73
  skip,
72
- handler: async cliCommandOptions => {
74
+ handler: async ({ projectDirPath }) => {
75
+ const buildContext = getBuildContext({ projectDirPath });
76
+
73
77
  const { command } = await import("./keycloakify");
74
78
 
75
- await command({ cliCommandOptions });
79
+ await command({ buildContext });
76
80
  }
77
81
  });
78
82
 
79
- program
80
- .command<{
81
- port: number | undefined;
82
- keycloakVersion: string | undefined;
83
- realmJsonFilePath: string | undefined;
84
- }>({
85
- name: "start-keycloak",
86
- description:
87
- "Spin up a pre configured Docker image of Keycloak to test your theme."
88
- })
89
- .option({
90
- key: "port",
91
- name: (() => {
92
- const name = "port";
83
+ {
84
+ const commandName = "start-keycloak";
85
+
86
+ program
87
+ .command<{
88
+ port: number | undefined;
89
+ keycloakVersion: string | undefined;
90
+ realmJsonFilePath: string | undefined;
91
+ }>({
92
+ name: commandName,
93
+ description:
94
+ "Spin up a pre configured Docker image of Keycloak to test your theme."
95
+ })
96
+ .option({
97
+ key: "port",
98
+ name: (() => {
99
+ const name = "port";
100
+
101
+ optionsKeys.push(name);
102
+
103
+ return name;
104
+ })(),
105
+ description: ["Keycloak server port.", "Example `--port 8085`"].join(" "),
106
+ defaultValue: undefined
107
+ })
108
+ .option({
109
+ key: "keycloakVersion",
110
+ name: (() => {
111
+ const name = "keycloak-version";
112
+
113
+ optionsKeys.push(name);
114
+
115
+ return name;
116
+ })(),
117
+ description: [
118
+ "Use a specific version of Keycloak.",
119
+ "Example `--keycloak-version 21.1.1`"
120
+ ].join(" "),
121
+ defaultValue: undefined
122
+ })
123
+ .option({
124
+ key: "realmJsonFilePath",
125
+ name: (() => {
126
+ const name = "import";
127
+
128
+ optionsKeys.push(name);
129
+
130
+ return name;
131
+ })(),
132
+ defaultValue: undefined,
133
+ description: [
134
+ "Import your own realm configuration file",
135
+ "Example `--import path/to/myrealm-realm.json`"
136
+ ].join(" ")
137
+ })
138
+ .task({
139
+ skip,
140
+ handler: async ({
141
+ projectDirPath,
142
+ keycloakVersion,
143
+ port,
144
+ realmJsonFilePath
145
+ }) => {
146
+ const buildContext = getBuildContext({ projectDirPath });
147
+
148
+ const { command } = await import("./start-keycloak");
149
+
150
+ await command({
151
+ buildContext,
152
+ cliCommandOptions: { keycloakVersion, port, realmJsonFilePath }
153
+ });
154
+ }
155
+ });
156
+ }
93
157
 
94
- optionsKeys.push(name);
158
+ {
159
+ const commandName = "eject-page";
95
160
 
96
- return name;
97
- })(),
98
- description: ["Keycloak server port.", "Example `--port 8085`"].join(" "),
99
- defaultValue: undefined
100
- })
101
- .option({
102
- key: "keycloakVersion",
103
- name: (() => {
104
- const name = "keycloak-version";
105
-
106
- optionsKeys.push(name);
107
-
108
- return name;
109
- })(),
110
- description: [
111
- "Use a specific version of Keycloak.",
112
- "Example `--keycloak-version 21.1.1`"
113
- ].join(" "),
114
- defaultValue: undefined
115
- })
116
- .option({
117
- key: "realmJsonFilePath",
118
- name: (() => {
119
- const name = "import";
120
-
121
- optionsKeys.push(name);
122
-
123
- return name;
124
- })(),
125
- defaultValue: undefined,
126
- description: [
127
- "Import your own realm configuration file",
128
- "Example `--import path/to/myrealm-realm.json`"
129
- ].join(" ")
130
- })
131
- .task({
132
- skip,
133
- handler: async cliCommandOptions => {
134
- const { command } = await import("./start-keycloak");
161
+ program
162
+ .command({
163
+ name: commandName,
164
+ description: "Eject a Keycloak page."
165
+ })
166
+ .task({
167
+ skip,
168
+ handler: async ({ projectDirPath }) => {
169
+ const buildContext = getBuildContext({ projectDirPath });
135
170
 
136
- await command({ cliCommandOptions });
137
- }
138
- });
171
+ callHandlerIfAny({ buildContext, commandName });
139
172
 
140
- program
141
- .command({
142
- name: "eject-page",
143
- description: "Eject a Keycloak page."
144
- })
145
- .task({
146
- skip,
147
- handler: async cliCommandOptions => {
148
- const { command } = await import("./eject-page");
173
+ const { command } = await import("./eject-page");
149
174
 
150
- await command({ cliCommandOptions });
151
- }
152
- });
175
+ await command({ buildContext });
176
+ }
177
+ });
178
+ }
153
179
 
154
- program
155
- .command({
156
- name: "add-story",
157
- description: "Add *.stories.tsx file for a specific page to in your Storybook."
158
- })
159
- .task({
160
- skip,
161
- handler: async cliCommandOptions => {
162
- const { command } = await import("./add-story");
180
+ {
181
+ const commandName = "add-story";
163
182
 
164
- await command({ cliCommandOptions });
165
- }
166
- });
183
+ program
184
+ .command({
185
+ name: commandName,
186
+ description:
187
+ "Add *.stories.tsx file for a specific page to in your Storybook."
188
+ })
189
+ .task({
190
+ skip,
191
+ handler: async ({ projectDirPath }) => {
192
+ const buildContext = getBuildContext({ projectDirPath });
167
193
 
168
- program
169
- .command({
170
- name: "initialize-email-theme",
171
- description: "Initialize an email theme."
172
- })
173
- .task({
174
- skip,
175
- handler: async cliCommandOptions => {
176
- const { command } = await import("./initialize-email-theme");
194
+ callHandlerIfAny({ buildContext, commandName });
177
195
 
178
- await command({ cliCommandOptions });
179
- }
180
- });
196
+ const { command } = await import("./add-story");
197
+
198
+ await command({ buildContext });
199
+ }
200
+ });
201
+ }
202
+
203
+ {
204
+ const comandName = "initialize-login-theme";
205
+
206
+ program
207
+ .command({
208
+ name: comandName,
209
+ description: "Initialize an email theme."
210
+ })
211
+ .task({
212
+ skip,
213
+ handler: async ({ projectDirPath }) => {
214
+ const buildContext = getBuildContext({ projectDirPath });
215
+
216
+ const { command } = await import("./initialize-email-theme");
217
+
218
+ await command({ buildContext });
219
+ }
220
+ });
221
+ }
181
222
 
182
223
  program
183
224
  .command({
@@ -186,42 +227,58 @@ program
186
227
  })
187
228
  .task({
188
229
  skip,
189
- handler: async cliCommandOptions => {
230
+ handler: async ({ projectDirPath }) => {
231
+ const buildContext = getBuildContext({ projectDirPath });
232
+
190
233
  const { command } = await import("./initialize-account-theme");
191
234
 
192
- await command({ cliCommandOptions });
235
+ await command({ buildContext });
193
236
  }
194
237
  });
195
238
 
196
- program
197
- .command({
198
- name: "copy-keycloak-resources-to-public",
199
- description:
200
- "(Webpack/Create-React-App only) Copy Keycloak default theme resources to the public directory."
201
- })
202
- .task({
203
- skip,
204
- handler: async cliCommandOptions => {
205
- const { command } = await import("./copy-keycloak-resources-to-public");
239
+ {
240
+ const commandName = "copy-keycloak-resources-to-public";
241
+
242
+ program
243
+ .command({
244
+ name: commandName,
245
+ description:
246
+ "(Webpack/Create-React-App only) Copy Keycloak default theme resources to the public directory."
247
+ })
248
+ .task({
249
+ skip,
250
+ handler: async ({ projectDirPath }) => {
251
+ const buildContext = getBuildContext({ projectDirPath });
252
+
253
+ const { command } = await import("./copy-keycloak-resources-to-public");
254
+
255
+ await command({ buildContext });
256
+ }
257
+ });
258
+ }
206
259
 
207
- await command({ cliCommandOptions });
208
- }
209
- });
260
+ {
261
+ const commandName = "update-kc-gen";
210
262
 
211
- program
212
- .command({
213
- name: "update-kc-gen",
214
- description:
215
- "(Webpack/Create-React-App only) Create/update the kc.gen.ts file in your project."
216
- })
217
- .task({
218
- skip,
219
- handler: async cliCommandOptions => {
220
- const { command } = await import("./update-kc-gen");
263
+ program
264
+ .command({
265
+ name: commandName,
266
+ description:
267
+ "(Webpack/Create-React-App only) Create/update the kc.gen.ts file in your project."
268
+ })
269
+ .task({
270
+ skip,
271
+ handler: async ({ projectDirPath }) => {
272
+ const buildContext = getBuildContext({ projectDirPath });
221
273
 
222
- await command({ cliCommandOptions });
223
- }
224
- });
274
+ callHandlerIfAny({ buildContext, commandName });
275
+
276
+ const { command } = await import("./update-kc-gen");
277
+
278
+ await command({ buildContext });
279
+ }
280
+ });
281
+ }
225
282
 
226
283
  // Fallback to build command if no command is provided
227
284
  {
@@ -7,7 +7,6 @@ import {
7
7
  dirname as pathDirname
8
8
  } from "path";
9
9
  import { getAbsoluteAndInOsFormatPath } from "../tools/getAbsoluteAndInOsFormatPath";
10
- import type { CliCommandOptions } from "../main";
11
10
  import { z } from "zod";
12
11
  import * as fs from "fs";
13
12
  import { assert, type Equals } from "tsafe/assert";
@@ -129,14 +128,12 @@ export type ResolvedViteConfig = {
129
128
  };
130
129
 
131
130
  export function getBuildContext(params: {
132
- cliCommandOptions: CliCommandOptions;
131
+ projectDirPath: string | undefined;
133
132
  }): BuildContext {
134
- const { cliCommandOptions } = params;
135
-
136
133
  const projectDirPath =
137
- cliCommandOptions.projectDirPath !== undefined
134
+ params.projectDirPath !== undefined
138
135
  ? getAbsoluteAndInOsFormatPath({
139
- pathIsh: cliCommandOptions.projectDirPath,
136
+ pathIsh: params.projectDirPath,
140
137
  cwd: process.cwd()
141
138
  })
142
139
  : process.cwd();
@@ -71,3 +71,8 @@ export type AccountThemePageId = (typeof ACCOUNT_THEME_PAGE_IDS)[number];
71
71
  export const CONTAINER_NAME = "keycloak-keycloakify";
72
72
 
73
73
  export const FALLBACK_LANGUAGE_TAG = "en";
74
+
75
+ export const CUSTOM_HANDLER_ENV_NAMES = {
76
+ COMMAND_NAME: "KEYCLOAKIFY_COMMAND_NAME",
77
+ BUILD_CONTEXT: "KEYCLOAKIFY_BUILD_CONTEXT"
78
+ };
@@ -0,0 +1,35 @@
1
+ import { assert } from "tsafe/assert";
2
+ import type { BuildContext } from "./buildContext";
3
+ import { CUSTOM_HANDLER_ENV_NAMES } from "./constants";
4
+
5
+ export const BIN_NAME = "_keycloakify-custom-handler";
6
+
7
+ export const NOT_IMPLEMENTED_EXIT_CODE = 78;
8
+
9
+ export type CommandName = "update-kc-gen" | "eject-page" | "add-story";
10
+
11
+ export type ApiVersion = "v1";
12
+
13
+ export function readParams(params: { apiVersion: ApiVersion }) {
14
+ const { apiVersion } = params;
15
+
16
+ assert(apiVersion === "v1");
17
+
18
+ const commandName = (() => {
19
+ const envValue = process.env[CUSTOM_HANDLER_ENV_NAMES.COMMAND_NAME];
20
+
21
+ assert(envValue !== undefined);
22
+
23
+ return envValue as CommandName;
24
+ })();
25
+
26
+ const buildContext = (() => {
27
+ const envValue = process.env[CUSTOM_HANDLER_ENV_NAMES.BUILD_CONTEXT];
28
+
29
+ assert(envValue !== undefined);
30
+
31
+ return JSON.parse(envValue) as BuildContext;
32
+ })();
33
+
34
+ return { commandName, buildContext };
35
+ }
@@ -0,0 +1,47 @@
1
+ import { assert, type Equals } from "tsafe/assert";
2
+ import type { BuildContext } from "./buildContext";
3
+ import { CUSTOM_HANDLER_ENV_NAMES } from "./constants";
4
+ import {
5
+ NOT_IMPLEMENTED_EXIT_CODE,
6
+ type CommandName,
7
+ BIN_NAME,
8
+ ApiVersion
9
+ } from "./customHandler";
10
+ import * as child_process from "child_process";
11
+ import { is } from "tsafe/is";
12
+ import { dirname as pathDirname } from "path";
13
+ import * as fs from "fs";
14
+
15
+ assert<Equals<ApiVersion, "v1">>();
16
+
17
+ export function callHandlerIfAny(params: {
18
+ commandName: CommandName;
19
+ buildContext: BuildContext;
20
+ }) {
21
+ const { commandName, buildContext } = params;
22
+
23
+ if (!fs.readdirSync(pathDirname(process.argv[1])).includes(BIN_NAME)) {
24
+ return;
25
+ }
26
+
27
+ try {
28
+ child_process.execSync(`npx ${BIN_NAME}`, {
29
+ stdio: "inherit",
30
+ env: {
31
+ ...process.env,
32
+ [CUSTOM_HANDLER_ENV_NAMES.COMMAND_NAME]: commandName,
33
+ [CUSTOM_HANDLER_ENV_NAMES.BUILD_CONTEXT]: JSON.stringify(buildContext)
34
+ }
35
+ });
36
+ } catch (error) {
37
+ assert(is<child_process.ExecException>(error));
38
+
39
+ if (error.code === NOT_IMPLEMENTED_EXIT_CODE) {
40
+ return;
41
+ }
42
+
43
+ process.exit(error.code);
44
+ }
45
+
46
+ process.exit(0);
47
+ }
@@ -1,6 +1,5 @@
1
- import { getBuildContext } from "../shared/buildContext";
1
+ import type { BuildContext } from "../shared/buildContext";
2
2
  import { exclude } from "tsafe/exclude";
3
- import type { CliCommandOptions as CliCommandOptions_common } from "../main";
4
3
  import { promptKeycloakVersion } from "../shared/promptKeycloakVersion";
5
4
  import { CONTAINER_NAME } from "../shared/constants";
6
5
  import { SemVer } from "../tools/SemVer";
@@ -29,13 +28,14 @@ import { existsAsync } from "../tools/fs.existsAsync";
29
28
  import { rm } from "../tools/fs.rm";
30
29
  import { downloadAndExtractArchive } from "../tools/downloadAndExtractArchive";
31
30
 
32
- export type CliCommandOptions = CliCommandOptions_common & {
33
- port: number | undefined;
34
- keycloakVersion: string | undefined;
35
- realmJsonFilePath: string | undefined;
36
- };
37
-
38
- export async function command(params: { cliCommandOptions: CliCommandOptions }) {
31
+ export async function command(params: {
32
+ buildContext: BuildContext;
33
+ cliCommandOptions: {
34
+ port: number | undefined;
35
+ keycloakVersion: string | undefined;
36
+ realmJsonFilePath: string | undefined;
37
+ };
38
+ }) {
39
39
  exit_if_docker_not_installed: {
40
40
  let commandOutput: string | undefined = undefined;
41
41
 
@@ -88,9 +88,7 @@ export async function command(params: { cliCommandOptions: CliCommandOptions })
88
88
  process.exit(1);
89
89
  }
90
90
 
91
- const { cliCommandOptions } = params;
92
-
93
- const buildContext = getBuildContext({ cliCommandOptions });
91
+ const { cliCommandOptions, buildContext } = params;
94
92
 
95
93
  const { dockerImageTag } = await (async () => {
96
94
  if (cliCommandOptions.keycloakVersion !== undefined) {
@@ -1,13 +1,8 @@
1
- import type { CliCommandOptions } from "./main";
2
- import { getBuildContext } from "./shared/buildContext";
1
+ import type { BuildContext } from "./shared/buildContext";
3
2
  import { generateKcGenTs } from "./shared/generateKcGenTs";
4
3
 
5
- export async function command(params: { cliCommandOptions: CliCommandOptions }) {
6
- const { cliCommandOptions } = params;
7
-
8
- const buildContext = getBuildContext({
9
- cliCommandOptions
10
- });
4
+ export async function command(params: { buildContext: BuildContext }) {
5
+ const { buildContext } = params;
11
6
 
12
7
  await generateKcGenTs({ buildContext });
13
8
  }
@@ -122,9 +122,7 @@ export function keycloakify(params: keycloakify.Params) {
122
122
  }
123
123
 
124
124
  const buildContext = getBuildContext({
125
- cliCommandOptions: {
126
- projectDirPath
127
- }
125
+ projectDirPath
128
126
  });
129
127
 
130
128
  copyKeycloakResourcesToPublic({ buildContext }),
@@ -233,10 +233,9 @@ function ensureSingleOrNone(arg0) {
233
233
  (0,assert/* assert */.h)();
234
234
  function getBuildContext(params) {
235
235
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
236
- const { cliCommandOptions } = params;
237
- const projectDirPath = cliCommandOptions.projectDirPath !== undefined
236
+ const projectDirPath = params.projectDirPath !== undefined
238
237
  ? getAbsoluteAndInOsFormatPath({
239
- pathIsh: cliCommandOptions.projectDirPath,
238
+ pathIsh: params.projectDirPath,
240
239
  cwd: process.cwd()
241
240
  })
242
241
  : process.cwd();
@@ -830,6 +829,7 @@ __nccwpck_require__.r(__webpack_exports__);
830
829
  /* harmony export */ "ACCOUNT_THEME_PAGE_IDS": () => (/* binding */ ACCOUNT_THEME_PAGE_IDS),
831
830
  /* harmony export */ "BUILD_FOR_KEYCLOAK_MAJOR_VERSION_ENV_NAME": () => (/* binding */ BUILD_FOR_KEYCLOAK_MAJOR_VERSION_ENV_NAME),
832
831
  /* harmony export */ "CONTAINER_NAME": () => (/* binding */ CONTAINER_NAME),
832
+ /* harmony export */ "CUSTOM_HANDLER_ENV_NAMES": () => (/* binding */ CUSTOM_HANDLER_ENV_NAMES),
833
833
  /* harmony export */ "FALLBACK_LANGUAGE_TAG": () => (/* binding */ FALLBACK_LANGUAGE_TAG),
834
834
  /* harmony export */ "LOGIN_THEME_PAGE_IDS": () => (/* binding */ LOGIN_THEME_PAGE_IDS),
835
835
  /* harmony export */ "THEME_TYPES": () => (/* binding */ THEME_TYPES),
@@ -896,6 +896,10 @@ const ACCOUNT_THEME_PAGE_IDS = [
896
896
  ];
897
897
  const CONTAINER_NAME = "keycloak-keycloakify";
898
898
  const FALLBACK_LANGUAGE_TAG = "en";
899
+ const CUSTOM_HANDLER_ENV_NAMES = {
900
+ COMMAND_NAME: "KEYCLOAKIFY_COMMAND_NAME",
901
+ BUILD_CONTEXT: "KEYCLOAKIFY_BUILD_CONTEXT"
902
+ };
899
903
  //# sourceMappingURL=constants.js.map
900
904
 
901
905
  /***/ }),
@@ -1531,9 +1535,7 @@ function keycloakify(params) {
1531
1535
  process.exit(0);
1532
1536
  }
1533
1537
  const buildContext = (0, buildContext_1.getBuildContext)({
1534
- cliCommandOptions: {
1535
- projectDirPath
1536
- }
1538
+ projectDirPath
1537
1539
  });
1538
1540
  (0, copyKeycloakResourcesToPublic_1.copyKeycloakResourcesToPublic)({ buildContext }),
1539
1541
  await (0, generateKcGenTs_1.generateKcGenTs)({ buildContext });