@sap-ux/ui5-application-inquirer 0.3.14 → 0.3.16
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/index.d.ts +2 -2
- package/dist/prompts/prompt-helpers.d.ts +0 -17
- package/dist/prompts/prompt-helpers.js +2 -102
- package/dist/prompts/prompts.js +2 -2
- package/dist/types.d.ts +5 -12
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type CdsUi5PluginInfo } from '@sap-ux/cap-config-writer';
|
|
2
|
-
import type { InquirerAdapter } from '@sap-ux/inquirer-common';
|
|
3
|
-
import type {
|
|
2
|
+
import type { InquirerAdapter, PromptDefaultValue } from '@sap-ux/inquirer-common';
|
|
3
|
+
import type { UI5ApplicationAnswers, UI5ApplicationPromptOptions, UI5ApplicationQuestion } from './types';
|
|
4
4
|
import { promptNames } from './types';
|
|
5
5
|
/**
|
|
6
6
|
* Get the inquirer prompts for ui5 library inquirer.
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { Answers, Question } from 'inquirer';
|
|
2
1
|
import { promptNames, type UI5ApplicationPromptOptions, type UI5ApplicationQuestion } from '../types';
|
|
3
2
|
/**
|
|
4
3
|
* Tests if a directory with the specified `appName` exists at the path specified by `targetPath`.
|
|
@@ -24,22 +23,6 @@ export declare function defaultAppName(targetPath: string): string;
|
|
|
24
23
|
* @returns - true if the specified version is greater than or equal to the minimum version, or the version is not a coercible semver
|
|
25
24
|
*/
|
|
26
25
|
export declare function isVersionIncluded(version: string, minVersion: string): boolean;
|
|
27
|
-
/**
|
|
28
|
-
* Adds additional conditions to the provided questions.
|
|
29
|
-
*
|
|
30
|
-
* @param questions the questions to which the condition will be added
|
|
31
|
-
* @param condition function which returns true or false
|
|
32
|
-
* @returns the passed questions reference
|
|
33
|
-
*/
|
|
34
|
-
export declare function withCondition(questions: Question[], condition: (answers: Answers) => boolean): Question[];
|
|
35
|
-
/**
|
|
36
|
-
* Updates questions with extensions for specific properties. Only `validate`, `default` and `additionalMessages` are currently supported.
|
|
37
|
-
*
|
|
38
|
-
* @param questions - array of prompts to be extended
|
|
39
|
-
* @param promptOptions - the prompt options possibly containing function extensions
|
|
40
|
-
* @returns - the extended questions
|
|
41
|
-
*/
|
|
42
|
-
export declare function extendWithOptions(questions: UI5ApplicationQuestion[], promptOptions: UI5ApplicationPromptOptions): UI5ApplicationQuestion[];
|
|
43
26
|
/**
|
|
44
27
|
* Will remove prompts from the specified prompts based on prompt options
|
|
45
28
|
* and applicability in the case of CAP projects. Removing prompts is preferable to using `when()`
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.hidePrompts = exports.
|
|
4
|
-
const
|
|
3
|
+
exports.hidePrompts = exports.isVersionIncluded = exports.defaultAppName = exports.appPathExists = void 0;
|
|
4
|
+
const ui5_info_1 = require("@sap-ux/ui5-info");
|
|
5
5
|
const fs_1 = require("fs");
|
|
6
6
|
const path_1 = require("path");
|
|
7
7
|
const semver_1 = require("semver");
|
|
8
8
|
const i18n_1 = require("../i18n");
|
|
9
9
|
const types_1 = require("../types");
|
|
10
|
-
const ui5_info_1 = require("@sap-ux/ui5-info");
|
|
11
10
|
/**
|
|
12
11
|
* Tests if a directory with the specified `appName` exists at the path specified by `targetPath`.
|
|
13
12
|
*
|
|
@@ -55,105 +54,6 @@ function isVersionIncluded(version, minVersion) {
|
|
|
55
54
|
return version === ui5_info_1.latestVersionString;
|
|
56
55
|
}
|
|
57
56
|
exports.isVersionIncluded = isVersionIncluded;
|
|
58
|
-
/**
|
|
59
|
-
* Adds additional conditions to the provided questions.
|
|
60
|
-
*
|
|
61
|
-
* @param questions the questions to which the condition will be added
|
|
62
|
-
* @param condition function which returns true or false
|
|
63
|
-
* @returns the passed questions reference
|
|
64
|
-
*/
|
|
65
|
-
function withCondition(questions, condition) {
|
|
66
|
-
questions.forEach((question) => {
|
|
67
|
-
if (question.when !== undefined) {
|
|
68
|
-
if (typeof question.when === 'function') {
|
|
69
|
-
const when = question.when;
|
|
70
|
-
question.when = (answers) => {
|
|
71
|
-
if (condition(answers)) {
|
|
72
|
-
return when(answers);
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
return false;
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
const whenValue = question.when;
|
|
81
|
-
question.when = (answers) => {
|
|
82
|
-
return condition(answers) && whenValue;
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
question.when = condition;
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
return questions;
|
|
91
|
-
}
|
|
92
|
-
exports.withCondition = withCondition;
|
|
93
|
-
/**
|
|
94
|
-
* Extends a validate function.
|
|
95
|
-
*
|
|
96
|
-
* @param question - the question to which the validate function will be applied
|
|
97
|
-
* @param validateFunc - the validate function which will be applied to the question
|
|
98
|
-
* @returns the extended validate function
|
|
99
|
-
*/
|
|
100
|
-
function extendValidate(question, validateFunc) {
|
|
101
|
-
const validate = question.validate;
|
|
102
|
-
return (value, previousAnswers) => {
|
|
103
|
-
const extVal = validateFunc(value, previousAnswers);
|
|
104
|
-
if (extVal !== true) {
|
|
105
|
-
return extVal;
|
|
106
|
-
}
|
|
107
|
-
return typeof validate === 'function' ? validate(value, previousAnswers) : true;
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Extend the existing prompt property function with the one specified in prompt options or add as new.
|
|
112
|
-
*
|
|
113
|
-
* @param question - the question to which the extending function will be applied
|
|
114
|
-
* @param promptOption - prompt options, containing extending functions
|
|
115
|
-
* @param funcName - the question property (function) name to extend
|
|
116
|
-
* @returns the extended question
|
|
117
|
-
*/
|
|
118
|
-
function applyExtensionFunction(question, promptOption, funcName) {
|
|
119
|
-
let extendedFunc;
|
|
120
|
-
if (funcName === 'validate' && promptOption.validate) {
|
|
121
|
-
extendedFunc = extendValidate(question, promptOption.validate);
|
|
122
|
-
}
|
|
123
|
-
if (funcName === 'additionalMessages' && promptOption.additionalMessages) {
|
|
124
|
-
extendedFunc = (0, inquirer_common_1.extendAdditionalMessages)(question, promptOption.additionalMessages);
|
|
125
|
-
}
|
|
126
|
-
question = Object.assign(question, { [funcName]: extendedFunc });
|
|
127
|
-
return question;
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Updates questions with extensions for specific properties. Only `validate`, `default` and `additionalMessages` are currently supported.
|
|
131
|
-
*
|
|
132
|
-
* @param questions - array of prompts to be extended
|
|
133
|
-
* @param promptOptions - the prompt options possibly containing function extensions
|
|
134
|
-
* @returns - the extended questions
|
|
135
|
-
*/
|
|
136
|
-
function extendWithOptions(questions, promptOptions) {
|
|
137
|
-
questions.forEach((question) => {
|
|
138
|
-
const promptOptKey = question.name;
|
|
139
|
-
const promptOpt = promptOptions[promptOptKey];
|
|
140
|
-
if (promptOpt) {
|
|
141
|
-
const propsToExtend = Object.keys(promptOpt);
|
|
142
|
-
for (const extProp of propsToExtend) {
|
|
143
|
-
if (extProp === 'validate' || extProp === 'additionalMessages') {
|
|
144
|
-
question = applyExtensionFunction(question, promptOpt, extProp);
|
|
145
|
-
}
|
|
146
|
-
// Provided defaults will override built in defaults
|
|
147
|
-
const defaultOverride = promptOptions[promptOptKey].default;
|
|
148
|
-
if (defaultOverride) {
|
|
149
|
-
question.default = defaultOverride;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
});
|
|
154
|
-
return questions;
|
|
155
|
-
}
|
|
156
|
-
exports.extendWithOptions = extendWithOptions;
|
|
157
57
|
/**
|
|
158
58
|
* Will remove prompts from the specified prompts based on prompt options
|
|
159
59
|
* and applicability in the case of CAP projects. Removing prompts is preferable to using `when()`
|
package/dist/prompts/prompts.js
CHANGED
|
@@ -60,7 +60,7 @@ function getQuestions(ui5Versions, promptOptions, capCdsInfo, isYUI = false) {
|
|
|
60
60
|
applyAdvancedOption(questions, promptOptions);
|
|
61
61
|
// Apply extended `validate`, `additionalMessages` or override `default` prompt properties
|
|
62
62
|
if (promptOptions) {
|
|
63
|
-
questions = (0,
|
|
63
|
+
questions = (0, inquirer_common_1.extendWithOptions)(questions, promptOptions);
|
|
64
64
|
}
|
|
65
65
|
return questions;
|
|
66
66
|
}
|
|
@@ -413,6 +413,6 @@ function getNamePrompt(targetDir, isCapProject, appName, isYUI) {
|
|
|
413
413
|
* @param promptOptions the prompt options which specify which prompts should be grouped as advanced options
|
|
414
414
|
*/
|
|
415
415
|
function applyAdvancedOption(questions, promptOptions) {
|
|
416
|
-
(0,
|
|
416
|
+
(0, inquirer_common_1.withCondition)(questions.filter(({ name }) => { var _a; return (_a = promptOptions === null || promptOptions === void 0 ? void 0 : promptOptions[name]) === null || _a === void 0 ? void 0 : _a.advancedOption; }), (answers) => { var _a; return (_a = answers.showAdvanced) !== null && _a !== void 0 ? _a : false; });
|
|
417
417
|
}
|
|
418
418
|
//# sourceMappingURL=prompts.js.map
|
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { AsyncDynamicQuestionProperty } from 'inquirer';
|
|
1
|
+
import type { CommonPromptOptions, PromptDefaultValue, UI5VersionChoice, YUIQuestion } from '@sap-ux/inquirer-common';
|
|
3
2
|
import type { AutocompleteQuestionOptions } from 'inquirer-autocomplete-prompt';
|
|
4
3
|
export interface UI5ApplicationAnswers {
|
|
5
4
|
name?: string;
|
|
@@ -87,23 +86,17 @@ type booleanValuePromptType = Pick<typeof promptNames, booleanPromptKeys>;
|
|
|
87
86
|
type booleanValuePrompts = booleanValuePromptType[keyof booleanValuePromptType];
|
|
88
87
|
type DefaultValueInputPrompts = promptNames.name | promptNames.description | promptNames.namespace | promptNames.ui5Version | promptNames.targetFolder;
|
|
89
88
|
type DefaultValueConfirmPrompts = promptNames.enableCodeAssist | promptNames.enableEslint | promptNames.skipAnnotations | promptNames.enableTypeScript;
|
|
90
|
-
export type PromptDefaultValue<T> = {
|
|
91
|
-
default?: AsyncDynamicQuestionProperty<T>;
|
|
92
|
-
};
|
|
93
89
|
/**
|
|
94
90
|
* Defines prompt/question default values and/or whether or not they should be shown.
|
|
95
91
|
*/
|
|
96
|
-
export type
|
|
97
|
-
hide?: boolean;
|
|
92
|
+
export type UI5ApplicationCommonPromptOptions = {
|
|
98
93
|
advancedOption?: boolean;
|
|
99
|
-
|
|
100
|
-
additionalMessages?: PromptSeverityMessage;
|
|
101
|
-
};
|
|
94
|
+
} & CommonPromptOptions;
|
|
102
95
|
/**
|
|
103
96
|
* Provide the correct type checking for string value prompts and `ui5Version` options
|
|
104
97
|
*
|
|
105
98
|
*/
|
|
106
|
-
type stringValuePromptOptions = Record<stringValuePrompts,
|
|
99
|
+
type stringValuePromptOptions = Record<stringValuePrompts, UI5ApplicationCommonPromptOptions> & Record<DefaultValueInputPrompts, PromptDefaultValue<string>> & Record<promptNames.ui5Version, UI5VersionPromptOptions>;
|
|
107
100
|
/**
|
|
108
101
|
* Provide the correct type checking for boolean value prompts and validator callback options
|
|
109
102
|
*
|
|
@@ -118,7 +111,7 @@ type booleanValuePromptOtions = Record<booleanValuePrompts, {
|
|
|
118
111
|
* @returns
|
|
119
112
|
*/
|
|
120
113
|
validatorCallback?: (answer: boolean, promptName: string) => void;
|
|
121
|
-
} &
|
|
114
|
+
} & UI5ApplicationCommonPromptOptions> & Record<DefaultValueConfirmPrompts, PromptDefaultValue<boolean>>;
|
|
122
115
|
export type UI5ApplicationQuestion = YUIQuestion<UI5ApplicationAnswers> & Partial<Pick<AutocompleteQuestionOptions, 'source'>>;
|
|
123
116
|
export type UI5ApplicationPromptOptions = Partial<stringValuePromptOptions & booleanValuePromptOtions>;
|
|
124
117
|
export {};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sap-ux/ui5-application-inquirer",
|
|
3
3
|
"description": "Prompts module that can prompt users for inputs required for UI5 application writing",
|
|
4
|
-
"version": "0.3.
|
|
4
|
+
"version": "0.3.16",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "https://github.com/SAP/open-ux-tools.git",
|
|
@@ -23,10 +23,10 @@
|
|
|
23
23
|
"inquirer-autocomplete-prompt": "2.0.1",
|
|
24
24
|
"lodash": "4.17.21",
|
|
25
25
|
"semver": "7.5.4",
|
|
26
|
-
"@sap-ux/inquirer-common": "0.2.
|
|
26
|
+
"@sap-ux/inquirer-common": "0.2.8",
|
|
27
27
|
"@sap-ux/project-access": "1.19.14",
|
|
28
28
|
"@sap-ux/project-input-validator": "0.2.3",
|
|
29
|
-
"@sap-ux/ui5-info": "0.
|
|
29
|
+
"@sap-ux/ui5-info": "0.5.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@sap-devx/yeoman-ui-types": "1.14.4",
|