keycloakify 10.0.0-rc.118 → 10.0.0-rc.119

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 (48) hide show
  1. package/bin/{490.index.js → 246.index.js} +20 -2
  2. package/bin/31.index.js +151 -159
  3. package/bin/440.index.js +27 -22
  4. package/bin/526.index.js +168 -56
  5. package/bin/599.index.js +560 -0
  6. package/bin/622.index.js +4 -2
  7. package/bin/{36.index.js → 678.index.js} +577 -71
  8. package/bin/{180.index.js → 697.index.js} +611 -526
  9. package/bin/743.index.js +70 -0
  10. package/bin/780.index.js +729 -0
  11. package/bin/932.index.js +725 -48
  12. package/bin/{966.index.js → 941.index.js} +2 -19
  13. package/bin/main.js +19 -7
  14. package/bin/shared/buildContext.d.ts +28 -19
  15. package/bin/shared/buildContext.js.map +1 -1
  16. package/bin/shared/getLatestsSemVersionedTag.d.ts +10 -0
  17. package/bin/shared/getLatestsSemVersionedTag.js.map +1 -0
  18. package/bin/shared/promptKeycloakVersion.js.map +1 -1
  19. package/package.json +24 -5
  20. package/src/bin/initialize-account-theme/copyBoilerplate.ts +32 -0
  21. package/src/bin/initialize-account-theme/index.ts +1 -0
  22. package/src/bin/initialize-account-theme/initialize-account-theme.ts +95 -0
  23. package/src/bin/initialize-account-theme/initializeAccountTheme_multiPage.ts +21 -0
  24. package/src/bin/initialize-account-theme/initializeAccountTheme_singlePage.ts +150 -0
  25. package/src/bin/initialize-account-theme/src/multi-page/KcContext.ts +12 -0
  26. package/src/bin/initialize-account-theme/src/multi-page/KcPage.tsx +25 -0
  27. package/src/bin/initialize-account-theme/src/multi-page/KcPageStory.tsx +38 -0
  28. package/src/bin/initialize-account-theme/src/multi-page/i18n.ts +5 -0
  29. package/src/bin/initialize-account-theme/src/single-page/KcContext.ts +7 -0
  30. package/src/bin/initialize-account-theme/src/single-page/KcPage.tsx +11 -0
  31. package/src/bin/initialize-account-theme/updateAccountThemeImplementationInConfig.ts +92 -0
  32. package/src/bin/keycloakify/buildJars/buildJar.ts +2 -2
  33. package/src/bin/keycloakify/buildJars/buildJars.ts +3 -4
  34. package/src/bin/keycloakify/generateResources/generateResourcesForMainTheme.ts +26 -20
  35. package/src/bin/keycloakify/keycloakify.ts +1 -1
  36. package/src/bin/keycloakify/replacers/replaceImportsInJsCode/replaceImportsInJsCode.ts +2 -2
  37. package/src/bin/main.ts +14 -0
  38. package/src/bin/shared/buildContext.ts +246 -225
  39. package/src/bin/shared/getLatestsSemVersionedTag.ts +180 -0
  40. package/src/bin/shared/promptKeycloakVersion.ts +8 -77
  41. package/src/bin/start-keycloak/appBuild.ts +13 -9
  42. package/src/bin/tools/downloadAndExtractArchive.ts +4 -2
  43. package/src/bin/tools/npmInstall.ts +63 -0
  44. package/src/bin/tools/octokit-addons/getLatestsSemVersionedTag.ts +3 -2
  45. package/src/bin/tsconfig.json +3 -1
  46. package/src/vite-plugin/vite-plugin.ts +7 -5
  47. package/vite-plugin/index.js +156 -180
  48. package/vite-plugin/vite-plugin.d.ts +6 -4
package/bin/932.index.js CHANGED
@@ -14,7 +14,7 @@ __webpack_require__.r(__webpack_exports__);
14
14
  /* harmony import */ var path__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(71017);
15
15
  /* harmony import */ var path__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(path__WEBPACK_IMPORTED_MODULE_1__);
16
16
  /* harmony import */ var _tools_transformCodebase__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(60332);
17
- /* harmony import */ var _shared_promptKeycloakVersion__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(95781);
17
+ /* harmony import */ var _shared_promptKeycloakVersion__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(82635);
18
18
  /* harmony import */ var _shared_buildContext__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(56031);
19
19
  /* harmony import */ var fs__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(57147);
20
20
  /* harmony import */ var fs__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(fs__WEBPACK_IMPORTED_MODULE_5__);
@@ -58,13 +58,13 @@ async function command(params) {
58
58
 
59
59
  /***/ }),
60
60
 
61
- /***/ 95781:
61
+ /***/ 97189:
62
62
  /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
63
63
 
64
64
 
65
65
  // EXPORTS
66
66
  __webpack_require__.d(__webpack_exports__, {
67
- "s": () => (/* binding */ promptKeycloakVersion)
67
+ "_": () => (/* binding */ getLatestsSemVersionedTag)
68
68
  });
69
69
 
70
70
  ;// CONCATENATED MODULE: ./dist/bin/tools/octokit-addons/listTags.js
@@ -134,7 +134,7 @@ function getLatestsSemVersionedTagFactory(params) {
134
134
  const { octokit } = params;
135
135
  async function getLatestsSemVersionedTag(params) {
136
136
  var _a, e_1, _b, _c;
137
- const { owner, repo, count } = params;
137
+ const { owner, repo, count, doIgnoreReleaseCandidates } = params;
138
138
  const semVersionedTags = [];
139
139
  const { listTags } = listTagsFactory({ octokit });
140
140
  try {
@@ -150,7 +150,7 @@ function getLatestsSemVersionedTagFactory(params) {
150
150
  catch (_g) {
151
151
  continue;
152
152
  }
153
- if (version.rc !== undefined) {
153
+ if (doIgnoreReleaseCandidates && version.rc !== undefined) {
154
154
  continue;
155
155
  }
156
156
  semVersionedTags.push({ tag, version });
@@ -176,16 +176,30 @@ function getLatestsSemVersionedTagFactory(params) {
176
176
  //# sourceMappingURL=getLatestsSemVersionedTag.js.map
177
177
  // EXTERNAL MODULE: ./node_modules/@octokit/rest/dist-node/index.js
178
178
  var dist_node = __webpack_require__(55375);
179
- // EXTERNAL MODULE: ./node_modules/cli-select/dist/index.js
180
- var dist = __webpack_require__(99398);
181
- var dist_default = /*#__PURE__*/__webpack_require__.n(dist);
182
179
  // EXTERNAL MODULE: external "path"
183
180
  var external_path_ = __webpack_require__(71017);
184
181
  // EXTERNAL MODULE: external "fs"
185
182
  var external_fs_ = __webpack_require__(57147);
183
+ // EXTERNAL MODULE: ./node_modules/zod/lib/index.mjs
184
+ var lib = __webpack_require__(52300);
185
+ // EXTERNAL MODULE: ./node_modules/tsafe/assert.js
186
+ var assert = __webpack_require__(88078);
186
187
  // EXTERNAL MODULE: ./node_modules/tsafe/id.js
187
188
  var id = __webpack_require__(43047);
188
- ;// CONCATENATED MODULE: ./dist/bin/shared/promptKeycloakVersion.js
189
+ // EXTERNAL MODULE: ./node_modules/evt/tools/inDepth/same.js
190
+ var same = __webpack_require__(33805);
191
+ ;// CONCATENATED MODULE: ./dist/bin/shared/getLatestsSemVersionedTag.js
192
+ var __rest = (undefined && undefined.__rest) || function (s, e) {
193
+ var t = {};
194
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
195
+ t[p] = s[p];
196
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
197
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
198
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
199
+ t[p[i]] = s[p[i]];
200
+ }
201
+ return t;
202
+ };
189
203
 
190
204
 
191
205
 
@@ -193,50 +207,144 @@ var id = __webpack_require__(43047);
193
207
 
194
208
 
195
209
 
196
- async function promptKeycloakVersion(params) {
197
- const { startingFromMajor, excludeMajorVersions, cacheDirPath } = params;
198
- const { getLatestsSemVersionedTag } = (() => {
199
- const { octokit } = (() => {
210
+
211
+ let getLatestsSemVersionedTag_stateless = undefined;
212
+ const CACHE_VERSION = 1;
213
+ async function getLatestsSemVersionedTag(_a) {
214
+ var { cacheDirPath } = _a, params = __rest(_a, ["cacheDirPath"]);
215
+ const cacheFilePath = (0,external_path_.join)(cacheDirPath, "latest-sem-versioned-tags.json");
216
+ const cacheLookupResult = (() => {
217
+ const getResult_currentCache = (currentCacheEntries) => ({
218
+ hasCachedResult: false,
219
+ currentCache: {
220
+ version: CACHE_VERSION,
221
+ entries: currentCacheEntries
222
+ }
223
+ });
224
+ if (!external_fs_.existsSync(cacheFilePath)) {
225
+ return getResult_currentCache([]);
226
+ }
227
+ let cache_json;
228
+ try {
229
+ cache_json = external_fs_.readFileSync(cacheFilePath).toString("utf8");
230
+ }
231
+ catch (_a) {
232
+ return getResult_currentCache([]);
233
+ }
234
+ let cache_json_parsed;
235
+ try {
236
+ cache_json_parsed = JSON.parse(cache_json);
237
+ }
238
+ catch (_b) {
239
+ return getResult_currentCache([]);
240
+ }
241
+ const zSemVer = (() => {
242
+ const zTargetType = lib.z.object({
243
+ major: lib.z.number(),
244
+ minor: lib.z.number(),
245
+ patch: lib.z.number(),
246
+ rc: lib.z.number().optional(),
247
+ parsedFrom: lib.z.string()
248
+ });
249
+ (0,assert.assert)();
250
+ return (0,id.id)(zTargetType);
251
+ })();
252
+ const zCache = (() => {
253
+ const zTargetType = lib.z.object({
254
+ version: lib.z.literal(CACHE_VERSION),
255
+ entries: lib.z.array(lib.z.object({
256
+ time: lib.z.number(),
257
+ params: lib.z.object({
258
+ owner: lib.z.string(),
259
+ repo: lib.z.string(),
260
+ count: lib.z.number(),
261
+ doIgnoreReleaseCandidates: lib.z.boolean()
262
+ }),
263
+ result: lib.z.array(lib.z.object({
264
+ tag: lib.z.string(),
265
+ version: zSemVer
266
+ }))
267
+ }))
268
+ });
269
+ (0,assert.assert)();
270
+ return (0,id.id)(zTargetType);
271
+ })();
272
+ let cache;
273
+ try {
274
+ cache = zCache.parse(cache_json_parsed);
275
+ }
276
+ catch (_c) {
277
+ return getResult_currentCache([]);
278
+ }
279
+ const cacheEntry = cache.entries.find(e => (0,same.same)(e.params, params));
280
+ if (cacheEntry === undefined) {
281
+ return getResult_currentCache(cache.entries);
282
+ }
283
+ if (Date.now() - cacheEntry.time > 3600000) {
284
+ return getResult_currentCache(cache.entries.filter(e => e !== cacheEntry));
285
+ }
286
+ return {
287
+ hasCachedResult: true,
288
+ cachedResult: cacheEntry.result
289
+ };
290
+ })();
291
+ if (cacheLookupResult.hasCachedResult) {
292
+ return cacheLookupResult.cachedResult;
293
+ }
294
+ const { currentCache } = cacheLookupResult;
295
+ getLatestsSemVersionedTag_stateless !== null && getLatestsSemVersionedTag_stateless !== void 0 ? getLatestsSemVersionedTag_stateless : (getLatestsSemVersionedTag_stateless = (() => {
296
+ const octokit = (() => {
200
297
  const githubToken = process.env.GITHUB_TOKEN;
201
298
  const octokit = new dist_node.Octokit(githubToken === undefined ? undefined : { auth: githubToken });
202
- return { octokit };
299
+ return octokit;
203
300
  })();
204
301
  const { getLatestsSemVersionedTag } = getLatestsSemVersionedTagFactory({
205
302
  octokit
206
303
  });
207
- return { getLatestsSemVersionedTag };
208
- })();
209
- const semVersionedTagByMajor = new Map();
210
- const semVersionedTags = await (async () => {
211
- const cacheFilePath = (0,external_path_.join)(cacheDirPath, "keycloak-versions.json");
212
- use_cache: {
213
- if (!external_fs_.existsSync(cacheFilePath)) {
214
- break use_cache;
215
- }
216
- const cache = JSON.parse(external_fs_.readFileSync(cacheFilePath).toString("utf8"));
217
- if (Date.now() - cache.time > 3600000) {
218
- external_fs_.unlinkSync(cacheFilePath);
219
- break use_cache;
220
- }
221
- return cache.semVersionedTags;
222
- }
223
- const semVersionedTags = await getLatestsSemVersionedTag({
224
- count: 50,
225
- owner: "keycloak",
226
- repo: "keycloak"
227
- });
228
- {
229
- const dirPath = (0,external_path_.dirname)(cacheFilePath);
230
- if (!external_fs_.existsSync(dirPath)) {
231
- external_fs_.mkdirSync(dirPath, { recursive: true });
232
- }
304
+ return getLatestsSemVersionedTag;
305
+ })());
306
+ const result = await getLatestsSemVersionedTag_stateless(params);
307
+ currentCache.entries.push({
308
+ time: Date.now(),
309
+ params,
310
+ result
311
+ });
312
+ {
313
+ const dirPath = (0,external_path_.dirname)(cacheFilePath);
314
+ if (!external_fs_.existsSync(dirPath)) {
315
+ external_fs_.mkdirSync(dirPath, { recursive: true });
233
316
  }
234
- external_fs_.writeFileSync(cacheFilePath, JSON.stringify((0,id.id)({
235
- time: Date.now(),
236
- semVersionedTags
237
- }), null, 2));
238
- return semVersionedTags;
239
- })();
317
+ }
318
+ external_fs_.writeFileSync(cacheFilePath, JSON.stringify(currentCache, null, 2));
319
+ return result;
320
+ }
321
+ //# sourceMappingURL=getLatestsSemVersionedTag.js.map
322
+
323
+ /***/ }),
324
+
325
+ /***/ 82635:
326
+ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
327
+
328
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
329
+ /* harmony export */ "s": () => (/* binding */ promptKeycloakVersion)
330
+ /* harmony export */ });
331
+ /* harmony import */ var _getLatestsSemVersionedTag__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(97189);
332
+ /* harmony import */ var cli_select__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(99398);
333
+ /* harmony import */ var cli_select__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(cli_select__WEBPACK_IMPORTED_MODULE_1__);
334
+ /* harmony import */ var _tools_SemVer__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(12171);
335
+
336
+
337
+
338
+ async function promptKeycloakVersion(params) {
339
+ const { startingFromMajor, excludeMajorVersions, cacheDirPath } = params;
340
+ const semVersionedTagByMajor = new Map();
341
+ const semVersionedTags = await (0,_getLatestsSemVersionedTag__WEBPACK_IMPORTED_MODULE_0__/* .getLatestsSemVersionedTag */ ._)({
342
+ cacheDirPath,
343
+ count: 50,
344
+ owner: "keycloak",
345
+ repo: "keycloak",
346
+ doIgnoreReleaseCandidates: true
347
+ });
240
348
  semVersionedTags.forEach(semVersionedTag => {
241
349
  if (startingFromMajor !== undefined &&
242
350
  semVersionedTag.version.major < startingFromMajor) {
@@ -247,13 +355,13 @@ async function promptKeycloakVersion(params) {
247
355
  }
248
356
  const currentSemVersionedTag = semVersionedTagByMajor.get(semVersionedTag.version.major);
249
357
  if (currentSemVersionedTag !== undefined &&
250
- SemVer/* SemVer.compare */.h.compare(semVersionedTag.version, currentSemVersionedTag.version) === -1) {
358
+ _tools_SemVer__WEBPACK_IMPORTED_MODULE_2__/* .SemVer.compare */ .h.compare(semVersionedTag.version, currentSemVersionedTag.version) === -1) {
251
359
  return;
252
360
  }
253
361
  semVersionedTagByMajor.set(semVersionedTag.version.major, semVersionedTag);
254
362
  });
255
363
  const lastMajorVersions = Array.from(semVersionedTagByMajor.values()).map(({ tag }) => tag);
256
- const { value } = await dist_default()({
364
+ const { value } = await cli_select__WEBPACK_IMPORTED_MODULE_1___default()({
257
365
  values: lastMajorVersions
258
366
  }).catch(() => {
259
367
  process.exit(-1);
@@ -263,6 +371,575 @@ async function promptKeycloakVersion(params) {
263
371
  }
264
372
  //# sourceMappingURL=promptKeycloakVersion.js.map
265
373
 
374
+ /***/ }),
375
+
376
+ /***/ 18512:
377
+ /***/ ((module) => {
378
+
379
+
380
+ const x = module.exports;
381
+ const ESC = '\u001B[';
382
+ const OSC = '\u001B]';
383
+ const BEL = '\u0007';
384
+ const SEP = ';';
385
+ const isTerminalApp = process.env.TERM_PROGRAM === 'Apple_Terminal';
386
+
387
+ x.cursorTo = (x, y) => {
388
+ if (typeof x !== 'number') {
389
+ throw new TypeError('The `x` argument is required');
390
+ }
391
+
392
+ if (typeof y !== 'number') {
393
+ return ESC + (x + 1) + 'G';
394
+ }
395
+
396
+ return ESC + (y + 1) + ';' + (x + 1) + 'H';
397
+ };
398
+
399
+ x.cursorMove = (x, y) => {
400
+ if (typeof x !== 'number') {
401
+ throw new TypeError('The `x` argument is required');
402
+ }
403
+
404
+ let ret = '';
405
+
406
+ if (x < 0) {
407
+ ret += ESC + (-x) + 'D';
408
+ } else if (x > 0) {
409
+ ret += ESC + x + 'C';
410
+ }
411
+
412
+ if (y < 0) {
413
+ ret += ESC + (-y) + 'A';
414
+ } else if (y > 0) {
415
+ ret += ESC + y + 'B';
416
+ }
417
+
418
+ return ret;
419
+ };
420
+
421
+ x.cursorUp = count => ESC + (typeof count === 'number' ? count : 1) + 'A';
422
+ x.cursorDown = count => ESC + (typeof count === 'number' ? count : 1) + 'B';
423
+ x.cursorForward = count => ESC + (typeof count === 'number' ? count : 1) + 'C';
424
+ x.cursorBackward = count => ESC + (typeof count === 'number' ? count : 1) + 'D';
425
+
426
+ x.cursorLeft = ESC + 'G';
427
+ x.cursorSavePosition = ESC + (isTerminalApp ? '7' : 's');
428
+ x.cursorRestorePosition = ESC + (isTerminalApp ? '8' : 'u');
429
+ x.cursorGetPosition = ESC + '6n';
430
+ x.cursorNextLine = ESC + 'E';
431
+ x.cursorPrevLine = ESC + 'F';
432
+ x.cursorHide = ESC + '?25l';
433
+ x.cursorShow = ESC + '?25h';
434
+
435
+ x.eraseLines = count => {
436
+ let clear = '';
437
+
438
+ for (let i = 0; i < count; i++) {
439
+ clear += x.eraseLine + (i < count - 1 ? x.cursorUp() : '');
440
+ }
441
+
442
+ if (count) {
443
+ clear += x.cursorLeft;
444
+ }
445
+
446
+ return clear;
447
+ };
448
+
449
+ x.eraseEndLine = ESC + 'K';
450
+ x.eraseStartLine = ESC + '1K';
451
+ x.eraseLine = ESC + '2K';
452
+ x.eraseDown = ESC + 'J';
453
+ x.eraseUp = ESC + '1J';
454
+ x.eraseScreen = ESC + '2J';
455
+ x.scrollUp = ESC + 'S';
456
+ x.scrollDown = ESC + 'T';
457
+
458
+ x.clearScreen = '\u001Bc';
459
+
460
+ x.clearTerminal = process.platform === 'win32' ?
461
+ `${x.eraseScreen}${ESC}0f` :
462
+ // 1. Erases the screen (Only done in case `2` is not supported)
463
+ // 2. Erases the whole screen including scrollback buffer
464
+ // 3. Moves cursor to the top-left position
465
+ // More info: https://www.real-world-systems.com/docs/ANSIcode.html
466
+ `${x.eraseScreen}${ESC}3J${ESC}H`;
467
+
468
+ x.beep = BEL;
469
+
470
+ x.link = (text, url) => {
471
+ return [
472
+ OSC,
473
+ '8',
474
+ SEP,
475
+ SEP,
476
+ url,
477
+ BEL,
478
+ text,
479
+ OSC,
480
+ '8',
481
+ SEP,
482
+ SEP,
483
+ BEL
484
+ ].join('');
485
+ };
486
+
487
+ x.image = (buf, opts) => {
488
+ opts = opts || {};
489
+
490
+ let ret = OSC + '1337;File=inline=1';
491
+
492
+ if (opts.width) {
493
+ ret += `;width=${opts.width}`;
494
+ }
495
+
496
+ if (opts.height) {
497
+ ret += `;height=${opts.height}`;
498
+ }
499
+
500
+ if (opts.preserveAspectRatio === false) {
501
+ ret += ';preserveAspectRatio=0';
502
+ }
503
+
504
+ return ret + ':' + buf.toString('base64') + BEL;
505
+ };
506
+
507
+ x.iTerm = {};
508
+
509
+ x.iTerm.setCwd = cwd => OSC + '50;CurrentDir=' + (cwd || process.cwd()) + BEL;
510
+
511
+
512
+ /***/ }),
513
+
514
+ /***/ 39340:
515
+ /***/ ((__unused_webpack_module, exports) => {
516
+
517
+
518
+
519
+ Object.defineProperty(exports, "__esModule", ({
520
+ value: true
521
+ }));
522
+ exports.withPromise = exports.withCallback = void 0;
523
+
524
+ /**
525
+ * Open the input with a normal callback function
526
+ *
527
+ * @param {Input} input - input object
528
+ * @param {function} valueMapper - function which maps the resulting id and value back to the expected format
529
+ * @param {function} callback - callback function
530
+ */
531
+ const withCallback = (input, valueMapper, callback) => {
532
+ input.open();
533
+ input.onSelect((id, value) => callback(valueMapper(id, value)));
534
+ };
535
+ /**
536
+ * Open the input with a promise
537
+ *
538
+ * @param {Input} input - input object
539
+ * @param {function} valueMapper - function which maps the resulting id and value back to the expected format
540
+ */
541
+
542
+
543
+ exports.withCallback = withCallback;
544
+
545
+ const withPromise = (input, valueMapper) => {
546
+ return new Promise((resolve, reject) => {
547
+ input.open();
548
+ input.onSelect((id, value) => {
549
+ if (id === null) {
550
+ reject();
551
+ } else {
552
+ resolve(valueMapper(id, value));
553
+ }
554
+ });
555
+ });
556
+ };
557
+
558
+ exports.withPromise = withPromise;
559
+
560
+ /***/ }),
561
+
562
+ /***/ 99398:
563
+ /***/ ((module, exports, __webpack_require__) => {
564
+
565
+
566
+
567
+ Object.defineProperty(exports, "__esModule", ({
568
+ value: true
569
+ }));
570
+ exports["default"] = void 0;
571
+
572
+ var _input = _interopRequireDefault(__webpack_require__(25730));
573
+
574
+ var _renderer = _interopRequireDefault(__webpack_require__(16059));
575
+
576
+ var _callbackMappers = __webpack_require__(39340);
577
+
578
+ var _valueMappers = __webpack_require__(26730);
579
+
580
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
581
+
582
+ 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; }
583
+
584
+ 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; }
585
+
586
+ /**
587
+ * Default options
588
+ */
589
+ const defaultOptions = {
590
+ outputStream: process.stdout,
591
+ inputStream: process.stdin,
592
+ values: [],
593
+ defaultValue: 0,
594
+ selected: '(x)',
595
+ unselected: '( )',
596
+ indentation: 0,
597
+ cleanup: true,
598
+ valueRenderer: value => value
599
+ };
600
+ /**
601
+ * Create an instance of cli-select with the given options
602
+ *
603
+ * @param {object} options - options for cli-select
604
+ * @param {function} callback - if specified, a callback will be used, otherwise a promise gets returned (optional)
605
+ */
606
+
607
+ const creator = (options, callback) => {
608
+ // merge options with default options
609
+ options = _objectSpread({}, defaultOptions, options); // create renderer and input instances
610
+
611
+ const renderer = new _renderer.default(options, options.outputStream);
612
+ const input = new _input.default(options.inputStream);
613
+ input.setDefaultValue(options.defaultValue);
614
+ input.attachRenderer(renderer); // handle array and object values
615
+
616
+ let valueMapper;
617
+
618
+ if (Array.isArray(options.values)) {
619
+ valueMapper = (0, _valueMappers.withArrayValues)(options);
620
+ } else {
621
+ valueMapper = (0, _valueMappers.withObjectValues)(options);
622
+ } // map values
623
+
624
+
625
+ options.values = valueMapper.input;
626
+ input.setValues(options.values); // handle different callback methods
627
+
628
+ if (typeof callback === 'function') {
629
+ return (0, _callbackMappers.withCallback)(input, valueMapper.output, callback);
630
+ } else {
631
+ return (0, _callbackMappers.withPromise)(input, valueMapper.output);
632
+ }
633
+ };
634
+
635
+ exports = module.exports = creator;
636
+ Object.defineProperty(exports, "__esModule", ({
637
+ value: true
638
+ }));
639
+ var _default = creator;
640
+ exports["default"] = _default;
641
+
642
+ /***/ }),
643
+
644
+ /***/ 25730:
645
+ /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
646
+
647
+
648
+
649
+ Object.defineProperty(exports, "__esModule", ({
650
+ value: true
651
+ }));
652
+ exports["default"] = void 0;
653
+
654
+ var _readline = _interopRequireDefault(__webpack_require__(14521));
655
+
656
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
657
+
658
+ /**
659
+ * Handle cli input
660
+ */
661
+ class Input {
662
+ /**
663
+ * Input constructor
664
+ *
665
+ * @param {any} stream - stream to catch (optional)
666
+ */
667
+ constructor(stream = process.stdin) {
668
+ // set default values
669
+ this.stream = stream;
670
+ this.values = [];
671
+ this.selectedValue = 0;
672
+
673
+ this.onSelectListener = () => {};
674
+
675
+ this.onKeyPress = this.onKeyPress.bind(this);
676
+ }
677
+ /**
678
+ * Set the available values
679
+ *
680
+ * @param {array} values - all available values
681
+ */
682
+
683
+
684
+ setValues(values) {
685
+ this.values = values;
686
+
687
+ if (this.renderer) {
688
+ this.renderer.setValues(values);
689
+ }
690
+ }
691
+ /**
692
+ * Set the default value
693
+ *
694
+ * @param {number} defaultValue - default value id
695
+ */
696
+
697
+
698
+ setDefaultValue(defaultValue) {
699
+ this.selectedValue = defaultValue;
700
+ }
701
+ /**
702
+ * Attach a renderer to the input catcher
703
+ *
704
+ * @param {Renderer} renderer - renderer to use for rendering responses
705
+ */
706
+
707
+
708
+ attachRenderer(renderer) {
709
+ this.renderer = renderer;
710
+ this.renderer.setValues(this.values);
711
+ }
712
+ /**
713
+ * Register an on select listener
714
+ *
715
+ * @param {function} listener - listener function which receives two parameters: valueId and value
716
+ */
717
+
718
+
719
+ onSelect(listener) {
720
+ this.onSelectListener = listener;
721
+ }
722
+ /**
723
+ * Open the stream and listen for input
724
+ */
725
+
726
+
727
+ open() {
728
+ // register keypress event
729
+ _readline.default.emitKeypressEvents(this.stream); // handle keypress
730
+
731
+
732
+ this.stream.on('keypress', this.onKeyPress); // initially render the response
733
+
734
+ if (this.renderer) {
735
+ this.renderer.render(this.selectedValue);
736
+ } // hide pressed keys and start listening on input
737
+
738
+
739
+ this.stream.setRawMode(true);
740
+ this.stream.resume();
741
+ }
742
+ /**
743
+ * Close the stream
744
+ *
745
+ * @param {boolean} cancelled - true if no value was selected (optional)
746
+ */
747
+
748
+
749
+ close(cancelled = false) {
750
+ // reset stream properties
751
+ this.stream.setRawMode(false);
752
+ this.stream.pause(); // cleanup the output
753
+
754
+ if (this.renderer) {
755
+ this.renderer.cleanup();
756
+ } // call the on select listener
757
+
758
+
759
+ if (cancelled) {
760
+ this.onSelectListener(null);
761
+ } else {
762
+ this.onSelectListener(this.selectedValue, this.values[this.selectedValue]);
763
+ }
764
+
765
+ this.stream.removeListener('keypress', this.onKeyPress);
766
+ }
767
+ /**
768
+ * Render the response
769
+ */
770
+
771
+
772
+ render() {
773
+ if (!this.renderer) {
774
+ return;
775
+ }
776
+
777
+ this.renderer.render(this.selectedValue);
778
+ }
779
+ /**
780
+ * Handle key press event
781
+ *
782
+ * @param {string} string - input string
783
+ * @param {object} key - object containing information about the pressed key
784
+ */
785
+
786
+
787
+ onKeyPress(string, key) {
788
+ if (key) {
789
+ if (key.name === 'up' && this.selectedValue > 0) {
790
+ this.selectedValue--;
791
+ this.render();
792
+ } else if (key.name === 'down' && this.selectedValue + 1 < this.values.length) {
793
+ this.selectedValue++;
794
+ this.render();
795
+ } else if (key.name === 'return') {
796
+ this.close();
797
+ } else if (key.name === 'escape' || key.name === 'c' && key.ctrl) {
798
+ this.close(true);
799
+ }
800
+ }
801
+ }
802
+
803
+ }
804
+
805
+ exports["default"] = Input;
806
+
807
+ /***/ }),
808
+
809
+ /***/ 16059:
810
+ /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
811
+
812
+
813
+
814
+ Object.defineProperty(exports, "__esModule", ({
815
+ value: true
816
+ }));
817
+ exports["default"] = void 0;
818
+
819
+ var _readline = _interopRequireDefault(__webpack_require__(14521));
820
+
821
+ var _ansiEscapes = __webpack_require__(18512);
822
+
823
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
824
+
825
+ /**
826
+ * Response renderer
827
+ */
828
+ class Renderer {
829
+ /**
830
+ * Renderer constructor
831
+ *
832
+ * @param {object} options - renderer options
833
+ * @param {any} stream - stream to write to (optional)
834
+ */
835
+ constructor(options, stream = process.stdout) {
836
+ this.options = options;
837
+ this.stream = stream;
838
+ this.values = [];
839
+ this.initialRender = true;
840
+ }
841
+ /**
842
+ * Set the available values
843
+ *
844
+ * @param {array} values - all available values
845
+ */
846
+
847
+
848
+ setValues(values) {
849
+ this.values = values;
850
+ }
851
+ /**
852
+ * Render the values
853
+ *
854
+ * @param {number} selectedValue - selected value (optional)
855
+ */
856
+
857
+
858
+ render(selectedValue = 0) {
859
+ if (this.initialRender) {
860
+ // hide the cursor initially
861
+ this.initialRender = false;
862
+ this.stream.write(_ansiEscapes.cursorHide);
863
+ } else {
864
+ // remove previous lines and values
865
+ this.stream.write((0, _ansiEscapes.eraseLines)(this.values.length));
866
+ } // output the current values
867
+
868
+
869
+ this.values.forEach((value, index) => {
870
+ const symbol = selectedValue === index ? this.options.selected : this.options.unselected;
871
+ const indentation = ' '.repeat(this.options.indentation);
872
+ const renderedValue = this.options.valueRenderer(value, selectedValue === index);
873
+ const end = index !== this.values.length - 1 ? '\n' : '';
874
+ this.stream.write(indentation + symbol + ' ' + renderedValue + end);
875
+ });
876
+ }
877
+ /**
878
+ * Cleanup the console at the end
879
+ */
880
+
881
+
882
+ cleanup() {
883
+ this.stream.write((0, _ansiEscapes.eraseLines)(this.values.length));
884
+ this.stream.write(_ansiEscapes.cursorShow);
885
+ }
886
+
887
+ }
888
+
889
+ exports["default"] = Renderer;
890
+
891
+ /***/ }),
892
+
893
+ /***/ 26730:
894
+ /***/ ((__unused_webpack_module, exports) => {
895
+
896
+
897
+
898
+ Object.defineProperty(exports, "__esModule", ({
899
+ value: true
900
+ }));
901
+ exports.withObjectValues = exports.withArrayValues = void 0;
902
+
903
+ /**
904
+ * Map incoming and outgoing values if the initial values are an array
905
+ *
906
+ * @param {object} options - cli-select options
907
+ */
908
+ const withArrayValues = options => {
909
+ return {
910
+ input: options.values,
911
+ output: (id, value) => {
912
+ return {
913
+ id,
914
+ value
915
+ };
916
+ }
917
+ };
918
+ };
919
+ /**
920
+ * Map incoming and outgoing values if the initial values are an object
921
+ *
922
+ * @param {object} options - cli-select options
923
+ */
924
+
925
+
926
+ exports.withArrayValues = withArrayValues;
927
+
928
+ const withObjectValues = options => {
929
+ const originalValues = options.values;
930
+ return {
931
+ input: Object.values(originalValues),
932
+ output: (id, value) => {
933
+ return {
934
+ id: Object.keys(originalValues)[id],
935
+ value
936
+ };
937
+ }
938
+ };
939
+ };
940
+
941
+ exports.withObjectValues = withObjectValues;
942
+
266
943
  /***/ })
267
944
 
268
945
  };