@opencrvs/toolkit 2.0.0-rc.bd45274 → 2.0.0-rc.bd55713

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 (79) hide show
  1. package/README.md +14 -0
  2. package/build.sh +1 -0
  3. package/dist/application-config/index.js +7 -1
  4. package/dist/cli.js +3191 -42
  5. package/dist/commons/api/router.d.ts +11 -2
  6. package/dist/commons/events/ActionConfig.d.ts +28 -2
  7. package/dist/commons/events/FieldConfig.d.ts +1 -0
  8. package/dist/commons/events/FieldType.d.ts +1 -0
  9. package/dist/commons/events/FieldTypeMapping.d.ts +1 -1
  10. package/dist/environment/custom-types.d.ts +33 -0
  11. package/dist/environment/custom-types.d.ts.map +1 -0
  12. package/dist/environment/custom-types.js +2 -0
  13. package/dist/environment/derived-variables.d.ts +134 -0
  14. package/dist/environment/derived-variables.d.ts.map +1 -0
  15. package/dist/environment/derived-variables.js +159 -0
  16. package/dist/environment/editor-questions.d.ts +5 -0
  17. package/dist/environment/editor-questions.d.ts.map +1 -0
  18. package/dist/environment/editor-questions.js +56 -0
  19. package/dist/environment/git.d.ts +5 -0
  20. package/dist/environment/git.d.ts.map +1 -0
  21. package/dist/environment/git.js +28 -0
  22. package/dist/environment/github.d.ts +26 -0
  23. package/dist/environment/github.d.ts.map +1 -0
  24. package/dist/environment/github.js +234 -0
  25. package/dist/environment/index.d.ts +6 -0
  26. package/dist/environment/index.d.ts.map +1 -0
  27. package/dist/environment/index.js +61 -0
  28. package/dist/environment/logger.d.ts +15 -0
  29. package/dist/environment/logger.d.ts.map +1 -0
  30. package/dist/environment/logger.js +15 -0
  31. package/dist/environment/manage-users.d.ts +11 -0
  32. package/dist/environment/manage-users.d.ts.map +1 -0
  33. package/dist/environment/manage-users.js +484 -0
  34. package/dist/environment/questions-helper.d.ts +15 -0
  35. package/dist/environment/questions-helper.d.ts.map +1 -0
  36. package/dist/environment/questions-helper.js +60 -0
  37. package/dist/environment/questions.d.ts +222 -0
  38. package/dist/environment/questions.d.ts.map +1 -0
  39. package/dist/environment/questions.js +455 -0
  40. package/dist/environment/setup-environment.d.ts +2 -0
  41. package/dist/environment/setup-environment.d.ts.map +1 -0
  42. package/dist/environment/setup-environment.js +763 -0
  43. package/dist/environment/ssh-keygen.d.ts +5 -0
  44. package/dist/environment/ssh-keygen.d.ts.map +1 -0
  45. package/dist/environment/ssh-keygen.js +8 -0
  46. package/dist/environment/swarm-to-k8s.d.ts +2 -0
  47. package/dist/environment/swarm-to-k8s.d.ts.map +1 -0
  48. package/dist/environment/swarm-to-k8s.js +162 -0
  49. package/dist/environment/templates/charts-values/dependencies/values.override.yaml +4 -0
  50. package/dist/environment/templates/charts-values/dependencies/values.yaml +82 -0
  51. package/dist/environment/templates/charts-values/opencrvs-services/values.override.yaml +4 -0
  52. package/dist/environment/templates/charts-values/opencrvs-services/values.yaml +79 -0
  53. package/dist/environment/templates/charts-values/traefik/values.override.yaml +4 -0
  54. package/dist/environment/templates/charts-values/traefik/values.yaml +116 -0
  55. package/dist/environment/templates/inventory/inventory.template.yml +100 -0
  56. package/dist/environment/templates/inventory/production.example.yml +77 -0
  57. package/dist/environment/templates/inventory/qa.example.yml +48 -0
  58. package/dist/environment/templates.d.ts +27 -0
  59. package/dist/environment/templates.d.ts.map +1 -0
  60. package/dist/environment/templates.js +149 -0
  61. package/dist/environment/update-workflows.d.ts +2 -0
  62. package/dist/environment/update-workflows.d.ts.map +1 -0
  63. package/dist/environment/update-workflows.js +151 -0
  64. package/dist/environment/users.d.ts +2 -0
  65. package/dist/environment/users.d.ts.map +1 -0
  66. package/dist/environment/users.js +92 -0
  67. package/dist/environment/utils.d.ts +18 -0
  68. package/dist/environment/utils.d.ts.map +1 -0
  69. package/dist/environment/utils.js +90 -0
  70. package/dist/events/index.js +153 -62
  71. package/dist/migrations/v2.0/checkout-upstream-files.d.ts +1 -1
  72. package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +1 -1
  73. package/dist/migrations/v2.0/checkout-upstream-files.js +1 -1
  74. package/dist/migrations/v2.0/index.js +1 -1
  75. package/dist/notification/index.js +96 -3
  76. package/opencrvs-toolkit-2.0.0-rc.bd55713.tgz +0 -0
  77. package/package.json +15 -1
  78. package/tsconfig.tsbuildinfo +1 -1
  79. package/opencrvs-toolkit-2.0.0-rc.bd45274.tgz +0 -0
@@ -0,0 +1,484 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ Object.defineProperty(exports, "__esModule", { value: true });
35
+ exports.manageUsers = manageUsers;
36
+ const os = __importStar(require("os"));
37
+ const fs = __importStar(require("fs"));
38
+ const path = __importStar(require("path"));
39
+ function inquirerPrompt(name, options) {
40
+ return __awaiter(this, void 0, void 0, function* () {
41
+ const inquirer = yield import('@inquirer/prompts');
42
+ return inquirer[name](options);
43
+ });
44
+ }
45
+ const input = (options) => inquirerPrompt('input', options);
46
+ const select = (options) => inquirerPrompt('select', options);
47
+ const confirm = (options) => inquirerPrompt('confirm', options);
48
+ const editor = (options) => inquirerPrompt('editor', options);
49
+ const checkbox = (options) => inquirerPrompt('checkbox', options);
50
+ const logger_1 = require("./logger");
51
+ const utils_1 = require("./utils");
52
+ const templates_1 = require("./templates");
53
+ /**
54
+ * Updates users in Ansible inventory file
55
+ *
56
+ * @param {string} filePath - Path to the inventory file
57
+ * @param {User[]} users - Users array
58
+ */
59
+ function updateInventoryFile(filePath, users) {
60
+ var _a, _b;
61
+ const data = (0, utils_1.readYamlFile)(filePath);
62
+ if (!((_b = (_a = data === null || data === void 0 ? void 0 : data.all) === null || _a === void 0 ? void 0 : _a.vars) === null || _b === void 0 ? void 0 : _b.users)) {
63
+ throw Error(`'users' section not found within inventory file: ${filePath}`);
64
+ }
65
+ data.all.vars.users = users;
66
+ (0, utils_1.writeYamlFile)(filePath, data);
67
+ }
68
+ /**
69
+ * Parses the Ansible inventory file and extracts existing users
70
+ *
71
+ * @param {string} filePath - Path to the inventory file
72
+ * @returns {User[]} Array of existing users
73
+ */
74
+ function parseInventoryFile(filePath) {
75
+ try {
76
+ const data = (0, utils_1.readYamlFile)(filePath);
77
+ return (0, templates_1.getUsers)(data);
78
+ }
79
+ catch (_a) {
80
+ return [];
81
+ }
82
+ }
83
+ /**
84
+ * Gets the current system username
85
+ *
86
+ * @returns {string} Current OS username
87
+ */
88
+ function getCurrentUsername() {
89
+ return os.userInfo().username;
90
+ }
91
+ /**
92
+ * Reads SSH public keys from the current user's .ssh directory
93
+ *
94
+ * @returns {string[]} Array of SSH public keys found
95
+ */
96
+ function getCurrentUserSSHKeys() {
97
+ const homeDir = os.homedir();
98
+ const sshDir = path.join(homeDir, '.ssh');
99
+ const keys = [];
100
+ // Common public key filenames
101
+ const keyFiles = [
102
+ 'id_rsa.pub',
103
+ 'id_ecdsa.pub',
104
+ 'id_ed25519.pub',
105
+ 'id_dsa.pub'
106
+ ];
107
+ for (const keyFile of keyFiles) {
108
+ const keyPath = path.join(sshDir, keyFile);
109
+ try {
110
+ if (fs.existsSync(keyPath)) {
111
+ const keyContent = fs.readFileSync(keyPath, 'utf8').trim();
112
+ if (keyContent) {
113
+ keys.push(keyContent);
114
+ }
115
+ }
116
+ }
117
+ catch (error) {
118
+ // Silently skip if can't read the file
119
+ continue;
120
+ }
121
+ }
122
+ return keys;
123
+ }
124
+ function selectRole() {
125
+ return __awaiter(this, void 0, void 0, function* () {
126
+ return yield select({
127
+ message: 'Select user role:',
128
+ choices: [
129
+ { name: 'Admin (full access to OS and Kubernetes)', value: 'admin' },
130
+ { name: 'Operator (read-only OS, full Kubernetes)', value: 'operator' }
131
+ ]
132
+ });
133
+ });
134
+ }
135
+ function selectState() {
136
+ return __awaiter(this, void 0, void 0, function* () {
137
+ return yield select({
138
+ message: 'Select user state:',
139
+ choices: [
140
+ { name: 'Present (user is allowed to login)', value: 'present' },
141
+ { name: 'Absent (user account is disabled)', value: 'absent' }
142
+ ]
143
+ });
144
+ });
145
+ }
146
+ /**
147
+ * Asks if user wants to add current system user as the first user
148
+ *
149
+ * @returns {Promise<User | null>} User object if accepted, null if declined
150
+ */
151
+ function askToAddCurrentUser(existingUsers) {
152
+ return __awaiter(this, void 0, void 0, function* () {
153
+ const currentUsername = getCurrentUsername();
154
+ const currentKeys = getCurrentUserSSHKeys();
155
+ // Check if user already exists
156
+ if (existingUsers.find(u => u.name === currentUsername)) {
157
+ (0, logger_1.info)(`ℹ️ User "${currentUsername}" already exists in inventory.`);
158
+ return null;
159
+ }
160
+ if (currentKeys.length === 0) {
161
+ // No SSH keys found for current user
162
+ return null;
163
+ }
164
+ const addCurrentUser = yield confirm({
165
+ message: `Add current user "${currentUsername}" with ${currentKeys.length} SSH key(s)?`,
166
+ default: true
167
+ });
168
+ if (!addCurrentUser) {
169
+ return null;
170
+ }
171
+ // Ask for role
172
+ const role = yield selectRole();
173
+ return {
174
+ name: currentUsername,
175
+ ssh_keys: currentKeys,
176
+ state: 'present',
177
+ role: role
178
+ };
179
+ });
180
+ }
181
+ /**
182
+ * Add a new user
183
+ */
184
+ function addNewUser(existingUsers) {
185
+ return __awaiter(this, void 0, void 0, function* () {
186
+ const name = yield input({
187
+ message: 'Enter username:',
188
+ validate: (value) => {
189
+ if (!value.trim()) {
190
+ return 'Username required';
191
+ }
192
+ if (existingUsers.find(u => u.name === value.trim())) {
193
+ return `User "${value}" already exists`;
194
+ }
195
+ if (!/^[a-z_][a-z0-9_-]*[$]?$/.test(value.trim())) {
196
+ return 'Invalid username format (use lowercase, numbers, underscore, hyphen)';
197
+ }
198
+ return true;
199
+ }
200
+ });
201
+ const keysInput = yield editor({
202
+ message: 'Paste SSH public key(s) (one per line):',
203
+ default: ''
204
+ });
205
+ const ssh_keys = keysInput
206
+ .split('\n')
207
+ .map((key) => key.trim())
208
+ .filter((key) => key && !key.startsWith('#'));
209
+ if (ssh_keys.length === 0) {
210
+ (0, logger_1.warn)('⚠️ Warning: No SSH keys provided. User will not be able to login remotely.');
211
+ }
212
+ const role = yield selectRole();
213
+ // New users always active
214
+ const state = "present";
215
+ return {
216
+ name: name.trim(),
217
+ ssh_keys,
218
+ state,
219
+ role
220
+ };
221
+ });
222
+ }
223
+ /**
224
+ * Display user summary
225
+ */
226
+ function displayUserSummary(users) {
227
+ if (users.length === 0) {
228
+ console.log('\n📋 No users configured.\n');
229
+ return;
230
+ }
231
+ console.log('\n' + '='.repeat(70));
232
+ console.log(`📋 User Configuration Summary - Total users: ${users.length}`);
233
+ console.log('='.repeat(70));
234
+ users.forEach((user, index) => {
235
+ const stateIcon = user.state === 'present' ? '✅' : '❌';
236
+ const roleIcon = user.role === 'admin' ? '👑' : '👤';
237
+ console.log(`${index + 1}. ${stateIcon} ${roleIcon} ${user.name.padEnd(20)} ` +
238
+ `Role: ${user.role.padEnd(10)} State: ${user.state.padEnd(10)} ` +
239
+ `SSH Keys: ${user.ssh_keys.length}`);
240
+ });
241
+ console.log('='.repeat(70) + '\n');
242
+ }
243
+ /**
244
+ * Edit an existing user with screen clearing for better UX
245
+ */
246
+ function editUser(user) {
247
+ return __awaiter(this, void 0, void 0, function* () {
248
+ const updatedUser = Object.assign({}, user);
249
+ let continueEditing = true;
250
+ // Function to clear screen and move cursor to top
251
+ const clearScreen = () => {
252
+ process.stdout.write('\x1Bc'); // Clear entire screen
253
+ // Alternative: process.stdout.write('\x1B[2J\x1B[0f'); // Clear screen + move cursor to top
254
+ };
255
+ // Function to display current user state
256
+ const displayUserState = () => {
257
+ clearScreen();
258
+ console.log('─'.repeat(70));
259
+ console.log(`📝 Editing user: ${updatedUser.name}`);
260
+ console.log('─'.repeat(70));
261
+ console.log(`Current Role: ${updatedUser.role === 'admin' ? '👑 admin' : '👤 operator'}`);
262
+ console.log(`Current State: ${updatedUser.state === 'present' ? '✅ present' : '❌ absent'}`);
263
+ console.log(`Current SSH Keys: ${updatedUser.ssh_keys.length} key(s)`);
264
+ if (updatedUser.ssh_keys.length > 0) {
265
+ updatedUser.ssh_keys.forEach((key, idx) => {
266
+ const keyPreview = key.length > 50 ? key.substring(0, 47) + '...' : key;
267
+ console.log(` ${idx + 1}. ${keyPreview}`);
268
+ });
269
+ }
270
+ console.log('─'.repeat(70));
271
+ console.log(''); // Empty line for spacing
272
+ };
273
+ while (continueEditing) {
274
+ displayUserState();
275
+ const action = yield select({
276
+ message: 'What would you like to modify?',
277
+ choices: [
278
+ {
279
+ name: `Change role (current: ${updatedUser.role})`,
280
+ value: 'role'
281
+ },
282
+ {
283
+ name: `Change state (current: ${updatedUser.state})`,
284
+ value: 'state'
285
+ },
286
+ {
287
+ name: `Update SSH keys (current: ${updatedUser.ssh_keys.length} key(s))`,
288
+ value: 'keys'
289
+ },
290
+ {
291
+ name: '💾 Save changes and return',
292
+ value: 'save'
293
+ },
294
+ {
295
+ name: '🚫 Cancel and discard changes',
296
+ value: 'cancel'
297
+ }
298
+ ]
299
+ });
300
+ switch (action) {
301
+ case 'role':
302
+ const newRole = yield selectRole();
303
+ if (newRole !== updatedUser.role) {
304
+ updatedUser.role = newRole;
305
+ }
306
+ break;
307
+ case 'state':
308
+ const newState = yield selectState();
309
+ if (newState !== updatedUser.state) {
310
+ updatedUser.state = newState;
311
+ }
312
+ break;
313
+ case 'keys':
314
+ const keysInput = yield editor({
315
+ message: 'Update SSH public key(s) (one per line):',
316
+ default: updatedUser.ssh_keys.join('\n')
317
+ });
318
+ const newKeys = keysInput
319
+ .split('\n')
320
+ .map((key) => key.trim())
321
+ .filter((key) => key && !key.startsWith('#'));
322
+ if (newKeys.length === 0) {
323
+ clearScreen();
324
+ displayUserState();
325
+ const confirmRemoveKeys = yield confirm({
326
+ message: '⚠️ Warning: All SSH keys will be removed. Continue with no SSH keys?',
327
+ default: false
328
+ });
329
+ if (confirmRemoveKeys) {
330
+ updatedUser.ssh_keys = [];
331
+ }
332
+ }
333
+ else {
334
+ updatedUser.ssh_keys = newKeys;
335
+ }
336
+ break;
337
+ case 'save':
338
+ const hasChanges = updatedUser.role !== user.role ||
339
+ updatedUser.state !== user.state ||
340
+ JSON.stringify(updatedUser.ssh_keys) !== JSON.stringify(user.ssh_keys);
341
+ clearScreen();
342
+ if (hasChanges) {
343
+ console.log('\n✅ Changes saved for user:', updatedUser.name, '\n');
344
+ }
345
+ else {
346
+ console.log('\nℹ️ No changes made\n');
347
+ }
348
+ continueEditing = false;
349
+ break;
350
+ case 'cancel':
351
+ clearScreen();
352
+ const confirmCancel = yield confirm({
353
+ message: 'Discard all changes?',
354
+ default: false
355
+ });
356
+ if (confirmCancel) {
357
+ console.log('\n🚫 Changes discarded\n');
358
+ return user; // Return original user
359
+ }
360
+ break;
361
+ }
362
+ }
363
+ return updatedUser;
364
+ });
365
+ }
366
+ /**
367
+ * Main function to manage users
368
+ */
369
+ function manageUsers(inventoryPath) {
370
+ return __awaiter(this, void 0, void 0, function* () {
371
+ let users = fs.existsSync(inventoryPath) ? parseInventoryFile(inventoryPath) : [];
372
+ if (users.length > 0) {
373
+ displayUserSummary(users);
374
+ }
375
+ let continueManaging = true;
376
+ while (continueManaging) {
377
+ const action = yield select({
378
+ message: 'What would you like to do?',
379
+ choices: [
380
+ { name: '➕ Add new user', value: 'add' },
381
+ { name: '✏️ Edit existing user', value: 'edit' },
382
+ { name: '🗑️ Remove user', value: 'remove' },
383
+ { name: '👤 Add current system user', value: 'add-current' },
384
+ { name: '📋 View all users', value: 'view' },
385
+ { name: '💾 Save and exit', value: 'save' },
386
+ { name: '🚪 Exit without saving', value: 'exit' }
387
+ ]
388
+ });
389
+ switch (action) {
390
+ case 'add':
391
+ const newUser = yield addNewUser(users);
392
+ if (newUser) {
393
+ users.push(newUser);
394
+ console.log(`✅ User "${newUser.name}" added.\n`);
395
+ }
396
+ break;
397
+ case 'add-current':
398
+ const currentUser = yield askToAddCurrentUser(users);
399
+ if (currentUser) {
400
+ users.push(currentUser);
401
+ console.log(`✅ Current user "${currentUser.name}" added.\n`);
402
+ }
403
+ break;
404
+ case 'edit':
405
+ if (users.length === 0) {
406
+ console.log('⚠️ No users to edit.\n');
407
+ break;
408
+ }
409
+ const userToEdit = yield select({
410
+ message: 'Select user to edit:',
411
+ choices: users.map(u => ({
412
+ name: `${u.name} (${u.role}, ${u.state})`,
413
+ value: u.name
414
+ }))
415
+ });
416
+ const userIndex = users.findIndex(u => u.name === userToEdit);
417
+ if (userIndex !== -1) {
418
+ users[userIndex] = yield editUser(users[userIndex]);
419
+ console.log(`✅ User "${userToEdit}" updated.\n`);
420
+ }
421
+ break;
422
+ case 'remove':
423
+ if (users.length === 0) {
424
+ console.log('⚠️ No users to remove.\n');
425
+ break;
426
+ }
427
+ const usersToRemove = yield checkbox({
428
+ message: 'Select user(s) to remove:',
429
+ choices: users.map(u => ({
430
+ name: `${u.name} (${u.role}, ${u.state})`,
431
+ value: u.name
432
+ }))
433
+ });
434
+ if (usersToRemove.length > 0) {
435
+ const confirmRemove = yield confirm({
436
+ message: `Remove ${usersToRemove.length} user(s)?`,
437
+ default: false
438
+ });
439
+ if (confirmRemove) {
440
+ users = users.filter(u => !usersToRemove.includes(u.name));
441
+ console.log(`✅ Removed ${usersToRemove.length} user(s).\n`);
442
+ }
443
+ }
444
+ break;
445
+ case 'view':
446
+ displayUserSummary(users);
447
+ break;
448
+ case 'save':
449
+ if (users.length === 0) {
450
+ (0, logger_1.info)('\n📋 No users configured.\n');
451
+ continueManaging = false;
452
+ break;
453
+ }
454
+ displayUserSummary(users);
455
+ const confirmSave = yield confirm({
456
+ message: 'Save changes end exit?',
457
+ default: true
458
+ });
459
+ if (confirmSave && fs.existsSync(inventoryPath)) {
460
+ updateInventoryFile(inventoryPath, users);
461
+ console.log(`\n✅ Changes saved to ${inventoryPath}\n`);
462
+ }
463
+ continueManaging = false;
464
+ break;
465
+ case 'exit':
466
+ if (users.length === 0) {
467
+ (0, logger_1.info)('\n📋 No users configured.\n');
468
+ continueManaging = false;
469
+ break;
470
+ }
471
+ const confirmExit = yield confirm({
472
+ message: 'Exit without saving changes?',
473
+ default: false
474
+ });
475
+ if (confirmExit) {
476
+ console.log('👋 Exited without saving.\n');
477
+ continueManaging = false;
478
+ }
479
+ break;
480
+ }
481
+ }
482
+ return users;
483
+ });
484
+ }
@@ -0,0 +1,15 @@
1
+ import { Choice } from 'prompts';
2
+ export declare function getIndexFromChoices(choices: Choice[], value: string): number;
3
+ type SelectWithCustomOptions = {
4
+ message: string;
5
+ choices: readonly {
6
+ name: string;
7
+ value: string;
8
+ }[];
9
+ customLabel?: string;
10
+ customInputMessage?: string;
11
+ initial?: string;
12
+ };
13
+ export declare function selectWithCustom(config: SelectWithCustomOptions): Promise<string>;
14
+ export {};
15
+ //# sourceMappingURL=questions-helper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"questions-helper.d.ts","sourceRoot":"","sources":["../../src/environment/questions-helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAajC,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,UASnE;AAED,KAAK,uBAAuB,GAAG;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,SAAS;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IACpD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,wBAAsB,gBAAgB,CAClC,MAAM,EAAE,uBAAuB,GAChC,OAAO,CAAC,MAAM,CAAC,CAkCjB"}
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.getIndexFromChoices = getIndexFromChoices;
13
+ exports.selectWithCustom = selectWithCustom;
14
+ function input(options) {
15
+ return __awaiter(this, void 0, void 0, function* () {
16
+ const inquirer = yield import('@inquirer/prompts');
17
+ return inquirer.input(options);
18
+ });
19
+ }
20
+ function select(options) {
21
+ return __awaiter(this, void 0, void 0, function* () {
22
+ const inquirer = yield import('@inquirer/prompts');
23
+ return inquirer.select(options);
24
+ });
25
+ }
26
+ function getIndexFromChoices(choices, value) {
27
+ let idx = 0;
28
+ for (const choice of choices) {
29
+ if (choice.value === value) {
30
+ return idx;
31
+ }
32
+ idx++;
33
+ }
34
+ return 0;
35
+ }
36
+ function selectWithCustom(config) {
37
+ return __awaiter(this, void 0, void 0, function* () {
38
+ const { message, choices, initial = undefined, customLabel = 'Other...', customInputMessage = 'Enter custom value:', } = config;
39
+ const CUSTOM = '__custom__';
40
+ const selected = yield select({
41
+ message,
42
+ choices: [
43
+ ...choices,
44
+ {
45
+ value: CUSTOM,
46
+ name: customLabel,
47
+ },
48
+ ],
49
+ default: initial,
50
+ });
51
+ if (selected === CUSTOM) {
52
+ const customValue = yield input({
53
+ message: customInputMessage,
54
+ validate: (value) => value.trim().length > 0 ? true : 'Value cannot be empty',
55
+ });
56
+ return customValue;
57
+ }
58
+ return selected;
59
+ });
60
+ }