1 |
|
2 |
|
3 |
|
4 |
|
5 | import { input, select, number, confirm, rawlist, expand, checkbox, password, editor, Separator, } from '@inquirer/prompts';
|
6 | import { default as PromptsRunner } from './ui/prompt.mjs';
|
7 | const defaultPrompts = {
|
8 | input,
|
9 | select,
|
10 |
|
11 | list: select,
|
12 | number,
|
13 | confirm,
|
14 | rawlist,
|
15 | expand,
|
16 | checkbox,
|
17 | password,
|
18 | editor,
|
19 | };
|
20 |
|
21 |
|
22 |
|
23 | export function createPromptModule(opt) {
|
24 | function promptModule(questions, answers) {
|
25 | const runner = new PromptsRunner(promptModule.prompts, opt);
|
26 | try {
|
27 | return runner.run(questions, answers);
|
28 | }
|
29 | catch (error) {
|
30 | const promise = Promise.reject(error);
|
31 | return Object.assign(promise, { ui: runner });
|
32 | }
|
33 | }
|
34 | promptModule.prompts = { ...defaultPrompts };
|
35 | |
36 |
|
37 |
|
38 | promptModule.registerPrompt = function (name, prompt) {
|
39 | promptModule.prompts[name] = prompt;
|
40 | return this;
|
41 | };
|
42 | |
43 |
|
44 |
|
45 | promptModule.restoreDefaultPrompts = function () {
|
46 | promptModule.prompts = { ...defaultPrompts };
|
47 | };
|
48 | return promptModule;
|
49 | }
|
50 |
|
51 |
|
52 |
|
53 | const prompt = createPromptModule();
|
54 |
|
55 | function registerPrompt(name, newPrompt) {
|
56 | prompt.registerPrompt(name, newPrompt);
|
57 | }
|
58 | function restoreDefaultPrompts() {
|
59 | prompt.restoreDefaultPrompts();
|
60 | }
|
61 | const inquirer = {
|
62 | prompt,
|
63 | ui: {
|
64 | Prompt: PromptsRunner,
|
65 | },
|
66 | createPromptModule,
|
67 | registerPrompt,
|
68 | restoreDefaultPrompts,
|
69 | Separator,
|
70 | };
|
71 | export default inquirer;
|