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