@sap-ux/inquirer-common 0.2.8 → 0.3.1
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/dist/prompts/helpers.d.ts +8 -4
- package/dist/prompts/helpers.js +22 -10
- package/dist/types.d.ts +5 -1
- package/package.json +4 -2
|
@@ -5,26 +5,29 @@ import type { CommonPromptOptions, PromptDefaultValue, PromptSeverityMessage, YU
|
|
|
5
5
|
*
|
|
6
6
|
* @param question - the question to which the validate function will be applied
|
|
7
7
|
* @param addMsgFunc - the additional messages function which will be applied to the question
|
|
8
|
+
* @param promptState - the runtime state of the prompts, this can be used to provide additional answers not defined by the prompt answers object
|
|
8
9
|
* @returns the extended additional messages function
|
|
9
10
|
*/
|
|
10
|
-
export declare function extendAdditionalMessages(question: YUIQuestion, addMsgFunc: PromptSeverityMessage): PromptSeverityMessage;
|
|
11
|
+
export declare function extendAdditionalMessages(question: YUIQuestion, addMsgFunc: PromptSeverityMessage, promptState?: Answers): PromptSeverityMessage;
|
|
11
12
|
/**
|
|
12
13
|
* Extends a validate function. The extended function will be called first.
|
|
13
14
|
*
|
|
14
15
|
* @param question - the question to which the validate function will be applied
|
|
15
16
|
* @param validateFunc - the validate function which will be applied to the question
|
|
17
|
+
* @param promptState - the runtime state of the prompts, this can be used to provide additional answers not defined by the prompt answers object
|
|
16
18
|
* @returns the extended validate function
|
|
17
19
|
*/
|
|
18
|
-
export declare function extendValidate<T extends Answers = Answers>(question: Question, validateFunc: NonNullable<Validator<T
|
|
20
|
+
export declare function extendValidate<T extends Answers = Answers>(question: Question, validateFunc: NonNullable<Validator<T>>, promptState?: Answers): NonNullable<Validator<T>>;
|
|
19
21
|
/**
|
|
20
22
|
* Extend the existing prompt property function with the one specified in prompt options or add as new.
|
|
21
23
|
*
|
|
22
24
|
* @param question - the question to which the extending function will be applied
|
|
23
25
|
* @param promptOption - prompt options, containing extending functions
|
|
24
26
|
* @param funcName - the question property (function) name to extend
|
|
27
|
+
* @param promptState - the runtime state of the prompts, this can be used to provide additional answers not defined by the prompt answers object
|
|
25
28
|
* @returns the extended question
|
|
26
29
|
*/
|
|
27
|
-
export declare function applyExtensionFunction<T extends Answers = Answers>(question: YUIQuestion, promptOption: CommonPromptOptions<T>, funcName: 'validate' | 'additionalMessages'): YUIQuestion;
|
|
30
|
+
export declare function applyExtensionFunction<T extends Answers = Answers>(question: YUIQuestion, promptOption: CommonPromptOptions<T>, funcName: 'validate' | 'additionalMessages', promptState?: Answers): YUIQuestion;
|
|
28
31
|
/**
|
|
29
32
|
* Adds additional conditions to the provided questions.
|
|
30
33
|
*
|
|
@@ -38,7 +41,8 @@ export declare function withCondition(questions: Question[], condition: (answers
|
|
|
38
41
|
*
|
|
39
42
|
* @param questions - array of prompts to be extended
|
|
40
43
|
* @param promptOptions - the prompt options possibly containing function extensions
|
|
44
|
+
* @param promptState - the runtime state of the prompts, this can be used to provide additional answers not defined by the prompt answers object
|
|
41
45
|
* @returns - the extended questions
|
|
42
46
|
*/
|
|
43
|
-
export declare function extendWithOptions<T extends YUIQuestion = YUIQuestion>(questions: T[], promptOptions: Record<string, CommonPromptOptions & PromptDefaultValue<string | boolean
|
|
47
|
+
export declare function extendWithOptions<T extends YUIQuestion = YUIQuestion>(questions: T[], promptOptions: Record<string, CommonPromptOptions & PromptDefaultValue<string | boolean>>, promptState?: Answers): YUIQuestion[];
|
|
44
48
|
//# sourceMappingURL=helpers.d.ts.map
|
package/dist/prompts/helpers.js
CHANGED
|
@@ -1,17 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.extendWithOptions = exports.withCondition = exports.applyExtensionFunction = exports.extendValidate = exports.extendAdditionalMessages = void 0;
|
|
7
|
+
const cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
|
|
4
8
|
/**
|
|
5
9
|
* Extends an additionalMessages function.
|
|
6
10
|
*
|
|
7
11
|
* @param question - the question to which the validate function will be applied
|
|
8
12
|
* @param addMsgFunc - the additional messages function which will be applied to the question
|
|
13
|
+
* @param promptState - the runtime state of the prompts, this can be used to provide additional answers not defined by the prompt answers object
|
|
9
14
|
* @returns the extended additional messages function
|
|
10
15
|
*/
|
|
11
|
-
function extendAdditionalMessages(question, addMsgFunc) {
|
|
16
|
+
function extendAdditionalMessages(question, addMsgFunc, promptState) {
|
|
12
17
|
const addMsgs = question.additionalMessages;
|
|
13
18
|
return (value, previousAnswers) => {
|
|
14
|
-
|
|
19
|
+
// Allow non-prompt answer (derived answers) values to be passed to the additional messages function
|
|
20
|
+
// We clone as answers should never be mutatable in prompt functions
|
|
21
|
+
const combinedAnswers = Object.assign(Object.assign({}, (0, cloneDeep_1.default)(previousAnswers)), (0, cloneDeep_1.default)(promptState));
|
|
22
|
+
const extMsg = addMsgFunc(value, combinedAnswers);
|
|
15
23
|
if (extMsg) {
|
|
16
24
|
return extMsg; // Extended prompt message is returned first
|
|
17
25
|
}
|
|
@@ -25,13 +33,15 @@ exports.extendAdditionalMessages = extendAdditionalMessages;
|
|
|
25
33
|
*
|
|
26
34
|
* @param question - the question to which the validate function will be applied
|
|
27
35
|
* @param validateFunc - the validate function which will be applied to the question
|
|
36
|
+
* @param promptState - the runtime state of the prompts, this can be used to provide additional answers not defined by the prompt answers object
|
|
28
37
|
* @returns the extended validate function
|
|
29
38
|
*/
|
|
30
|
-
function extendValidate(question, validateFunc) {
|
|
39
|
+
function extendValidate(question, validateFunc, promptState) {
|
|
31
40
|
const validate = question.validate;
|
|
32
41
|
return (value, previousAnswers) => {
|
|
33
|
-
//
|
|
34
|
-
const
|
|
42
|
+
// Allow non-prompt answer (derived answers) values to be passed to the validate function
|
|
43
|
+
const combinedAnswers = Object.assign(Object.assign({}, (0, cloneDeep_1.default)(previousAnswers)), (0, cloneDeep_1.default)(promptState));
|
|
44
|
+
const extVal = validateFunc === null || validateFunc === void 0 ? void 0 : validateFunc(value, combinedAnswers);
|
|
35
45
|
if (extVal !== true) {
|
|
36
46
|
return extVal;
|
|
37
47
|
}
|
|
@@ -45,15 +55,16 @@ exports.extendValidate = extendValidate;
|
|
|
45
55
|
* @param question - the question to which the extending function will be applied
|
|
46
56
|
* @param promptOption - prompt options, containing extending functions
|
|
47
57
|
* @param funcName - the question property (function) name to extend
|
|
58
|
+
* @param promptState - the runtime state of the prompts, this can be used to provide additional answers not defined by the prompt answers object
|
|
48
59
|
* @returns the extended question
|
|
49
60
|
*/
|
|
50
|
-
function applyExtensionFunction(question, promptOption, funcName) {
|
|
61
|
+
function applyExtensionFunction(question, promptOption, funcName, promptState) {
|
|
51
62
|
let extendedFunc;
|
|
52
63
|
if (funcName === 'validate' && promptOption.validate) {
|
|
53
|
-
extendedFunc = extendValidate(question, promptOption.validate);
|
|
64
|
+
extendedFunc = extendValidate(question, promptOption.validate, promptState);
|
|
54
65
|
}
|
|
55
66
|
if (funcName === 'additionalMessages' && promptOption.additionalMessages) {
|
|
56
|
-
extendedFunc = extendAdditionalMessages(question, promptOption.additionalMessages);
|
|
67
|
+
extendedFunc = extendAdditionalMessages(question, promptOption.additionalMessages, promptState);
|
|
57
68
|
}
|
|
58
69
|
question = Object.assign(question, { [funcName]: extendedFunc });
|
|
59
70
|
return question;
|
|
@@ -99,9 +110,10 @@ exports.withCondition = withCondition;
|
|
|
99
110
|
*
|
|
100
111
|
* @param questions - array of prompts to be extended
|
|
101
112
|
* @param promptOptions - the prompt options possibly containing function extensions
|
|
113
|
+
* @param promptState - the runtime state of the prompts, this can be used to provide additional answers not defined by the prompt answers object
|
|
102
114
|
* @returns - the extended questions
|
|
103
115
|
*/
|
|
104
|
-
function extendWithOptions(questions, promptOptions) {
|
|
116
|
+
function extendWithOptions(questions, promptOptions, promptState) {
|
|
105
117
|
questions.forEach((question) => {
|
|
106
118
|
const promptOptKey = question.name;
|
|
107
119
|
const promptOpt = promptOptions[question.name];
|
|
@@ -109,7 +121,7 @@ function extendWithOptions(questions, promptOptions) {
|
|
|
109
121
|
const propsToExtend = Object.keys(promptOpt);
|
|
110
122
|
for (const extProp of propsToExtend) {
|
|
111
123
|
if (extProp === 'validate' || extProp === 'additionalMessages') {
|
|
112
|
-
question = applyExtensionFunction(question, promptOpt, extProp);
|
|
124
|
+
question = applyExtensionFunction(question, promptOpt, extProp, promptState);
|
|
113
125
|
}
|
|
114
126
|
// Provided defaults will override built in defaults
|
|
115
127
|
const defaultOverride = promptOptions[promptOptKey].default;
|
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type IMessageSeverity } from '@sap-devx/yeoman-ui-types';
|
|
2
|
-
import type { Answers, ConfirmQuestion as BaseConfirmQuestion, InputQuestion as BaseInputQuestion, ListQuestion as BaseListQuestion, CheckboxQuestion as BaseCheckBoxQuestion, ListChoiceOptions, PromptFunction, PromptModule, Question, Validator, AsyncDynamicQuestionProperty } from 'inquirer';
|
|
2
|
+
import type { Answers, ConfirmQuestion as BaseConfirmQuestion, InputQuestion as BaseInputQuestion, ListQuestion as BaseListQuestion, CheckboxQuestion as BaseCheckBoxQuestion, NumberQuestion as BaseNumberQuestion, ListChoiceOptions, PromptFunction, PromptModule, Question, Validator, AsyncDynamicQuestionProperty } from 'inquirer';
|
|
3
3
|
export interface UI5VersionChoice extends ListChoiceOptions {
|
|
4
4
|
/**
|
|
5
5
|
* UI5 semantic version
|
|
@@ -66,6 +66,10 @@ export interface CheckBoxQuestion<A extends Answers = Answers> extends BaseCheck
|
|
|
66
66
|
guiOptions?: YUIQuestion['guiOptions'];
|
|
67
67
|
additionalMessages?: YUIQuestion['additionalMessages'];
|
|
68
68
|
}
|
|
69
|
+
export interface NumberQuestion<A extends Answers = Answers> extends BaseNumberQuestion<A> {
|
|
70
|
+
name: YUIQuestion['name'];
|
|
71
|
+
guiOptions?: YUIQuestion['guiOptions'];
|
|
72
|
+
}
|
|
69
73
|
/**
|
|
70
74
|
* Defines prompt/question default values and/or whether or not they should be shown.
|
|
71
75
|
*/
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sap-ux/inquirer-common",
|
|
3
3
|
"description": "Commonly used shared functionality and types to support inquirer modules.",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.3.1",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "https://github.com/SAP/open-ux-tools.git",
|
|
@@ -24,12 +24,14 @@
|
|
|
24
24
|
"chalk": "4.1.2",
|
|
25
25
|
"figures": "3.2.0",
|
|
26
26
|
"semver": "7.5.4",
|
|
27
|
+
"lodash": "4.17.21",
|
|
27
28
|
"@sap-ux/ui5-info": "0.5.0"
|
|
28
29
|
},
|
|
29
30
|
"devDependencies": {
|
|
30
31
|
"@sap-devx/yeoman-ui-types": "1.14.4",
|
|
31
32
|
"@types/inquirer": "8.2.6",
|
|
32
|
-
"@types/semver": "7.5.4"
|
|
33
|
+
"@types/semver": "7.5.4",
|
|
34
|
+
"@types/lodash": "4.14.202"
|
|
33
35
|
},
|
|
34
36
|
"engines": {
|
|
35
37
|
"node": ">=18.x"
|