keycloakify 10.0.0-rc.65 → 10.0.0-rc.67

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 (53) hide show
  1. package/bin/193.index.js +51 -0
  2. package/bin/246.index.js +371 -75118
  3. package/bin/363.index.js +64 -165
  4. package/bin/453.index.js +603 -23
  5. package/bin/{890.index.js → 456.index.js} +1831 -3
  6. package/bin/490.index.js +75195 -0
  7. package/bin/526.index.js +294 -173
  8. package/bin/538.index.js +1 -509
  9. package/bin/{203.index.js → 751.index.js} +306 -305
  10. package/bin/772.index.js +1 -1
  11. package/bin/{190.index.js → 837.index.js} +259 -35
  12. package/bin/932.index.js +1 -578
  13. package/bin/97.index.js +594 -14
  14. package/bin/main.js +8 -8
  15. package/bin/shared/KeycloakVersionRange.d.ts +5 -0
  16. package/bin/shared/KeycloakVersionRange.js.map +1 -0
  17. package/bin/shared/buildContext.d.ts +16 -0
  18. package/bin/shared/buildContext.js.map +1 -0
  19. package/bin/shared/constants.d.ts +1 -1
  20. package/bin/shared/constants.js.map +1 -1
  21. package/bin/shared/copyKeycloakResourcesToPublic.d.ts +8 -0
  22. package/bin/shared/copyKeycloakResourcesToPublic.js.map +1 -0
  23. package/bin/shared/downloadKeycloakDefaultTheme.d.ts +10 -0
  24. package/bin/shared/downloadKeycloakDefaultTheme.js.map +1 -0
  25. package/bin/shared/downloadKeycloakStaticResources.d.ts +9 -0
  26. package/bin/shared/downloadKeycloakStaticResources.js.map +1 -0
  27. package/bin/shared/generateKcGenTs.d.ts +12 -0
  28. package/bin/shared/generateKcGenTs.js.map +1 -0
  29. package/bin/shared/metaInfKeycloakThemes.d.ts +13 -0
  30. package/bin/shared/metaInfKeycloakThemes.js.map +1 -0
  31. package/bin/shared/promptKeycloakVersion.d.ts +7 -0
  32. package/bin/shared/promptKeycloakVersion.js.map +1 -0
  33. package/package.json +21 -12
  34. package/src/bin/add-story.ts +1 -6
  35. package/src/bin/eject-page.ts +7 -8
  36. package/src/bin/initialize-email-theme.ts +1 -6
  37. package/src/bin/keycloakify/buildJars/buildJars.ts +23 -49
  38. package/src/bin/keycloakify/generateResources/generateResourcesForMainTheme.ts +15 -20
  39. package/src/bin/keycloakify/keycloakify.ts +6 -8
  40. package/src/bin/shared/buildContext.ts +434 -42
  41. package/src/bin/shared/constants.ts +2 -1
  42. package/src/bin/shared/generateKcGenTs.ts +2 -6
  43. package/src/bin/start-keycloak/keycloakifyBuild.ts +4 -4
  44. package/src/bin/start-keycloak/start-keycloak.ts +40 -83
  45. package/src/vite-plugin/vite-plugin.ts +5 -4
  46. package/vite-plugin/index.js +341 -117
  47. package/bin/480.index.js +0 -466
  48. package/bin/818.index.js +0 -1802
  49. package/bin/827.index.js +0 -1094
  50. package/bin/shared/constants.js +0 -59
  51. package/src/bin/shared/getImplementedThemeTypes.ts +0 -38
  52. package/src/bin/shared/getJarFileBasename.ts +0 -11
  53. package/src/bin/shared/getThemeSrcDirPath.ts +0 -62
package/bin/453.index.js CHANGED
@@ -22,11 +22,9 @@ __webpack_require__.r(__webpack_exports__);
22
22
  /* harmony import */ var _tools_kebabCaseToSnakeCase__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(17192);
23
23
  /* harmony import */ var tsafe_assert__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(88078);
24
24
  /* harmony import */ var tsafe_assert__WEBPACK_IMPORTED_MODULE_7___default = /*#__PURE__*/__webpack_require__.n(tsafe_assert__WEBPACK_IMPORTED_MODULE_7__);
25
- /* harmony import */ var _shared_getThemeSrcDirPath__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(39216);
26
- /* harmony import */ var _shared_buildContext__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(87751);
27
- /* harmony import */ var chalk__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(78818);
28
- /* harmony import */ var chalk__WEBPACK_IMPORTED_MODULE_10___default = /*#__PURE__*/__webpack_require__.n(chalk__WEBPACK_IMPORTED_MODULE_10__);
29
-
25
+ /* harmony import */ var _shared_buildContext__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(87751);
26
+ /* harmony import */ var chalk__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(78818);
27
+ /* harmony import */ var chalk__WEBPACK_IMPORTED_MODULE_9___default = /*#__PURE__*/__webpack_require__.n(chalk__WEBPACK_IMPORTED_MODULE_9__);
30
28
 
31
29
 
32
30
 
@@ -39,17 +37,17 @@ __webpack_require__.r(__webpack_exports__);
39
37
 
40
38
  async function command(params) {
41
39
  const { cliCommandOptions } = params;
42
- const buildContext = (0,_shared_buildContext__WEBPACK_IMPORTED_MODULE_9__/* .getBuildContext */ .s)({
40
+ const buildContext = (0,_shared_buildContext__WEBPACK_IMPORTED_MODULE_8__/* .getBuildContext */ .s)({
43
41
  cliCommandOptions
44
42
  });
45
- console.log(chalk__WEBPACK_IMPORTED_MODULE_10___default().cyan("Theme type:"));
43
+ console.log(chalk__WEBPACK_IMPORTED_MODULE_9___default().cyan("Theme type:"));
46
44
  const { value: themeType } = await cli_select__WEBPACK_IMPORTED_MODULE_1___default()({
47
45
  values: [..._shared_constants__WEBPACK_IMPORTED_MODULE_2__/* .themeTypes */ .rO]
48
46
  }).catch(() => {
49
47
  process.exit(-1);
50
48
  });
51
49
  console.log(`→ ${themeType}`);
52
- console.log(chalk__WEBPACK_IMPORTED_MODULE_10___default().cyan("Select the page you want to customize:"));
50
+ console.log(chalk__WEBPACK_IMPORTED_MODULE_9___default().cyan("Select the page you want to customize:"));
53
51
  const templateValue = "Template.tsx (Layout common to every page)";
54
52
  const userProfileFormFieldsValue = "UserProfileFormFields.tsx (Renders the form of the register.ftl, login-update-profile.ftl, update-email.ftl and idp-review-user-profile.ftl)";
55
53
  const { value: pageIdOrComponent } = await cli_select__WEBPACK_IMPORTED_MODULE_1___default()({
@@ -70,9 +68,6 @@ async function command(params) {
70
68
  process.exit(-1);
71
69
  });
72
70
  console.log(`→ ${pageIdOrComponent}`);
73
- const { themeSrcDirPath } = (0,_shared_getThemeSrcDirPath__WEBPACK_IMPORTED_MODULE_8__/* .getThemeSrcDirPath */ .f)({
74
- projectDirPath: buildContext.projectDirPath
75
- });
76
71
  const componentBasename = (() => {
77
72
  if (pageIdOrComponent === templateValue) {
78
73
  return "Template.tsx";
@@ -89,7 +84,7 @@ async function command(params) {
89
84
  }
90
85
  return "pages";
91
86
  })();
92
- const targetFilePath = (0,path__WEBPACK_IMPORTED_MODULE_5__.join)(themeSrcDirPath, themeType, pagesOrDot, componentBasename);
87
+ const targetFilePath = (0,path__WEBPACK_IMPORTED_MODULE_5__.join)(buildContext.themeSrcDirPath, themeType, pagesOrDot, componentBasename);
93
88
  if (fs__WEBPACK_IMPORTED_MODULE_4__.existsSync(targetFilePath)) {
94
89
  console.log(`${pageIdOrComponent} is already ejected, ${(0,path__WEBPACK_IMPORTED_MODULE_5__.relative)(process.cwd(), targetFilePath)} already exists`);
95
90
  process.exit(-1);
@@ -103,13 +98,13 @@ async function command(params) {
103
98
  }
104
99
  }
105
100
  fs__WEBPACK_IMPORTED_MODULE_4__.writeFileSync(targetFilePath, Buffer.from(componentCode, "utf8"));
106
- console.log(`${chalk__WEBPACK_IMPORTED_MODULE_10___default().green("✓")} ${chalk__WEBPACK_IMPORTED_MODULE_10___default().bold((0,path__WEBPACK_IMPORTED_MODULE_5__.join)(".", (0,path__WEBPACK_IMPORTED_MODULE_5__.relative)(process.cwd(), targetFilePath)))} copy pasted from the Keycloakify source code into your project`);
101
+ console.log(`${chalk__WEBPACK_IMPORTED_MODULE_9___default().green("✓")} ${chalk__WEBPACK_IMPORTED_MODULE_9___default().bold((0,path__WEBPACK_IMPORTED_MODULE_5__.join)(".", (0,path__WEBPACK_IMPORTED_MODULE_5__.relative)(process.cwd(), targetFilePath)))} copy pasted from the Keycloakify source code into your project`);
107
102
  edit_KcApp: {
108
103
  if (pageIdOrComponent !== templateValue &&
109
104
  pageIdOrComponent !== userProfileFormFieldsValue) {
110
105
  break edit_KcApp;
111
106
  }
112
- const kcAppTsxPath = (0,path__WEBPACK_IMPORTED_MODULE_5__.join)(themeSrcDirPath, themeType, "KcPage.tsx");
107
+ const kcAppTsxPath = (0,path__WEBPACK_IMPORTED_MODULE_5__.join)(buildContext.themeSrcDirPath, themeType, "KcPage.tsx");
113
108
  const kcAppTsxCode = fs__WEBPACK_IMPORTED_MODULE_4__.readFileSync(kcAppTsxPath).toString("utf8");
114
109
  const modifiedKcAppTsxCode = (() => {
115
110
  switch (pageIdOrComponent) {
@@ -121,11 +116,11 @@ async function command(params) {
121
116
  (0,tsafe_assert__WEBPACK_IMPORTED_MODULE_7__.assert)(false);
122
117
  })();
123
118
  if (kcAppTsxCode === modifiedKcAppTsxCode) {
124
- console.log(chalk__WEBPACK_IMPORTED_MODULE_10___default().red("Unable to automatically update KcPage.tsx, please update it manually"));
119
+ console.log(chalk__WEBPACK_IMPORTED_MODULE_9___default().red("Unable to automatically update KcPage.tsx, please update it manually"));
125
120
  return;
126
121
  }
127
122
  fs__WEBPACK_IMPORTED_MODULE_4__.writeFileSync(kcAppTsxPath, Buffer.from(modifiedKcAppTsxCode, "utf8"));
128
- console.log(`${chalk__WEBPACK_IMPORTED_MODULE_10___default().green("✓")} ${chalk__WEBPACK_IMPORTED_MODULE_10___default().bold((0,path__WEBPACK_IMPORTED_MODULE_5__.join)(".", (0,path__WEBPACK_IMPORTED_MODULE_5__.relative)(process.cwd(), kcAppTsxPath)))} Updated`);
123
+ console.log(`${chalk__WEBPACK_IMPORTED_MODULE_9___default().green("✓")} ${chalk__WEBPACK_IMPORTED_MODULE_9___default().bold((0,path__WEBPACK_IMPORTED_MODULE_5__.join)(".", (0,path__WEBPACK_IMPORTED_MODULE_5__.relative)(process.cwd(), kcAppTsxPath)))} Updated`);
129
124
  return;
130
125
  }
131
126
  const userProfileFormFieldComponentName = "UserProfileFormFields";
@@ -133,11 +128,11 @@ async function command(params) {
133
128
  ``,
134
129
  `You now need to update your page router:`,
135
130
  ``,
136
- `${chalk__WEBPACK_IMPORTED_MODULE_10___default().bold((0,path__WEBPACK_IMPORTED_MODULE_5__.join)(".", (0,path__WEBPACK_IMPORTED_MODULE_5__.relative)(process.cwd(), themeSrcDirPath), themeType, "KcPage.tsx"))}:`,
137
- chalk__WEBPACK_IMPORTED_MODULE_10___default().grey("```"),
131
+ `${chalk__WEBPACK_IMPORTED_MODULE_9___default().bold((0,path__WEBPACK_IMPORTED_MODULE_5__.join)(".", (0,path__WEBPACK_IMPORTED_MODULE_5__.relative)(process.cwd(), buildContext.themeSrcDirPath), themeType, "KcPage.tsx"))}:`,
132
+ chalk__WEBPACK_IMPORTED_MODULE_9___default().grey("```"),
138
133
  `// ...`,
139
134
  ``,
140
- chalk__WEBPACK_IMPORTED_MODULE_10___default().green(`+const ${componentBasename.replace(/.tsx$/, "")} = lazy(() => import("./pages/${componentBasename}"));`),
135
+ chalk__WEBPACK_IMPORTED_MODULE_9___default().green(`+const ${componentBasename.replace(/.tsx$/, "")} = lazy(() => import("./pages/${componentBasename}"));`),
141
136
  ...[
142
137
  ``,
143
138
  ` export default function KcPage(props: { kcContext: KcContext; }) {`,
@@ -170,18 +165,603 @@ async function command(params) {
170
165
  ` }`
171
166
  ].map(line => {
172
167
  if (line.startsWith("+")) {
173
- return chalk__WEBPACK_IMPORTED_MODULE_10___default().green(line);
168
+ return chalk__WEBPACK_IMPORTED_MODULE_9___default().green(line);
174
169
  }
175
170
  if (line.startsWith("-")) {
176
- return chalk__WEBPACK_IMPORTED_MODULE_10___default().red(line);
171
+ return chalk__WEBPACK_IMPORTED_MODULE_9___default().red(line);
177
172
  }
178
- return chalk__WEBPACK_IMPORTED_MODULE_10___default().grey(line);
173
+ return chalk__WEBPACK_IMPORTED_MODULE_9___default().grey(line);
179
174
  }),
180
- chalk__WEBPACK_IMPORTED_MODULE_10___default().grey("```")
175
+ chalk__WEBPACK_IMPORTED_MODULE_9___default().grey("```")
181
176
  ].join("\n"));
182
177
  }
183
178
  //# sourceMappingURL=eject-page.js.map
184
179
 
180
+ /***/ }),
181
+
182
+ /***/ 17192:
183
+ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
184
+
185
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
186
+ /* harmony export */ "A": () => (/* binding */ kebabCaseToCamelCase)
187
+ /* harmony export */ });
188
+ /* harmony import */ var tsafe_capitalize__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(61502);
189
+
190
+ function kebabCaseToCamelCase(kebabCaseString) {
191
+ const [first, ...rest] = kebabCaseString.split("-");
192
+ return [first, ...rest.map(tsafe_capitalize__WEBPACK_IMPORTED_MODULE_0__.capitalize)].join("");
193
+ }
194
+ //# sourceMappingURL=kebabCaseToSnakeCase.js.map
195
+
196
+ /***/ }),
197
+
198
+ /***/ 18512:
199
+ /***/ ((module) => {
200
+
201
+
202
+ const x = module.exports;
203
+ const ESC = '\u001B[';
204
+ const OSC = '\u001B]';
205
+ const BEL = '\u0007';
206
+ const SEP = ';';
207
+ const isTerminalApp = process.env.TERM_PROGRAM === 'Apple_Terminal';
208
+
209
+ x.cursorTo = (x, y) => {
210
+ if (typeof x !== 'number') {
211
+ throw new TypeError('The `x` argument is required');
212
+ }
213
+
214
+ if (typeof y !== 'number') {
215
+ return ESC + (x + 1) + 'G';
216
+ }
217
+
218
+ return ESC + (y + 1) + ';' + (x + 1) + 'H';
219
+ };
220
+
221
+ x.cursorMove = (x, y) => {
222
+ if (typeof x !== 'number') {
223
+ throw new TypeError('The `x` argument is required');
224
+ }
225
+
226
+ let ret = '';
227
+
228
+ if (x < 0) {
229
+ ret += ESC + (-x) + 'D';
230
+ } else if (x > 0) {
231
+ ret += ESC + x + 'C';
232
+ }
233
+
234
+ if (y < 0) {
235
+ ret += ESC + (-y) + 'A';
236
+ } else if (y > 0) {
237
+ ret += ESC + y + 'B';
238
+ }
239
+
240
+ return ret;
241
+ };
242
+
243
+ x.cursorUp = count => ESC + (typeof count === 'number' ? count : 1) + 'A';
244
+ x.cursorDown = count => ESC + (typeof count === 'number' ? count : 1) + 'B';
245
+ x.cursorForward = count => ESC + (typeof count === 'number' ? count : 1) + 'C';
246
+ x.cursorBackward = count => ESC + (typeof count === 'number' ? count : 1) + 'D';
247
+
248
+ x.cursorLeft = ESC + 'G';
249
+ x.cursorSavePosition = ESC + (isTerminalApp ? '7' : 's');
250
+ x.cursorRestorePosition = ESC + (isTerminalApp ? '8' : 'u');
251
+ x.cursorGetPosition = ESC + '6n';
252
+ x.cursorNextLine = ESC + 'E';
253
+ x.cursorPrevLine = ESC + 'F';
254
+ x.cursorHide = ESC + '?25l';
255
+ x.cursorShow = ESC + '?25h';
256
+
257
+ x.eraseLines = count => {
258
+ let clear = '';
259
+
260
+ for (let i = 0; i < count; i++) {
261
+ clear += x.eraseLine + (i < count - 1 ? x.cursorUp() : '');
262
+ }
263
+
264
+ if (count) {
265
+ clear += x.cursorLeft;
266
+ }
267
+
268
+ return clear;
269
+ };
270
+
271
+ x.eraseEndLine = ESC + 'K';
272
+ x.eraseStartLine = ESC + '1K';
273
+ x.eraseLine = ESC + '2K';
274
+ x.eraseDown = ESC + 'J';
275
+ x.eraseUp = ESC + '1J';
276
+ x.eraseScreen = ESC + '2J';
277
+ x.scrollUp = ESC + 'S';
278
+ x.scrollDown = ESC + 'T';
279
+
280
+ x.clearScreen = '\u001Bc';
281
+
282
+ x.clearTerminal = process.platform === 'win32' ?
283
+ `${x.eraseScreen}${ESC}0f` :
284
+ // 1. Erases the screen (Only done in case `2` is not supported)
285
+ // 2. Erases the whole screen including scrollback buffer
286
+ // 3. Moves cursor to the top-left position
287
+ // More info: https://www.real-world-systems.com/docs/ANSIcode.html
288
+ `${x.eraseScreen}${ESC}3J${ESC}H`;
289
+
290
+ x.beep = BEL;
291
+
292
+ x.link = (text, url) => {
293
+ return [
294
+ OSC,
295
+ '8',
296
+ SEP,
297
+ SEP,
298
+ url,
299
+ BEL,
300
+ text,
301
+ OSC,
302
+ '8',
303
+ SEP,
304
+ SEP,
305
+ BEL
306
+ ].join('');
307
+ };
308
+
309
+ x.image = (buf, opts) => {
310
+ opts = opts || {};
311
+
312
+ let ret = OSC + '1337;File=inline=1';
313
+
314
+ if (opts.width) {
315
+ ret += `;width=${opts.width}`;
316
+ }
317
+
318
+ if (opts.height) {
319
+ ret += `;height=${opts.height}`;
320
+ }
321
+
322
+ if (opts.preserveAspectRatio === false) {
323
+ ret += ';preserveAspectRatio=0';
324
+ }
325
+
326
+ return ret + ':' + buf.toString('base64') + BEL;
327
+ };
328
+
329
+ x.iTerm = {};
330
+
331
+ x.iTerm.setCwd = cwd => OSC + '50;CurrentDir=' + (cwd || process.cwd()) + BEL;
332
+
333
+
334
+ /***/ }),
335
+
336
+ /***/ 39340:
337
+ /***/ ((__unused_webpack_module, exports) => {
338
+
339
+
340
+
341
+ Object.defineProperty(exports, "__esModule", ({
342
+ value: true
343
+ }));
344
+ exports.withPromise = exports.withCallback = void 0;
345
+
346
+ /**
347
+ * Open the input with a normal callback function
348
+ *
349
+ * @param {Input} input - input object
350
+ * @param {function} valueMapper - function which maps the resulting id and value back to the expected format
351
+ * @param {function} callback - callback function
352
+ */
353
+ const withCallback = (input, valueMapper, callback) => {
354
+ input.open();
355
+ input.onSelect((id, value) => callback(valueMapper(id, value)));
356
+ };
357
+ /**
358
+ * Open the input with a promise
359
+ *
360
+ * @param {Input} input - input object
361
+ * @param {function} valueMapper - function which maps the resulting id and value back to the expected format
362
+ */
363
+
364
+
365
+ exports.withCallback = withCallback;
366
+
367
+ const withPromise = (input, valueMapper) => {
368
+ return new Promise((resolve, reject) => {
369
+ input.open();
370
+ input.onSelect((id, value) => {
371
+ if (id === null) {
372
+ reject();
373
+ } else {
374
+ resolve(valueMapper(id, value));
375
+ }
376
+ });
377
+ });
378
+ };
379
+
380
+ exports.withPromise = withPromise;
381
+
382
+ /***/ }),
383
+
384
+ /***/ 99398:
385
+ /***/ ((module, exports, __webpack_require__) => {
386
+
387
+
388
+
389
+ Object.defineProperty(exports, "__esModule", ({
390
+ value: true
391
+ }));
392
+ exports["default"] = void 0;
393
+
394
+ var _input = _interopRequireDefault(__webpack_require__(25730));
395
+
396
+ var _renderer = _interopRequireDefault(__webpack_require__(16059));
397
+
398
+ var _callbackMappers = __webpack_require__(39340);
399
+
400
+ var _valueMappers = __webpack_require__(26730);
401
+
402
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
403
+
404
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
405
+
406
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
407
+
408
+ /**
409
+ * Default options
410
+ */
411
+ const defaultOptions = {
412
+ outputStream: process.stdout,
413
+ inputStream: process.stdin,
414
+ values: [],
415
+ defaultValue: 0,
416
+ selected: '(x)',
417
+ unselected: '( )',
418
+ indentation: 0,
419
+ cleanup: true,
420
+ valueRenderer: value => value
421
+ };
422
+ /**
423
+ * Create an instance of cli-select with the given options
424
+ *
425
+ * @param {object} options - options for cli-select
426
+ * @param {function} callback - if specified, a callback will be used, otherwise a promise gets returned (optional)
427
+ */
428
+
429
+ const creator = (options, callback) => {
430
+ // merge options with default options
431
+ options = _objectSpread({}, defaultOptions, options); // create renderer and input instances
432
+
433
+ const renderer = new _renderer.default(options, options.outputStream);
434
+ const input = new _input.default(options.inputStream);
435
+ input.setDefaultValue(options.defaultValue);
436
+ input.attachRenderer(renderer); // handle array and object values
437
+
438
+ let valueMapper;
439
+
440
+ if (Array.isArray(options.values)) {
441
+ valueMapper = (0, _valueMappers.withArrayValues)(options);
442
+ } else {
443
+ valueMapper = (0, _valueMappers.withObjectValues)(options);
444
+ } // map values
445
+
446
+
447
+ options.values = valueMapper.input;
448
+ input.setValues(options.values); // handle different callback methods
449
+
450
+ if (typeof callback === 'function') {
451
+ return (0, _callbackMappers.withCallback)(input, valueMapper.output, callback);
452
+ } else {
453
+ return (0, _callbackMappers.withPromise)(input, valueMapper.output);
454
+ }
455
+ };
456
+
457
+ exports = module.exports = creator;
458
+ Object.defineProperty(exports, "__esModule", ({
459
+ value: true
460
+ }));
461
+ var _default = creator;
462
+ exports["default"] = _default;
463
+
464
+ /***/ }),
465
+
466
+ /***/ 25730:
467
+ /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
468
+
469
+
470
+
471
+ Object.defineProperty(exports, "__esModule", ({
472
+ value: true
473
+ }));
474
+ exports["default"] = void 0;
475
+
476
+ var _readline = _interopRequireDefault(__webpack_require__(14521));
477
+
478
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
479
+
480
+ /**
481
+ * Handle cli input
482
+ */
483
+ class Input {
484
+ /**
485
+ * Input constructor
486
+ *
487
+ * @param {any} stream - stream to catch (optional)
488
+ */
489
+ constructor(stream = process.stdin) {
490
+ // set default values
491
+ this.stream = stream;
492
+ this.values = [];
493
+ this.selectedValue = 0;
494
+
495
+ this.onSelectListener = () => {};
496
+
497
+ this.onKeyPress = this.onKeyPress.bind(this);
498
+ }
499
+ /**
500
+ * Set the available values
501
+ *
502
+ * @param {array} values - all available values
503
+ */
504
+
505
+
506
+ setValues(values) {
507
+ this.values = values;
508
+
509
+ if (this.renderer) {
510
+ this.renderer.setValues(values);
511
+ }
512
+ }
513
+ /**
514
+ * Set the default value
515
+ *
516
+ * @param {number} defaultValue - default value id
517
+ */
518
+
519
+
520
+ setDefaultValue(defaultValue) {
521
+ this.selectedValue = defaultValue;
522
+ }
523
+ /**
524
+ * Attach a renderer to the input catcher
525
+ *
526
+ * @param {Renderer} renderer - renderer to use for rendering responses
527
+ */
528
+
529
+
530
+ attachRenderer(renderer) {
531
+ this.renderer = renderer;
532
+ this.renderer.setValues(this.values);
533
+ }
534
+ /**
535
+ * Register an on select listener
536
+ *
537
+ * @param {function} listener - listener function which receives two parameters: valueId and value
538
+ */
539
+
540
+
541
+ onSelect(listener) {
542
+ this.onSelectListener = listener;
543
+ }
544
+ /**
545
+ * Open the stream and listen for input
546
+ */
547
+
548
+
549
+ open() {
550
+ // register keypress event
551
+ _readline.default.emitKeypressEvents(this.stream); // handle keypress
552
+
553
+
554
+ this.stream.on('keypress', this.onKeyPress); // initially render the response
555
+
556
+ if (this.renderer) {
557
+ this.renderer.render(this.selectedValue);
558
+ } // hide pressed keys and start listening on input
559
+
560
+
561
+ this.stream.setRawMode(true);
562
+ this.stream.resume();
563
+ }
564
+ /**
565
+ * Close the stream
566
+ *
567
+ * @param {boolean} cancelled - true if no value was selected (optional)
568
+ */
569
+
570
+
571
+ close(cancelled = false) {
572
+ // reset stream properties
573
+ this.stream.setRawMode(false);
574
+ this.stream.pause(); // cleanup the output
575
+
576
+ if (this.renderer) {
577
+ this.renderer.cleanup();
578
+ } // call the on select listener
579
+
580
+
581
+ if (cancelled) {
582
+ this.onSelectListener(null);
583
+ } else {
584
+ this.onSelectListener(this.selectedValue, this.values[this.selectedValue]);
585
+ }
586
+
587
+ this.stream.removeListener('keypress', this.onKeyPress);
588
+ }
589
+ /**
590
+ * Render the response
591
+ */
592
+
593
+
594
+ render() {
595
+ if (!this.renderer) {
596
+ return;
597
+ }
598
+
599
+ this.renderer.render(this.selectedValue);
600
+ }
601
+ /**
602
+ * Handle key press event
603
+ *
604
+ * @param {string} string - input string
605
+ * @param {object} key - object containing information about the pressed key
606
+ */
607
+
608
+
609
+ onKeyPress(string, key) {
610
+ if (key) {
611
+ if (key.name === 'up' && this.selectedValue > 0) {
612
+ this.selectedValue--;
613
+ this.render();
614
+ } else if (key.name === 'down' && this.selectedValue + 1 < this.values.length) {
615
+ this.selectedValue++;
616
+ this.render();
617
+ } else if (key.name === 'return') {
618
+ this.close();
619
+ } else if (key.name === 'escape' || key.name === 'c' && key.ctrl) {
620
+ this.close(true);
621
+ }
622
+ }
623
+ }
624
+
625
+ }
626
+
627
+ exports["default"] = Input;
628
+
629
+ /***/ }),
630
+
631
+ /***/ 16059:
632
+ /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
633
+
634
+
635
+
636
+ Object.defineProperty(exports, "__esModule", ({
637
+ value: true
638
+ }));
639
+ exports["default"] = void 0;
640
+
641
+ var _readline = _interopRequireDefault(__webpack_require__(14521));
642
+
643
+ var _ansiEscapes = __webpack_require__(18512);
644
+
645
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
646
+
647
+ /**
648
+ * Response renderer
649
+ */
650
+ class Renderer {
651
+ /**
652
+ * Renderer constructor
653
+ *
654
+ * @param {object} options - renderer options
655
+ * @param {any} stream - stream to write to (optional)
656
+ */
657
+ constructor(options, stream = process.stdout) {
658
+ this.options = options;
659
+ this.stream = stream;
660
+ this.values = [];
661
+ this.initialRender = true;
662
+ }
663
+ /**
664
+ * Set the available values
665
+ *
666
+ * @param {array} values - all available values
667
+ */
668
+
669
+
670
+ setValues(values) {
671
+ this.values = values;
672
+ }
673
+ /**
674
+ * Render the values
675
+ *
676
+ * @param {number} selectedValue - selected value (optional)
677
+ */
678
+
679
+
680
+ render(selectedValue = 0) {
681
+ if (this.initialRender) {
682
+ // hide the cursor initially
683
+ this.initialRender = false;
684
+ this.stream.write(_ansiEscapes.cursorHide);
685
+ } else {
686
+ // remove previous lines and values
687
+ this.stream.write((0, _ansiEscapes.eraseLines)(this.values.length));
688
+ } // output the current values
689
+
690
+
691
+ this.values.forEach((value, index) => {
692
+ const symbol = selectedValue === index ? this.options.selected : this.options.unselected;
693
+ const indentation = ' '.repeat(this.options.indentation);
694
+ const renderedValue = this.options.valueRenderer(value, selectedValue === index);
695
+ const end = index !== this.values.length - 1 ? '\n' : '';
696
+ this.stream.write(indentation + symbol + ' ' + renderedValue + end);
697
+ });
698
+ }
699
+ /**
700
+ * Cleanup the console at the end
701
+ */
702
+
703
+
704
+ cleanup() {
705
+ this.stream.write((0, _ansiEscapes.eraseLines)(this.values.length));
706
+ this.stream.write(_ansiEscapes.cursorShow);
707
+ }
708
+
709
+ }
710
+
711
+ exports["default"] = Renderer;
712
+
713
+ /***/ }),
714
+
715
+ /***/ 26730:
716
+ /***/ ((__unused_webpack_module, exports) => {
717
+
718
+
719
+
720
+ Object.defineProperty(exports, "__esModule", ({
721
+ value: true
722
+ }));
723
+ exports.withObjectValues = exports.withArrayValues = void 0;
724
+
725
+ /**
726
+ * Map incoming and outgoing values if the initial values are an array
727
+ *
728
+ * @param {object} options - cli-select options
729
+ */
730
+ const withArrayValues = options => {
731
+ return {
732
+ input: options.values,
733
+ output: (id, value) => {
734
+ return {
735
+ id,
736
+ value
737
+ };
738
+ }
739
+ };
740
+ };
741
+ /**
742
+ * Map incoming and outgoing values if the initial values are an object
743
+ *
744
+ * @param {object} options - cli-select options
745
+ */
746
+
747
+
748
+ exports.withArrayValues = withArrayValues;
749
+
750
+ const withObjectValues = options => {
751
+ const originalValues = options.values;
752
+ return {
753
+ input: Object.values(originalValues),
754
+ output: (id, value) => {
755
+ return {
756
+ id: Object.keys(originalValues)[id],
757
+ value
758
+ };
759
+ }
760
+ };
761
+ };
762
+
763
+ exports.withObjectValues = withObjectValues;
764
+
185
765
  /***/ })
186
766
 
187
767
  };