UNPKG

2.29 kBJavaScriptView Raw
1"use strict";
2/**
3 * Inquirer.js
4 * A collection of common interactive command line user interfaces.
5 */
6var __importDefault = (this && this.__importDefault) || function (mod) {
7 return (mod && mod.__esModule) ? mod : { "default": mod };
8};
9Object.defineProperty(exports, "__esModule", { value: true });
10exports.createPromptModule = createPromptModule;
11const prompts_1 = require("@inquirer/prompts");
12const prompt_mjs_1 = __importDefault(require('./ui/prompt.js'));
13const defaultPrompts = {
14 input: prompts_1.input,
15 select: prompts_1.select,
16 /** @deprecated `list` is now named `select` */
17 list: prompts_1.select,
18 number: prompts_1.number,
19 confirm: prompts_1.confirm,
20 rawlist: prompts_1.rawlist,
21 expand: prompts_1.expand,
22 checkbox: prompts_1.checkbox,
23 password: prompts_1.password,
24 editor: prompts_1.editor,
25};
26/**
27 * Create a new self-contained prompt module.
28 */
29function createPromptModule(opt) {
30 function promptModule(questions, answers) {
31 const runner = new prompt_mjs_1.default(promptModule.prompts, opt);
32 try {
33 return runner.run(questions, answers);
34 }
35 catch (error) {
36 const promise = Promise.reject(error);
37 return Object.assign(promise, { ui: runner });
38 }
39 }
40 promptModule.prompts = Object.assign({}, defaultPrompts);
41 /**
42 * Register a prompt type
43 */
44 promptModule.registerPrompt = function (name, prompt) {
45 promptModule.prompts[name] = prompt;
46 return this;
47 };
48 /**
49 * Register the defaults provider prompts
50 */
51 promptModule.restoreDefaultPrompts = function () {
52 promptModule.prompts = Object.assign({}, defaultPrompts);
53 };
54 return promptModule;
55}
56/**
57 * Public CLI helper interface
58 */
59const prompt = createPromptModule();
60// Expose helper functions on the top level for easiest usage by common users
61function registerPrompt(name, newPrompt) {
62 prompt.registerPrompt(name, newPrompt);
63}
64function restoreDefaultPrompts() {
65 prompt.restoreDefaultPrompts();
66}
67const inquirer = {
68 prompt,
69 ui: {
70 Prompt: prompt_mjs_1.default,
71 },
72 createPromptModule,
73 registerPrompt,
74 restoreDefaultPrompts,
75 Separator: prompts_1.Separator,
76};
77exports.default = inquirer;