-
Notifications
You must be signed in to change notification settings - Fork 0
/
questions.ts
57 lines (54 loc) · 1.24 KB
/
questions.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import inquirer, { Answers, Question } from "inquirer";
import { isNonEmptyString } from "./validation";
/**
* Asks the input (text) question
* @param name The question name
* @param message The question to be asked
* @param answers The current answers
* @param defaultValue The default value to be used if none is provided
* @returns The updated answers
*/
export const askInputQuestion = (
name: string,
message: string,
answers: Answers,
defaultValue?: string
): Promise<Answers> =>
askQuestion(
{
type: "input",
name,
message,
validate: isNonEmptyString,
default: defaultValue,
},
answers
);
/**
* Asks the confirmation question (yes/no)
* @param name The question name
* @param message The question to be asked
* @param answers The current answers
* @returns The updated answers
*/
export const askConfirmQuestion = (
name: string,
message: string,
answers: Answers
): Promise<Answers> =>
askQuestion(
{
type: "confirm",
name,
message,
},
answers
);
const askQuestion = async (
question: Question,
answers: Answers
): Promise<Answers> => {
const answer = await inquirer.prompt([question]);
answers = { ...answers, ...answer };
return answers;
};