Skip to content

Commit 9f131d4

Browse files
author
Dimitar Tachev
authored
Merge pull request #3959 from NativeScript/tachev/update-prompter
chore: update inquirer to the latest version
2 parents 92b7b06 + f62eada commit 9f131d4

File tree

10 files changed

+1792
-894
lines changed

10 files changed

+1792
-894
lines changed

lib/common/commands/proxy/proxy-set.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { ProxyCommandBase } from "./proxy-base";
44
import { HttpProtocolToPort } from "../../constants";
55
import { parse } from "url";
66
import { platform, EOL } from "os";
7+
import * as prompt from "inquirer";
78
const { getCredentialsFromAuth } = require("proxy-lib/lib/utils");
89

910
const proxySetCommandName = "proxy|set";
@@ -121,7 +122,7 @@ export class ProxySetCommand extends ProxyCommandBase {
121122

122123
private async getPortFromUserInput(): Promise<number> {
123124
const schemaName = "port";
124-
const schema: IPromptSchema = {
125+
const schema: prompt.Question = {
125126
message: "Port",
126127
type: "input",
127128
name: schemaName,

lib/common/declarations.d.ts

-8
Original file line numberDiff line numberDiff line change
@@ -721,14 +721,6 @@ interface IPrompterOptions extends IAllowEmpty {
721721
defaultAction?: () => string
722722
}
723723

724-
interface IPrompter extends IDisposable {
725-
get(schemas: IPromptSchema[]): Promise<any>;
726-
getPassword(prompt: string, options?: IAllowEmpty): Promise<string>;
727-
getString(prompt: string, options?: IPrompterOptions): Promise<string>;
728-
promptForChoice(promptMessage: string, choices: any[]): Promise<string>;
729-
confirm(prompt: string, defaultAction?: () => boolean): Promise<boolean>;
730-
}
731-
732724
interface IAnalyticsSettingsService {
733725
canDoRequest(): Promise<boolean>;
734726
getUserId(): Promise<string>;

lib/common/definitions/prompt.d.ts

-295
This file was deleted.

lib/common/prompter.ts

+10-21
Original file line numberDiff line numberDiff line change
@@ -14,45 +14,34 @@ export class Prompter implements IPrompter {
1414
}
1515
}
1616

17-
public async get(schemas: IPromptSchema[]): Promise<any> {
18-
let promptResult: any;
19-
17+
public async get(questions: prompt.Question[]): Promise<any> {
2018
try {
21-
promptResult = await new Promise<any>((resolve, reject) => {
2219
this.muteStdout();
2320

2421
if (!helpers.isInteractive()) {
25-
if (_.some(schemas, s => !s.default)) {
26-
reject(new Error("Console is not interactive and no default action specified."));
22+
if (_.some(questions, s => !s.default)) {
23+
throw new Error("Console is not interactive and no default action specified.");
2724
} else {
2825
const result: any = {};
2926

30-
_.each(schemas, s => {
27+
_.each(questions, s => {
3128
// Curly brackets needed because s.default() may return false and break the loop
3229
result[s.name] = s.default();
3330
});
3431

35-
resolve(result);
32+
return result;
3633
}
3734
} else {
38-
prompt.prompt(schemas, (result: any) => {
39-
if (result) {
40-
resolve(result);
41-
} else {
42-
reject(new Error(`Unable to get result from prompt: ${result}`));
43-
}
44-
});
35+
const result = await prompt.prompt(questions);
36+
return result;
4537
}
46-
});
4738
} finally {
4839
this.unmuteStdout();
4940
}
50-
51-
return promptResult;
5241
}
5342

5443
public async getPassword(prompt: string, options?: IAllowEmpty): Promise<string> {
55-
const schema: IPromptSchema = {
44+
const schema: prompt.Question = {
5645
message: prompt,
5746
type: "password",
5847
name: "password",
@@ -67,7 +56,7 @@ export class Prompter implements IPrompter {
6756
}
6857

6958
public async getString(prompt: string, options?: IPrompterOptions): Promise<string> {
70-
const schema: IPromptSchema = {
59+
const schema: prompt.Question = {
7160
message: prompt,
7261
type: "input",
7362
name: "inputString",
@@ -83,7 +72,7 @@ export class Prompter implements IPrompter {
8372
}
8473

8574
public async promptForChoice(promptMessage: string, choices: any[]): Promise<string> {
86-
const schema: IPromptSchema = {
75+
const schema: prompt.Question = {
8776
message: promptMessage,
8877
type: "list",
8978
name: "userAnswer",

0 commit comments

Comments
 (0)