@sap-ux/ui5-application-inquirer 0.2.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/LICENSE +201 -0
- package/README.md +79 -0
- package/dist/i18n.d.ts +15 -0
- package/dist/i18n.js +54 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +104 -0
- package/dist/prompts/index.d.ts +2 -0
- package/dist/prompts/index.js +18 -0
- package/dist/prompts/prompt-helpers.d.ts +54 -0
- package/dist/prompts/prompt-helpers.js +203 -0
- package/dist/prompts/prompts.d.ts +14 -0
- package/dist/prompts/prompts.js +416 -0
- package/dist/prompts/validators.d.ts +10 -0
- package/dist/prompts/validators.js +27 -0
- package/dist/translations/ui5-application-inquirer.i18n.json +46 -0
- package/dist/types.d.ts +125 -0
- package/dist/types.js +44 -0
- package/package.json +54 -0
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hidePrompts = exports.extendWithOptions = exports.withCondition = exports.isVersionIncluded = exports.defaultAppName = exports.appPathExists = void 0;
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const semver_1 = require("semver");
|
|
7
|
+
const i18n_1 = require("../i18n");
|
|
8
|
+
const types_1 = require("../types");
|
|
9
|
+
const ui5_info_1 = require("@sap-ux/ui5-info");
|
|
10
|
+
/**
|
|
11
|
+
* Tests if a directory with the specified `appName` exists at the path specified by `targetPath`.
|
|
12
|
+
*
|
|
13
|
+
* @param appName directory name of application
|
|
14
|
+
* @param targetPath directory path where application directory would be created
|
|
15
|
+
* @returns true, if the combined path exists otherwise false
|
|
16
|
+
*/
|
|
17
|
+
function appPathExists(appName, targetPath) {
|
|
18
|
+
return (0, fs_1.existsSync)((0, path_1.join)(targetPath !== null && targetPath !== void 0 ? targetPath : process.cwd(), appName.trim()));
|
|
19
|
+
}
|
|
20
|
+
exports.appPathExists = appPathExists;
|
|
21
|
+
/**
|
|
22
|
+
* Generate a default applicaiton name that does not exist at the specified path.
|
|
23
|
+
*
|
|
24
|
+
* @param targetPath the target path where the application directory would be created
|
|
25
|
+
* @returns a suggested application name that can be created at the specified target path
|
|
26
|
+
*/
|
|
27
|
+
function defaultAppName(targetPath) {
|
|
28
|
+
let defProjNum = i18n_1.defaultProjectNumber;
|
|
29
|
+
let defaultName = (0, i18n_1.t)('prompts.appNameDefault');
|
|
30
|
+
while (exports.appPathExists(`${defaultName}`, targetPath)) {
|
|
31
|
+
defaultName = (0, i18n_1.t)('prompts.appNameDefault', { defaultProjectNumber: ++defProjNum });
|
|
32
|
+
// Dont loop forever, user will need to provide input otherwise
|
|
33
|
+
if (defProjNum > 999) {
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return defaultName;
|
|
38
|
+
}
|
|
39
|
+
exports.defaultAppName = defaultAppName;
|
|
40
|
+
/**
|
|
41
|
+
* Checks if the specified semantic version string is greater than or equal to the minimum version.
|
|
42
|
+
* If the specified version is not a parsable semantic version, returns true.
|
|
43
|
+
*
|
|
44
|
+
* @param version the version to test
|
|
45
|
+
* @param minVersion the minimum version to test against
|
|
46
|
+
* @returns - true if the specified version is greater than or equal to the minimum version, or the version is not a coercible semver
|
|
47
|
+
*/
|
|
48
|
+
function isVersionIncluded(version, minVersion) {
|
|
49
|
+
// Extract a usable version, `snapshot`, `latest` etc will be ignored
|
|
50
|
+
const ui5SemVer = (0, semver_1.coerce)(version);
|
|
51
|
+
if (ui5SemVer) {
|
|
52
|
+
return (0, semver_1.gte)(ui5SemVer, minVersion);
|
|
53
|
+
}
|
|
54
|
+
return version === ui5_info_1.latestVersionString;
|
|
55
|
+
}
|
|
56
|
+
exports.isVersionIncluded = isVersionIncluded;
|
|
57
|
+
/**
|
|
58
|
+
* Adds additional conditions to the provided questions.
|
|
59
|
+
*
|
|
60
|
+
* @param questions the questions to which the condition will be added
|
|
61
|
+
* @param condition function which returns true or false
|
|
62
|
+
* @returns the passed questions reference
|
|
63
|
+
*/
|
|
64
|
+
function withCondition(questions, condition) {
|
|
65
|
+
questions.forEach((question) => {
|
|
66
|
+
if (question.when !== undefined) {
|
|
67
|
+
if (typeof question.when === 'function') {
|
|
68
|
+
const when = question.when;
|
|
69
|
+
question.when = (answers) => {
|
|
70
|
+
if (condition(answers)) {
|
|
71
|
+
return when(answers);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
const whenValue = question.when;
|
|
80
|
+
question.when = (answers) => {
|
|
81
|
+
return condition(answers) && whenValue;
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
question.when = condition;
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
return questions;
|
|
90
|
+
}
|
|
91
|
+
exports.withCondition = withCondition;
|
|
92
|
+
/**
|
|
93
|
+
* Extends a validate function.
|
|
94
|
+
*
|
|
95
|
+
* @param question - the question to which the validate function will be applied
|
|
96
|
+
* @param validateFunc - the validate function which will be applied to the question
|
|
97
|
+
* @returns the extended validate function
|
|
98
|
+
*/
|
|
99
|
+
function extendValidate(question, validateFunc) {
|
|
100
|
+
const validate = question.validate;
|
|
101
|
+
return (value, previousAnswers) => {
|
|
102
|
+
const extVal = validateFunc(value, previousAnswers);
|
|
103
|
+
if (extVal !== true) {
|
|
104
|
+
return extVal;
|
|
105
|
+
}
|
|
106
|
+
return typeof validate === 'function' ? validate(value, previousAnswers) : true;
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Extends an additionalMessages function.
|
|
111
|
+
*
|
|
112
|
+
* @param question - the question to which the validate function will be applied
|
|
113
|
+
* @param addMsgFunc - the additional messages function which will be applied to the question
|
|
114
|
+
* @returns the extended additional messages function
|
|
115
|
+
*/
|
|
116
|
+
function extendAdditionalMessages(question, addMsgFunc) {
|
|
117
|
+
const addMsgs = question.additionalMessages;
|
|
118
|
+
return (value, previousAnswers) => {
|
|
119
|
+
const extMsg = addMsgFunc(value, previousAnswers);
|
|
120
|
+
if (extMsg) {
|
|
121
|
+
return extMsg; // Extended prompt message is returned first
|
|
122
|
+
}
|
|
123
|
+
// Defer to the original function if a valid message was not returned from the extended version
|
|
124
|
+
return typeof addMsgs === 'function' ? addMsgs(value, previousAnswers) : undefined;
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Extend the existing prompt property function with the one specified in prompt options or add as new.
|
|
129
|
+
*
|
|
130
|
+
* @param question - the question to which the extending function will be applied
|
|
131
|
+
* @param promptOption - prompt options, containing extending functions
|
|
132
|
+
* @param funcName - the question property (function) name to extend
|
|
133
|
+
* @returns the extended question
|
|
134
|
+
*/
|
|
135
|
+
function applyExtensionFunction(question, promptOption, funcName) {
|
|
136
|
+
let extendedFunc;
|
|
137
|
+
if (funcName === 'validate' && promptOption.validate) {
|
|
138
|
+
extendedFunc = extendValidate(question, promptOption.validate);
|
|
139
|
+
}
|
|
140
|
+
if (funcName === 'additionalMessages' && promptOption.additionalMessages) {
|
|
141
|
+
extendedFunc = extendAdditionalMessages(question, promptOption.additionalMessages);
|
|
142
|
+
}
|
|
143
|
+
question = Object.assign(question, { [funcName]: extendedFunc });
|
|
144
|
+
return question;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Updates questions with extensions for specific properties. Only `validate`, `default` and `additionalMessages` are currently supported.
|
|
148
|
+
*
|
|
149
|
+
* @param questions - array of prompts to be extended
|
|
150
|
+
* @param promptOptions - the prompt options possibly containing function extensions
|
|
151
|
+
* @returns - the extended questions
|
|
152
|
+
*/
|
|
153
|
+
function extendWithOptions(questions, promptOptions) {
|
|
154
|
+
questions.forEach((question) => {
|
|
155
|
+
const promptOptKey = question.name;
|
|
156
|
+
const promptOpt = promptOptions[promptOptKey];
|
|
157
|
+
if (promptOpt) {
|
|
158
|
+
const propsToExtend = Object.keys(promptOpt);
|
|
159
|
+
for (const extProp of propsToExtend) {
|
|
160
|
+
if (extProp === 'validate' || extProp === 'additionalMessages') {
|
|
161
|
+
question = applyExtensionFunction(question, promptOpt, extProp);
|
|
162
|
+
}
|
|
163
|
+
// Provided defaults will override built in defaults
|
|
164
|
+
const defaultOverride = promptOptions[promptOptKey].default;
|
|
165
|
+
if (defaultOverride) {
|
|
166
|
+
question.default = defaultOverride;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
return questions;
|
|
172
|
+
}
|
|
173
|
+
exports.extendWithOptions = extendWithOptions;
|
|
174
|
+
/**
|
|
175
|
+
* Will remove prompts from the specified prompts based on prompt options
|
|
176
|
+
* and applicability in the case of CAP projects. Removing prompts is preferable to using `when()`
|
|
177
|
+
* conditions when prompts are used in a UI to prevent continuous re-evaluation.
|
|
178
|
+
*
|
|
179
|
+
* @param prompts Keyed prompts object containing all possible prompts
|
|
180
|
+
* @param promptOptions prompt options
|
|
181
|
+
* @param isCapProject if we are generating into a CAP project certain prompts may be removed
|
|
182
|
+
* @returns the updated questions
|
|
183
|
+
*/
|
|
184
|
+
function hidePrompts(prompts, promptOptions, isCapProject) {
|
|
185
|
+
const questions = [];
|
|
186
|
+
if (promptOptions !== null && promptOptions !== void 0 ? promptOptions : isCapProject) {
|
|
187
|
+
Object.keys(prompts).forEach((key) => {
|
|
188
|
+
var _a;
|
|
189
|
+
const promptKey = key;
|
|
190
|
+
if (!((_a = promptOptions === null || promptOptions === void 0 ? void 0 : promptOptions[promptKey]) === null || _a === void 0 ? void 0 : _a.hide) &&
|
|
191
|
+
// Target directory is determined by the CAP project. `enableEsLint` and `targetFolder` are not available for CAP projects
|
|
192
|
+
!([types_1.promptNames.targetFolder, types_1.promptNames.enableEslint].includes(types_1.promptNames[promptKey]) && isCapProject)) {
|
|
193
|
+
questions.push(prompts[promptKey]);
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
questions.push(...Object.values(prompts));
|
|
199
|
+
}
|
|
200
|
+
return questions;
|
|
201
|
+
}
|
|
202
|
+
exports.hidePrompts = hidePrompts;
|
|
203
|
+
//# sourceMappingURL=prompt-helpers.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type CdsUi5PluginInfo } from '@sap-ux/cap-config-writer';
|
|
2
|
+
import { type UI5Version } from '@sap-ux/ui5-info';
|
|
3
|
+
import type { UI5ApplicationPromptOptions, UI5ApplicationQuestion } from '../types';
|
|
4
|
+
/**
|
|
5
|
+
* Get the prompts that will provide input for UI5 application writing.
|
|
6
|
+
*
|
|
7
|
+
* @param ui5Versions - ui5 versions to prompt for selection
|
|
8
|
+
* @param promptOptions - optional inputs used to pre-populate some prompt choices, default values and other prompting options. See {@link UI5ApplicationPromptOptions}.
|
|
9
|
+
* @param [capCdsInfo] - optional, additional information about CAP projects
|
|
10
|
+
* @param [isYUI] - optional, default is `false`. Changes the behaviour of some validation since YUI does not re-validate prompts that may be inter-dependant.
|
|
11
|
+
* @returns the prompts
|
|
12
|
+
*/
|
|
13
|
+
export declare function getQuestions(ui5Versions: UI5Version[], promptOptions?: UI5ApplicationPromptOptions, capCdsInfo?: CdsUi5PluginInfo, isYUI?: boolean): UI5ApplicationQuestion[];
|
|
14
|
+
//# sourceMappingURL=prompts.d.ts.map
|
|
@@ -0,0 +1,416 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.getQuestions = void 0;
|
|
13
|
+
const inquirer_common_1 = require("@sap-ux/inquirer-common");
|
|
14
|
+
const project_access_1 = require("@sap-ux/project-access");
|
|
15
|
+
const project_input_validator_1 = require("@sap-ux/project-input-validator");
|
|
16
|
+
const ui5_info_1 = require("@sap-ux/ui5-info");
|
|
17
|
+
const i18n_1 = require("../i18n");
|
|
18
|
+
const types_1 = require("../types");
|
|
19
|
+
const prompt_helpers_1 = require("./prompt-helpers");
|
|
20
|
+
const validators_1 = require("./validators");
|
|
21
|
+
/**
|
|
22
|
+
* Get the prompts that will provide input for UI5 application writing.
|
|
23
|
+
*
|
|
24
|
+
* @param ui5Versions - ui5 versions to prompt for selection
|
|
25
|
+
* @param promptOptions - optional inputs used to pre-populate some prompt choices, default values and other prompting options. See {@link UI5ApplicationPromptOptions}.
|
|
26
|
+
* @param [capCdsInfo] - optional, additional information about CAP projects
|
|
27
|
+
* @param [isYUI] - optional, default is `false`. Changes the behaviour of some validation since YUI does not re-validate prompts that may be inter-dependant.
|
|
28
|
+
* @returns the prompts
|
|
29
|
+
*/
|
|
30
|
+
function getQuestions(ui5Versions, promptOptions, capCdsInfo, isYUI = false) {
|
|
31
|
+
var _a, _b;
|
|
32
|
+
// Set shared defaults
|
|
33
|
+
const appName = typeof ((_a = promptOptions === null || promptOptions === void 0 ? void 0 : promptOptions[types_1.promptNames.name]) === null || _a === void 0 ? void 0 : _a.default) === 'string'
|
|
34
|
+
? promptOptions[types_1.promptNames.name].default
|
|
35
|
+
: undefined; // Default functions will be applied later, these replace the existing defaults
|
|
36
|
+
const targetDir = typeof ((_b = promptOptions === null || promptOptions === void 0 ? void 0 : promptOptions[types_1.promptNames.targetFolder]) === null || _b === void 0 ? void 0 : _b.default) === 'string'
|
|
37
|
+
? promptOptions[types_1.promptNames.targetFolder].default // Default functions will be applied later, these replace the existing defaults
|
|
38
|
+
: process.cwd();
|
|
39
|
+
const isCapProject = !!capCdsInfo;
|
|
40
|
+
const keyedPrompts = {
|
|
41
|
+
[types_1.promptNames.name]: getNamePrompt(targetDir, isCapProject, appName, isYUI),
|
|
42
|
+
[types_1.promptNames.title]: getTitlePrompt(),
|
|
43
|
+
[types_1.promptNames.namespace]: getNamespacePrompt(appName),
|
|
44
|
+
[types_1.promptNames.description]: getDescriptionPrompt(),
|
|
45
|
+
[types_1.promptNames.targetFolder]: getTargetFolderPrompt(targetDir),
|
|
46
|
+
[types_1.promptNames.ui5Version]: getUI5VersionPrompt(ui5Versions, promptOptions === null || promptOptions === void 0 ? void 0 : promptOptions.ui5Version),
|
|
47
|
+
[types_1.promptNames.addDeployConfig]: getAddDeployConfigPrompt(targetDir, promptOptions === null || promptOptions === void 0 ? void 0 : promptOptions.addDeployConfig, isCapProject),
|
|
48
|
+
[types_1.promptNames.addFlpConfig]: getAddFlpConfigPrompt(promptOptions === null || promptOptions === void 0 ? void 0 : promptOptions.addFlpConfig),
|
|
49
|
+
[types_1.promptNames.showAdvanced]: getShowAdvancedPrompt(),
|
|
50
|
+
[types_1.promptNames.ui5Theme]: getUI5ThemePrompt(),
|
|
51
|
+
[types_1.promptNames.enableEslint]: getEnableEsLintPrompt(),
|
|
52
|
+
[types_1.promptNames.enableCodeAssist]: getEnableCodeAssistPrompt(),
|
|
53
|
+
[types_1.promptNames.skipAnnotations]: getSkipAnnotationsPrompt(),
|
|
54
|
+
[types_1.promptNames.enableNPMWorkspaces]: getEnableNPMWorkspacesPrompt(capCdsInfo),
|
|
55
|
+
[types_1.promptNames.enableTypeScript]: getEnableTypeScriptPrompt(capCdsInfo)
|
|
56
|
+
};
|
|
57
|
+
// Hide not applicable prompts based on passed options or if this is a CAP project
|
|
58
|
+
let questions = (0, prompt_helpers_1.hidePrompts)(keyedPrompts, promptOptions, isCapProject);
|
|
59
|
+
// Add an additional condition to 'advanced' prompts so they can be shown/hidden at runtime
|
|
60
|
+
applyAdvancedOption(questions, promptOptions);
|
|
61
|
+
// Apply extended `validate`, `additionalMessages` or override `default` prompt properties
|
|
62
|
+
if (promptOptions) {
|
|
63
|
+
questions = (0, prompt_helpers_1.extendWithOptions)(questions, promptOptions);
|
|
64
|
+
}
|
|
65
|
+
return questions;
|
|
66
|
+
}
|
|
67
|
+
exports.getQuestions = getQuestions;
|
|
68
|
+
/**
|
|
69
|
+
* Get the `enableTypeScript` prompt.
|
|
70
|
+
*
|
|
71
|
+
* @param capCdsInfo CDS UI5 plugin information
|
|
72
|
+
* @returns The `enableTypeScript` prompt
|
|
73
|
+
*/
|
|
74
|
+
function getEnableTypeScriptPrompt(capCdsInfo) {
|
|
75
|
+
return {
|
|
76
|
+
when: (answers) => {
|
|
77
|
+
if (capCdsInfo) {
|
|
78
|
+
return capCdsInfo.isCdsUi5PluginEnabled || !!(answers === null || answers === void 0 ? void 0 : answers.enableNPMWorkspaces);
|
|
79
|
+
}
|
|
80
|
+
return true;
|
|
81
|
+
},
|
|
82
|
+
type: 'confirm',
|
|
83
|
+
name: types_1.promptNames.enableTypeScript,
|
|
84
|
+
message: (0, i18n_1.t)('prompts.appEnableTypeScriptMessage'),
|
|
85
|
+
default: false,
|
|
86
|
+
guiOptions: {
|
|
87
|
+
breadcrumb: true
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Get the `enableNPMWorkspaces` prompt.
|
|
93
|
+
*
|
|
94
|
+
* @param capCdsInfo CDS UI5 plugin information
|
|
95
|
+
* @returns The `enableNPMWorkspaces` prompt
|
|
96
|
+
*/
|
|
97
|
+
function getEnableNPMWorkspacesPrompt(capCdsInfo) {
|
|
98
|
+
return {
|
|
99
|
+
when: () => {
|
|
100
|
+
if (capCdsInfo) {
|
|
101
|
+
return capCdsInfo.hasMinCdsVersion && !capCdsInfo.hasCdsUi5Plugin;
|
|
102
|
+
}
|
|
103
|
+
return false;
|
|
104
|
+
},
|
|
105
|
+
type: 'confirm',
|
|
106
|
+
name: types_1.promptNames.enableNPMWorkspaces,
|
|
107
|
+
message: (0, i18n_1.t)('prompts.appEnableNpmWorkspacesMessage'),
|
|
108
|
+
default: false,
|
|
109
|
+
guiOptions: {
|
|
110
|
+
breadcrumb: (0, i18n_1.t)('prompts.appEnableNpmWorkspacesBreadcrumb')
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Get the `skipAnnotations` prompt. Skipping annotation generation can be useful for CAP projects
|
|
116
|
+
* where annotations may have been already created along with the service.
|
|
117
|
+
*
|
|
118
|
+
* @returns The `skipAnnotations` prompt
|
|
119
|
+
*/
|
|
120
|
+
function getSkipAnnotationsPrompt() {
|
|
121
|
+
return {
|
|
122
|
+
type: 'confirm',
|
|
123
|
+
name: types_1.promptNames.skipAnnotations,
|
|
124
|
+
message: (0, i18n_1.t)('prompts.appSkipAnnotationsMessage'),
|
|
125
|
+
default: false,
|
|
126
|
+
guiOptions: {
|
|
127
|
+
breadcrumb: (0, i18n_1.t)('prompts.appSkipAnnotationsBreadcrumb')
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Get the `enableCodeAssist` prompt.
|
|
133
|
+
*
|
|
134
|
+
* @returns The `enableCodeAssist` prompt
|
|
135
|
+
*/
|
|
136
|
+
function getEnableCodeAssistPrompt() {
|
|
137
|
+
return {
|
|
138
|
+
when: (answers) => (0, prompt_helpers_1.isVersionIncluded)((answers === null || answers === void 0 ? void 0 : answers.ui5Version) || ui5_info_1.defaultVersion, ui5_info_1.minUi5VersionSupportingCodeAssist),
|
|
139
|
+
type: 'confirm',
|
|
140
|
+
name: types_1.promptNames.enableCodeAssist,
|
|
141
|
+
message: (0, i18n_1.t)('prompts.appEnableCodeAssistMessage'),
|
|
142
|
+
default: false,
|
|
143
|
+
guiOptions: {
|
|
144
|
+
breadcrumb: (0, i18n_1.t)('prompts.appEnableCodeAssistBreadcrumb')
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Get the `enableEslint` prompt.
|
|
150
|
+
*
|
|
151
|
+
* @returns The `enableEslint` prompt
|
|
152
|
+
*/
|
|
153
|
+
function getEnableEsLintPrompt() {
|
|
154
|
+
return {
|
|
155
|
+
type: 'confirm',
|
|
156
|
+
name: types_1.promptNames.enableEslint,
|
|
157
|
+
message: (0, i18n_1.t)('prompts.appEnableEslintMessage'),
|
|
158
|
+
default: false,
|
|
159
|
+
guiOptions: {
|
|
160
|
+
breadcrumb: (0, i18n_1.t)('prompts.appEnableEslintBreadcrumb')
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Get the `ui5Theme` prompt.
|
|
166
|
+
*
|
|
167
|
+
* @returns The `ui5Theme` prompt
|
|
168
|
+
*/
|
|
169
|
+
function getUI5ThemePrompt() {
|
|
170
|
+
return {
|
|
171
|
+
type: 'list',
|
|
172
|
+
name: types_1.promptNames.ui5Theme,
|
|
173
|
+
message: (0, i18n_1.t)('prompts.appUi5ThemeMessage'),
|
|
174
|
+
guiOptions: {
|
|
175
|
+
applyDefaultWhenDirty: true,
|
|
176
|
+
breadcrumb: true
|
|
177
|
+
},
|
|
178
|
+
choices: ({ ui5Version = ui5_info_1.defaultVersion }) => (0, inquirer_common_1.getUI5ThemesChoices)(ui5Version),
|
|
179
|
+
default: ({ ui5Theme, ui5Version }) => {
|
|
180
|
+
if (!ui5Theme) {
|
|
181
|
+
ui5Theme = (0, ui5_info_1.getDefaultUI5Theme)(ui5Version);
|
|
182
|
+
}
|
|
183
|
+
return ui5Theme;
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Get the `showAdvanced` prompt.
|
|
189
|
+
*
|
|
190
|
+
* @returns The `showAdvanced` prompt
|
|
191
|
+
*/
|
|
192
|
+
function getShowAdvancedPrompt() {
|
|
193
|
+
return {
|
|
194
|
+
type: 'confirm',
|
|
195
|
+
name: 'showAdvanced',
|
|
196
|
+
message: (0, i18n_1.t)('prompts.appShowAdvancedOptionsMessage'),
|
|
197
|
+
guiOptions: {
|
|
198
|
+
hint: (0, i18n_1.t)('prompts.appShowAdvancedOptionsHint')
|
|
199
|
+
},
|
|
200
|
+
default: false
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Get the `addFlpConfig` prompt.
|
|
205
|
+
*
|
|
206
|
+
* @param addFlpConfigOptions the
|
|
207
|
+
* @returns The `addFlpConfig` prompt
|
|
208
|
+
*/
|
|
209
|
+
function getAddFlpConfigPrompt(addFlpConfigOptions) {
|
|
210
|
+
return {
|
|
211
|
+
type: 'confirm',
|
|
212
|
+
name: types_1.promptNames.addFlpConfig,
|
|
213
|
+
guiOptions: {
|
|
214
|
+
breadcrumb: (0, i18n_1.t)('prompts.appAddFlpConfigBreadcrumb')
|
|
215
|
+
},
|
|
216
|
+
message: () => (0, i18n_1.t)('prompts.appAddFlpConfigMessage'),
|
|
217
|
+
default: false,
|
|
218
|
+
validate: (addFlpConfig) => {
|
|
219
|
+
if (typeof (addFlpConfigOptions === null || addFlpConfigOptions === void 0 ? void 0 : addFlpConfigOptions.validatorCallback) === 'function') {
|
|
220
|
+
addFlpConfigOptions.validatorCallback(addFlpConfig, types_1.promptNames.addFlpConfig);
|
|
221
|
+
}
|
|
222
|
+
return true;
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Gets the `addDeployConfig` prompt.
|
|
228
|
+
*
|
|
229
|
+
* @param targetDir determines the path to search for `mta.yaml`
|
|
230
|
+
* @param addDeployConfigOptions add deploy configuration prompt options
|
|
231
|
+
* @param isCapProject is this a CAP project
|
|
232
|
+
* @returns the `addDeployConfig` prompt
|
|
233
|
+
*/
|
|
234
|
+
function getAddDeployConfigPrompt(targetDir, addDeployConfigOptions, isCapProject = false) {
|
|
235
|
+
let mtaPath; // cache mta path discovery
|
|
236
|
+
return {
|
|
237
|
+
type: 'confirm',
|
|
238
|
+
name: types_1.promptNames.addDeployConfig,
|
|
239
|
+
guiOptions: {
|
|
240
|
+
breadcrumb: (0, i18n_1.t)('prompts.appAddDeployConfigBreadcrumb')
|
|
241
|
+
},
|
|
242
|
+
// If the target directory is a CAP project then only offer `addDeployConfig (addToMta)` if an mta file is found
|
|
243
|
+
when: (answers) => __awaiter(this, void 0, void 0, function* () {
|
|
244
|
+
var _a;
|
|
245
|
+
mtaPath = (_a = (yield (0, project_access_1.getMtaPath)((answers === null || answers === void 0 ? void 0 : answers.targetFolder) || targetDir))) === null || _a === void 0 ? void 0 : _a.mtaPath;
|
|
246
|
+
return !!(mtaPath && isCapProject) || !isCapProject;
|
|
247
|
+
}),
|
|
248
|
+
message: () => {
|
|
249
|
+
return mtaPath
|
|
250
|
+
? (0, i18n_1.t)('prompts.appAddDeployConfigToMtaMessage', {
|
|
251
|
+
path: mtaPath,
|
|
252
|
+
interpolation: { escapeValue: false }
|
|
253
|
+
})
|
|
254
|
+
: (0, i18n_1.t)('prompts.appAddDeployConfigMessage');
|
|
255
|
+
},
|
|
256
|
+
default: () => __awaiter(this, void 0, void 0, function* () { return !!mtaPath; }),
|
|
257
|
+
validate: (addDeployConfig) => {
|
|
258
|
+
if (typeof (addDeployConfigOptions === null || addDeployConfigOptions === void 0 ? void 0 : addDeployConfigOptions.validatorCallback) === 'function') {
|
|
259
|
+
addDeployConfigOptions.validatorCallback(addDeployConfig, types_1.promptNames.addDeployConfig);
|
|
260
|
+
}
|
|
261
|
+
return true;
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Get the `ui5Version` prompt.
|
|
267
|
+
*
|
|
268
|
+
* @param ui5Versions the UI5 versions that will be available for selection
|
|
269
|
+
* @param ui5VersionPromptOptions UI5 version prompt options
|
|
270
|
+
* @returns the `ui5Version` prompt
|
|
271
|
+
*/
|
|
272
|
+
function getUI5VersionPrompt(ui5Versions = [], ui5VersionPromptOptions) {
|
|
273
|
+
const ui5VersionChoices = (0, inquirer_common_1.ui5VersionsGrouped)(ui5Versions, ui5VersionPromptOptions === null || ui5VersionPromptOptions === void 0 ? void 0 : ui5VersionPromptOptions.includeSeparators, ui5VersionPromptOptions === null || ui5VersionPromptOptions === void 0 ? void 0 : ui5VersionPromptOptions.defaultChoice);
|
|
274
|
+
return {
|
|
275
|
+
when: () => !!ui5VersionChoices,
|
|
276
|
+
type: (ui5VersionPromptOptions === null || ui5VersionPromptOptions === void 0 ? void 0 : ui5VersionPromptOptions.useAutocomplete) ? 'autocomplete' : 'list',
|
|
277
|
+
name: types_1.promptNames.ui5Version,
|
|
278
|
+
guiOptions: {
|
|
279
|
+
hint: (0, i18n_1.t)('prompts.appUi5VersionTooltip'),
|
|
280
|
+
breadcrumb: (0, i18n_1.t)('prompts.appUi5VersionBreadcrumb')
|
|
281
|
+
},
|
|
282
|
+
choices: () => ui5VersionChoices,
|
|
283
|
+
source: (prevAnswers, input) => (0, inquirer_common_1.searchChoices)(input, ui5VersionChoices),
|
|
284
|
+
message: (0, i18n_1.t)('prompts.appUi5VersionMessage'),
|
|
285
|
+
default: () => {
|
|
286
|
+
var _a, _b, _c;
|
|
287
|
+
// Set the default to be the passed value or the default as defined by ui5 version service
|
|
288
|
+
return ((_b = (_a = ui5VersionPromptOptions === null || ui5VersionPromptOptions === void 0 ? void 0 : ui5VersionPromptOptions.defaultChoice) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : (_c = ui5Versions.find((ui5Ver) => ui5Ver.default && ui5Ver.version)) === null || _c === void 0 ? void 0 : _c.version);
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Gets the `targetFolder` prompt.
|
|
294
|
+
*
|
|
295
|
+
* @param targetDir provides a default value for the target folder path
|
|
296
|
+
* @returns the `targetFolder` prompt
|
|
297
|
+
*/
|
|
298
|
+
function getTargetFolderPrompt(targetDir) {
|
|
299
|
+
return {
|
|
300
|
+
type: 'input',
|
|
301
|
+
name: types_1.promptNames.targetFolder,
|
|
302
|
+
message: (0, i18n_1.t)('prompts.appFolderPathMessage'),
|
|
303
|
+
guiType: 'folder-browser',
|
|
304
|
+
guiOptions: {
|
|
305
|
+
applyDefaultWhenDirty: true,
|
|
306
|
+
mandatory: true,
|
|
307
|
+
breadcrumb: (0, i18n_1.t)('prompts.appFolderPathBreadcrumb')
|
|
308
|
+
},
|
|
309
|
+
default: (answers) => answers.targetFolder || targetDir,
|
|
310
|
+
validate: (target, { name = '' }) => {
|
|
311
|
+
if (name.length > 2) {
|
|
312
|
+
return (0, project_input_validator_1.validateProjectFolder)(target, name);
|
|
313
|
+
}
|
|
314
|
+
return false;
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Gets the `description` prompt.
|
|
320
|
+
*
|
|
321
|
+
* @returns the `description` prompt
|
|
322
|
+
*/
|
|
323
|
+
function getDescriptionPrompt() {
|
|
324
|
+
return {
|
|
325
|
+
type: 'input',
|
|
326
|
+
name: types_1.promptNames.description,
|
|
327
|
+
guiOptions: {
|
|
328
|
+
hint: (0, i18n_1.t)('prompts.appDescTooltip'),
|
|
329
|
+
breadcrumb: true
|
|
330
|
+
},
|
|
331
|
+
message: (0, i18n_1.t)('prompts.appDescMessage'),
|
|
332
|
+
default: (answers) => answers.description || (0, i18n_1.t)('prompts.appDescDefault')
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* Gets the `namespace` prompt.
|
|
337
|
+
*
|
|
338
|
+
* @param appName the application is used as part of namespace validation to determine max combined length
|
|
339
|
+
* @returns the `namespace` prompt
|
|
340
|
+
*/
|
|
341
|
+
function getNamespacePrompt(appName) {
|
|
342
|
+
return {
|
|
343
|
+
type: 'input',
|
|
344
|
+
guiOptions: {
|
|
345
|
+
hint: (0, i18n_1.t)('prompts.appNamespaceTooltip'),
|
|
346
|
+
breadcrumb: true
|
|
347
|
+
},
|
|
348
|
+
name: types_1.promptNames.namespace,
|
|
349
|
+
message: (0, i18n_1.t)('prompts.appNamespaceMessage'),
|
|
350
|
+
default: (answers) => { var _a; return (_a = answers.namespace) !== null && _a !== void 0 ? _a : ''; },
|
|
351
|
+
validate: (namespace, answers) => {
|
|
352
|
+
if (namespace) {
|
|
353
|
+
return (0, project_input_validator_1.validateNamespace)(namespace, answers.name || appName);
|
|
354
|
+
}
|
|
355
|
+
return true;
|
|
356
|
+
}
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* Gets the `title` prompt.
|
|
361
|
+
*
|
|
362
|
+
* @returns the `title` prompt
|
|
363
|
+
*/
|
|
364
|
+
function getTitlePrompt() {
|
|
365
|
+
return {
|
|
366
|
+
type: 'input',
|
|
367
|
+
guiOptions: {
|
|
368
|
+
hint: (0, i18n_1.t)('prompts.appTitleTooltip'),
|
|
369
|
+
breadcrumb: true
|
|
370
|
+
},
|
|
371
|
+
name: types_1.promptNames.title,
|
|
372
|
+
message: (0, i18n_1.t)('prompts.appTitleMessage'),
|
|
373
|
+
default: (answers) => answers.title || (0, i18n_1.t)('prompts.appTitleDefault')
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Gets the `name` prompt.
|
|
378
|
+
*
|
|
379
|
+
* @param targetDir the directory path to search for exiting apps with the same name
|
|
380
|
+
* @param isCapProject if the app is to be generated in a CAP project ensure that the name is unique within the CAP apps folder path
|
|
381
|
+
* @param appName the default app name, if not provided a default app name will be suggested
|
|
382
|
+
* @param isYUI If true, do not use `targetFolder` value when validating the name for existence, since YUI will not re-validate when `targetFolder` is updated.
|
|
383
|
+
* @returns the UI5 application `name` prompt
|
|
384
|
+
*/
|
|
385
|
+
function getNamePrompt(targetDir, isCapProject, appName, isYUI) {
|
|
386
|
+
return {
|
|
387
|
+
type: 'input',
|
|
388
|
+
guiOptions: {
|
|
389
|
+
applyDefaultWhenDirty: true,
|
|
390
|
+
hint: (0, i18n_1.t)('prompts.appNameTooltip'),
|
|
391
|
+
mandatory: true,
|
|
392
|
+
breadcrumb: true
|
|
393
|
+
},
|
|
394
|
+
name: types_1.promptNames.name,
|
|
395
|
+
message: (0, i18n_1.t)('prompts.appNameMessage'),
|
|
396
|
+
default: (answers) => answers.name || appName || (0, prompt_helpers_1.defaultAppName)(targetDir),
|
|
397
|
+
validate: (name, answers) => {
|
|
398
|
+
if (!isYUI || isCapProject) {
|
|
399
|
+
return (0, validators_1.validateAppName)(name, answers.targetFolder || targetDir);
|
|
400
|
+
}
|
|
401
|
+
else {
|
|
402
|
+
return (0, project_input_validator_1.validateModuleName)(name);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
/**
|
|
408
|
+
* Applies the advanced grouping option which will hide the specified prompts behind and advanced options prompt.
|
|
409
|
+
*
|
|
410
|
+
* @param questions the questions to which the advanced option condition may be applied
|
|
411
|
+
* @param promptOptions the prompt options which specify which prompts should be grouped as advanced options
|
|
412
|
+
*/
|
|
413
|
+
function applyAdvancedOption(questions, promptOptions) {
|
|
414
|
+
(0, prompt_helpers_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; });
|
|
415
|
+
}
|
|
416
|
+
//# sourceMappingURL=prompts.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns true (valid) if the specified projectName is a valid module name
|
|
3
|
+
* and if an application folder (directory) at the specified path does not exist.
|
|
4
|
+
*
|
|
5
|
+
* @param appName the application directory name that would contain a UI5 application
|
|
6
|
+
* @param targetDir the directory path where the directory named `appName` would be created
|
|
7
|
+
* @returns true, if valid, or a string message indicating the reason why the input is invalid
|
|
8
|
+
*/
|
|
9
|
+
export declare function validateAppName(appName: string, targetDir: string): boolean | string;
|
|
10
|
+
//# sourceMappingURL=validators.d.ts.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateAppName = void 0;
|
|
4
|
+
const project_input_validator_1 = require("@sap-ux/project-input-validator");
|
|
5
|
+
const prompt_helpers_1 = require("./prompt-helpers");
|
|
6
|
+
const i18n_1 = require("../i18n");
|
|
7
|
+
/**
|
|
8
|
+
* Returns true (valid) if the specified projectName is a valid module name
|
|
9
|
+
* and if an application folder (directory) at the specified path does not exist.
|
|
10
|
+
*
|
|
11
|
+
* @param appName the application directory name that would contain a UI5 application
|
|
12
|
+
* @param targetDir the directory path where the directory named `appName` would be created
|
|
13
|
+
* @returns true, if valid, or a string message indicating the reason why the input is invalid
|
|
14
|
+
*/
|
|
15
|
+
function validateAppName(appName, targetDir) {
|
|
16
|
+
const nameValidationResult = (0, project_input_validator_1.validateModuleName)(appName);
|
|
17
|
+
if (nameValidationResult !== true) {
|
|
18
|
+
return nameValidationResult;
|
|
19
|
+
}
|
|
20
|
+
const existing = (0, prompt_helpers_1.appPathExists)(appName, targetDir);
|
|
21
|
+
if (existing) {
|
|
22
|
+
return (0, i18n_1.t)('validators.appFolderExistsAtPath', { path: targetDir });
|
|
23
|
+
}
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
exports.validateAppName = validateAppName;
|
|
27
|
+
//# sourceMappingURL=validators.js.map
|