@sap-ux/create 0.5.102 → 0.5.104

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.
@@ -27,16 +27,18 @@ function addGenerateAdaptationProjectCommand(cmd) {
27
27
  cmd.command('adaptation-project [path]')
28
28
  .option('-n, --skip-install', 'skip npm install step')
29
29
  .option('-s, --simulate', 'simulate only do not write or install')
30
+ .option('-y, --yes', 'use default values for all prompts')
30
31
  .option('--id [id]', 'id of the adaptation project')
31
32
  .option('--reference [reference]', 'id of the original application')
32
33
  .option('--url [url]', 'url pointing to the target system containing the original app')
34
+ .option('--ignoreCertErrors', 'ignore certificate errors when connecting to the target system')
33
35
  .option('--ft', 'enable the Fiori tools for the generated project')
34
36
  .option('--package [package]', 'ABAP package to be used for deployments')
35
37
  .option('--transport [transport]', 'ABAP transport to be used for deployments')
36
38
  .action((path, options) => __awaiter(this, void 0, void 0, function* () {
37
39
  console.log(`\nThe generation of adaptation projects outside of SAP Business Application Studio is currently ${chalk_1.default.bold('experimental')}.`);
38
40
  console.log('Please report any issues or feedback at https://github.com/SAP/open-ux-tools/issues/new/choose.\n');
39
- yield generateAdaptationProject(path, Object.assign({}, options), !!options.simulate, !!options.skipInstall);
41
+ yield generateAdaptationProject(path, Object.assign({}, options), !!options.yes, !!options.simulate, !!options.skipInstall);
40
42
  }));
41
43
  }
42
44
  exports.addGenerateAdaptationProjectCommand = addGenerateAdaptationProjectCommand;
@@ -45,40 +47,22 @@ exports.addGenerateAdaptationProjectCommand = addGenerateAdaptationProjectComman
45
47
  *
46
48
  * @param basePath target folder of the new project
47
49
  * @param defaults optional defaults
50
+ * @param useDefaults if set to true, then default values are used for all prompts and the prompting is skipped
48
51
  * @param simulate if set to true, then no files will be written to the filesystem
49
52
  * @param skipInstall if set to true then `npm i` is not executed in the new project
50
53
  */
51
- function generateAdaptationProject(basePath, defaults, simulate, skipInstall) {
54
+ function generateAdaptationProject(basePath, defaults, useDefaults, simulate, skipInstall) {
52
55
  var _a;
53
56
  return __awaiter(this, void 0, void 0, function* () {
54
57
  const logger = (0, tracing_1.getLogger)();
55
58
  try {
56
59
  logger.debug(`Called generate adaptation-project for path '${basePath}', skip install is '${skipInstall}'`);
57
- let config;
58
- if (defaults.id && defaults.reference && defaults.url) {
60
+ if (defaults.url) {
59
61
  const url = new URL(defaults.url);
60
- config = {
61
- app: {
62
- id: defaults.id,
63
- reference: defaults.reference,
64
- layer: 'CUSTOMER_BASE'
65
- },
66
- target: {
67
- url: url.origin,
68
- client: (_a = url.searchParams.get('sap-client')) !== null && _a !== void 0 ? _a : undefined
69
- },
70
- deploy: {
71
- package: defaults.package ? defaults.package.toUpperCase() : '$TMP',
72
- transport: defaults.transport ? defaults.transport.toUpperCase() : undefined
73
- },
74
- options: {
75
- fioriTools: defaults.ft
76
- }
77
- };
78
- }
79
- else {
80
- config = yield (0, adp_tooling_1.promptGeneratorInput)(defaults, logger);
62
+ defaults.url = url.origin;
63
+ defaults.client = (_a = url.searchParams.get('sap-client')) !== null && _a !== void 0 ? _a : undefined;
81
64
  }
65
+ const config = useDefaults ? createConfigFromDefaults(defaults) : yield (0, adp_tooling_1.promptGeneratorInput)(defaults, logger);
82
66
  if (!basePath) {
83
67
  basePath = (0, path_1.join)(process.cwd(), config.app.id);
84
68
  }
@@ -99,4 +83,35 @@ function generateAdaptationProject(basePath, defaults, simulate, skipInstall) {
99
83
  }
100
84
  });
101
85
  }
86
+ /**
87
+ * Create a writer config based on the given defaults.
88
+ *
89
+ * @param defaults default values provided via command line
90
+ * @returns writer config
91
+ */
92
+ function createConfigFromDefaults(defaults) {
93
+ if (defaults.id && defaults.reference && defaults.url) {
94
+ return {
95
+ app: {
96
+ id: defaults.id,
97
+ reference: defaults.reference,
98
+ layer: 'CUSTOMER_BASE'
99
+ },
100
+ target: {
101
+ url: defaults.url,
102
+ client: defaults.client
103
+ },
104
+ deploy: {
105
+ package: defaults.package ? defaults.package.toUpperCase() : '$TMP',
106
+ transport: defaults.transport ? defaults.transport.toUpperCase() : undefined
107
+ },
108
+ options: {
109
+ fioriTools: defaults.ft
110
+ }
111
+ };
112
+ }
113
+ else {
114
+ throw new Error('Missing required parameters. Please provide --id, --reference and --url.');
115
+ }
116
+ }
102
117
  //# sourceMappingURL=adaptation-project.js.map
@@ -1,3 +1,4 @@
1
+ export { promptYUIQuestions } from './prompts';
1
2
  /**
2
3
  * Run npm install command.
3
4
  *
@@ -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.102",
4
+ "version": "0.5.104",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/SAP/open-ux-tools.git",
@@ -28,9 +28,9 @@
28
28
  "commander": "9.4.0",
29
29
  "diff": "5.1.0",
30
30
  "prompts": "2.4.2",
31
- "@sap-ux/adp-tooling": "0.10.23",
32
- "@sap-ux/app-config-writer": "0.3.74",
31
+ "@sap-ux/adp-tooling": "0.11.0",
33
32
  "@sap-ux/cap-config-writer": "0.3.4",
33
+ "@sap-ux/app-config-writer": "0.3.74",
34
34
  "@sap-ux/cards-editor-config-writer": "0.3.6",
35
35
  "@sap-ux/logger": "0.5.1",
36
36
  "@sap-ux/mockserver-config-writer": "0.5.5",
@@ -38,9 +38,11 @@
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": {