@salesforce/sf-plugins-core 1.5.3 → 1.6.0
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.
- package/CHANGELOG.md +6 -0
- package/lib/ux/prompter.d.ts +4 -0
- package/lib/ux/prompter.js +22 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
## [1.6.0](https://github.com/salesforcecli/sf-plugins-core/compare/v1.5.3...v1.6.0) (2022-03-08)
|
|
6
|
+
|
|
7
|
+
### Features
|
|
8
|
+
|
|
9
|
+
- add timedPrompt method ([ea9e98c](https://github.com/salesforcecli/sf-plugins-core/commit/ea9e98c5bffdfc1e917d61006a91f4dba1f808f3))
|
|
10
|
+
|
|
5
11
|
### [1.5.3](https://github.com/salesforcecli/sf-plugins-core/compare/v1.5.2...v1.5.3) (2022-03-08)
|
|
6
12
|
|
|
7
13
|
### Bug Fixes
|
package/lib/ux/prompter.d.ts
CHANGED
|
@@ -5,6 +5,10 @@ export declare class Prompter {
|
|
|
5
5
|
* Prompt user for information. See https://www.npmjs.com/package/inquirer for more.
|
|
6
6
|
*/
|
|
7
7
|
prompt<T = Prompter.Answers>(questions: Prompter.Questions<T>, initialAnswers?: Partial<T>): Promise<T>;
|
|
8
|
+
/**
|
|
9
|
+
* Prompt user for information with a timeout (in milliseconds). See https://www.npmjs.com/package/inquirer for more.
|
|
10
|
+
*/
|
|
11
|
+
timedPrompt<T = Prompter.Answers>(questions: Prompter.Questions<T>, ms?: number, initialAnswers?: Partial<T>): Promise<T>;
|
|
8
12
|
}
|
|
9
13
|
export declare namespace Prompter {
|
|
10
14
|
type Answers<T = Record<string, unknown>> = T & Record<string, unknown>;
|
package/lib/ux/prompter.js
CHANGED
|
@@ -9,6 +9,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.generateTableChoices = exports.Prompter = void 0;
|
|
10
10
|
const inquirer_1 = require("inquirer");
|
|
11
11
|
const ts_types_1 = require("@salesforce/ts-types");
|
|
12
|
+
const core_1 = require("@oclif/core");
|
|
12
13
|
class Prompter {
|
|
13
14
|
/**
|
|
14
15
|
* Prompt user for information. See https://www.npmjs.com/package/inquirer for more.
|
|
@@ -17,6 +18,27 @@ class Prompter {
|
|
|
17
18
|
const answers = await (0, inquirer_1.prompt)(questions, initialAnswers);
|
|
18
19
|
return answers;
|
|
19
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Prompt user for information with a timeout (in milliseconds). See https://www.npmjs.com/package/inquirer for more.
|
|
23
|
+
*/
|
|
24
|
+
async timedPrompt(questions, ms = 10000, initialAnswers) {
|
|
25
|
+
let id;
|
|
26
|
+
const thePrompt = (0, inquirer_1.prompt)(questions, initialAnswers);
|
|
27
|
+
const timeout = new Promise((_, reject) => {
|
|
28
|
+
id = setTimeout(() => {
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
30
|
+
// @ts-expect-error
|
|
31
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
32
|
+
thePrompt.ui['activePrompt'].done();
|
|
33
|
+
core_1.CliUx.ux.log();
|
|
34
|
+
reject(new Error(`Timed out after ${ms} ms.`));
|
|
35
|
+
}, ms).unref();
|
|
36
|
+
});
|
|
37
|
+
return Promise.race([timeout, thePrompt]).then((result) => {
|
|
38
|
+
clearTimeout(id);
|
|
39
|
+
return result;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
20
42
|
}
|
|
21
43
|
exports.Prompter = Prompter;
|
|
22
44
|
/**
|