@sap-ux/create 0.5.103 → 0.5.105
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/common/index.d.ts +1 -0
- package/dist/common/index.js +3 -1
- package/dist/common/prompts.d.ts +22 -0
- package/dist/common/prompts.js +127 -0
- package/package.json +9 -7
package/dist/common/index.d.ts
CHANGED
package/dist/common/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.runNpmInstallCommand = void 0;
|
|
3
|
+
exports.runNpmInstallCommand = exports.promptYUIQuestions = void 0;
|
|
4
4
|
const child_process_1 = require("child_process");
|
|
5
|
+
var prompts_1 = require("./prompts");
|
|
6
|
+
Object.defineProperty(exports, "promptYUIQuestions", { enumerable: true, get: function () { return prompts_1.promptYUIQuestions; } });
|
|
5
7
|
/**
|
|
6
8
|
* Run npm install command.
|
|
7
9
|
*
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { PromptObject } from 'prompts';
|
|
2
|
+
import type { YUIQuestion } from '@sap-ux/inquirer-common';
|
|
3
|
+
import type { Answers } from 'inquirer';
|
|
4
|
+
/**
|
|
5
|
+
* Converts a YUI question to a simple prompts question.
|
|
6
|
+
*
|
|
7
|
+
* @param question YUI question to be converted
|
|
8
|
+
* @param answers previously given answers
|
|
9
|
+
* @returns question converted to prompts question
|
|
10
|
+
*/
|
|
11
|
+
export declare function convertQuestion<T extends Answers>(question: YUIQuestion<T> & {
|
|
12
|
+
choices?: unknown;
|
|
13
|
+
}, answers: T): Promise<PromptObject>;
|
|
14
|
+
/**
|
|
15
|
+
* Prompt a list of YeomanUI questions with the simple prompts module.
|
|
16
|
+
*
|
|
17
|
+
* @param questions list of questions
|
|
18
|
+
* @param useDefaults - if true, the default values are used for all prompts
|
|
19
|
+
* @returns the answers to the questions
|
|
20
|
+
*/
|
|
21
|
+
export declare function promptYUIQuestions<T extends Answers>(questions: YUIQuestion<T>[], useDefaults: boolean): Promise<T>;
|
|
22
|
+
//# sourceMappingURL=prompts.d.ts.map
|
|
@@ -0,0 +1,127 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.promptYUIQuestions = exports.convertQuestion = void 0;
|
|
16
|
+
const prompts_1 = __importDefault(require("prompts"));
|
|
17
|
+
const tracing_1 = require("../tracing");
|
|
18
|
+
/**
|
|
19
|
+
* Checks if a property is a function.
|
|
20
|
+
*
|
|
21
|
+
* @param property property to be checked
|
|
22
|
+
* @returns true if the property is a function
|
|
23
|
+
*/
|
|
24
|
+
function isFunction(property) {
|
|
25
|
+
return typeof property === 'function';
|
|
26
|
+
}
|
|
27
|
+
const QUESTION_TYPE_MAP = {
|
|
28
|
+
input: 'text',
|
|
29
|
+
list: 'autocomplete',
|
|
30
|
+
checkbox: 'multiselect'
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Enhances the new prompt with the choices from the original list question.
|
|
34
|
+
*
|
|
35
|
+
* @param listQuestion original list question
|
|
36
|
+
* @param prompt converted prompt
|
|
37
|
+
* @param answers previously given answers
|
|
38
|
+
*/
|
|
39
|
+
function enhanceListQuestion(listQuestion, prompt, answers) {
|
|
40
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
const choices = (isFunction(listQuestion.choices) ? yield listQuestion.choices(answers) : listQuestion.choices);
|
|
42
|
+
const mapppedChoices = choices.map((choice) => ({
|
|
43
|
+
title: typeof choice === 'object' ? choice.name : `${choice}`,
|
|
44
|
+
value: typeof choice === 'object' ? choice.value : choice
|
|
45
|
+
}));
|
|
46
|
+
const initialValue = prompt.initial();
|
|
47
|
+
prompt.choices = mapppedChoices;
|
|
48
|
+
prompt.initial = () => mapppedChoices[initialValue]
|
|
49
|
+
? initialValue
|
|
50
|
+
: mapppedChoices.findIndex((choice) => choice.value === initialValue);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Converts a YUI question to a simple prompts question.
|
|
55
|
+
*
|
|
56
|
+
* @param question YUI question to be converted
|
|
57
|
+
* @param answers previously given answers
|
|
58
|
+
* @returns question converted to prompts question
|
|
59
|
+
*/
|
|
60
|
+
function convertQuestion(question, answers) {
|
|
61
|
+
var _a, _b;
|
|
62
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
63
|
+
const prompt = {
|
|
64
|
+
type: (_b = QUESTION_TYPE_MAP[(_a = question.type) !== null && _a !== void 0 ? _a : 'input']) !== null && _b !== void 0 ? _b : question.type,
|
|
65
|
+
name: question.name,
|
|
66
|
+
message: isFunction(question.message) ? yield question.message(answers) : yield question.message,
|
|
67
|
+
validate: (value) => __awaiter(this, void 0, void 0, function* () { var _c; return isFunction(question.validate) ? yield question.validate(value, answers) : (_c = question.validate) !== null && _c !== void 0 ? _c : true; }),
|
|
68
|
+
initial: () => (isFunction(question.default) ? question.default(answers) : question.default)
|
|
69
|
+
};
|
|
70
|
+
if (question.choices) {
|
|
71
|
+
yield enhanceListQuestion(question, prompt, answers);
|
|
72
|
+
}
|
|
73
|
+
return prompt;
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
exports.convertQuestion = convertQuestion;
|
|
77
|
+
/**
|
|
78
|
+
* Prompt a list of YeomanUI questions with the simple prompts module.
|
|
79
|
+
*
|
|
80
|
+
* @param questions list of questions
|
|
81
|
+
* @param useDefaults - if true, the default values are used for all prompts
|
|
82
|
+
* @returns the answers to the questions
|
|
83
|
+
*/
|
|
84
|
+
function promptYUIQuestions(questions, useDefaults) {
|
|
85
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
86
|
+
const answers = {};
|
|
87
|
+
for (const question of questions) {
|
|
88
|
+
if (isFunction(question.when) ? question.when(answers) : question.when !== false) {
|
|
89
|
+
if (useDefaults) {
|
|
90
|
+
answers[question.name] = isFunction(question.default) ? question.default(answers) : question.default;
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
answers[question.name] = yield promptSingleQuestion(answers, question);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return answers;
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
exports.promptYUIQuestions = promptYUIQuestions;
|
|
101
|
+
/**
|
|
102
|
+
* Prompt a single YeomanUI question with the simple prompts module.
|
|
103
|
+
*
|
|
104
|
+
* @param answers previously given answers
|
|
105
|
+
* @param question question to be prompted
|
|
106
|
+
* @returns a promise with the answer of the question
|
|
107
|
+
*/
|
|
108
|
+
function promptSingleQuestion(answers, question) {
|
|
109
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
110
|
+
const q = yield convertQuestion(question, answers);
|
|
111
|
+
const answer = yield (0, prompts_1.default)(q, {
|
|
112
|
+
onCancel: () => {
|
|
113
|
+
throw new Error('User canceled the prompt');
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
// prompts does not handle validation for autocomplete out of the box
|
|
117
|
+
if (q.type === 'autocomplete') {
|
|
118
|
+
const valid = yield q.validate(answer[question.name]);
|
|
119
|
+
if (valid !== true) {
|
|
120
|
+
(0, tracing_1.getLogger)().warn(valid);
|
|
121
|
+
return promptSingleQuestion(answers, question);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return answer[question.name];
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=prompts.js.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sap-ux/create",
|
|
3
3
|
"description": "SAP Fiori tools module to add or remove features",
|
|
4
|
-
"version": "0.5.
|
|
4
|
+
"version": "0.5.105",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "https://github.com/SAP/open-ux-tools.git",
|
|
@@ -28,19 +28,21 @@
|
|
|
28
28
|
"commander": "9.4.0",
|
|
29
29
|
"diff": "5.1.0",
|
|
30
30
|
"prompts": "2.4.2",
|
|
31
|
-
"@sap-ux/adp-tooling": "0.11.
|
|
32
|
-
"@sap-ux/app-config-writer": "0.3.
|
|
33
|
-
"@sap-ux/cap-config-writer": "0.3.
|
|
34
|
-
"@sap-ux/cards-editor-config-writer": "0.3.
|
|
31
|
+
"@sap-ux/adp-tooling": "0.11.1",
|
|
32
|
+
"@sap-ux/app-config-writer": "0.3.75",
|
|
33
|
+
"@sap-ux/cap-config-writer": "0.3.5",
|
|
34
|
+
"@sap-ux/cards-editor-config-writer": "0.3.7",
|
|
35
35
|
"@sap-ux/logger": "0.5.1",
|
|
36
|
-
"@sap-ux/mockserver-config-writer": "0.5.
|
|
37
|
-
"@sap-ux/project-access": "1.22.
|
|
36
|
+
"@sap-ux/mockserver-config-writer": "0.5.6",
|
|
37
|
+
"@sap-ux/project-access": "1.22.1"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@types/diff": "5.0.9",
|
|
41
|
+
"@types/inquirer": "8.2.6",
|
|
41
42
|
"@types/mem-fs": "1.1.2",
|
|
42
43
|
"@types/mem-fs-editor": "7.0.1",
|
|
43
44
|
"@types/prompts": "2.4.4",
|
|
45
|
+
"@sap-ux/inquirer-common": "0.3.0",
|
|
44
46
|
"@sap-ux/store": "0.5.0"
|
|
45
47
|
},
|
|
46
48
|
"scripts": {
|