@sap-ux/adp-flp-config-sub-generator 0.0.2

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 ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,20 @@
1
+ # @sap-ux/adp-flp-config-sub-generator
2
+
3
+ ## Features
4
+
5
+ The SAP Adaptation Project FLP sub-generator enables users to create a FLP configuration for an Adaptation Project.
6
+
7
+ ## Installation
8
+
9
+ The SAP Adaptation Project FLP Configuration sub-generator is included in the [@sap/generator-fiori](https://www.npmjs.com/package/@sap/generator-fiori) generator and cannot be used independently. Additionally, it requires the [SAP Fiori Tools Extension](https://marketplace.visualstudio.com/items?itemName=SAPSE.sap-ux-fiori-tools-extension-pack) pack from the VSCode marketplace.
10
+
11
+
12
+ ## Launch the SAP Reference Library sub-generator
13
+
14
+ Open the Command Palette in MS Visual Studio Code ( CMD/CTRL + Shift + P ) and execute the Fiori: Adaptation Project FLP configuration command.
15
+
16
+
17
+ ## Keywords
18
+ SAP Fiori Elements
19
+ Yeoman
20
+ Generator
@@ -0,0 +1,94 @@
1
+ import type { FlpConfigOptions } from './types';
2
+ import Generator from 'yeoman-generator';
3
+ /**
4
+ * Generator for adding a FLP configuration to an adaptation project.
5
+ *
6
+ * @extends Generator
7
+ */
8
+ export default class extends Generator {
9
+ setPromptsCallback: (fn: object) => void;
10
+ private prompts;
11
+ private readonly launchAsSubGen;
12
+ private readonly appWizard;
13
+ private readonly vscode;
14
+ private readonly toolsLogger;
15
+ private readonly projectRootPath;
16
+ private manifest;
17
+ private answers;
18
+ private logger;
19
+ private authenticationRequired;
20
+ private abort;
21
+ private configuredSystem;
22
+ private ui5Yaml;
23
+ private credentials;
24
+ /**
25
+ * Creates an instance of the generator.
26
+ *
27
+ * @param {string | string[]} args - The arguments passed to the generator.
28
+ * @param {FlpConfigOptions} opts - The options for the generator.
29
+ */
30
+ constructor(args: string | string[], opts: FlpConfigOptions);
31
+ initializing(): Promise<void>;
32
+ prompting(): Promise<void>;
33
+ writing(): Promise<void>;
34
+ end(): void;
35
+ /**
36
+ * Retrieves the merged manifest for the project.
37
+ *
38
+ * @returns {Promise<Manifest>} The project manifest.
39
+ */
40
+ private _getManifest;
41
+ /**
42
+ * Prompts the user for authentication credentials.
43
+ *
44
+ * @returns {void}
45
+ */
46
+ private _promptAuthentication;
47
+ /**
48
+ * Handles errors that occur during the fetching of the manifest.
49
+ *
50
+ * @param {Error | AxiosError} error - The error that occurred.
51
+ */
52
+ private _handleFetchingError;
53
+ /**
54
+ * Adds navigations steps and callback function for the generator prompts.
55
+ */
56
+ private _setupFLPConfigPage;
57
+ /**
58
+ * Sets up the prompts for the generator.
59
+ */
60
+ private _setupPrompts;
61
+ /**
62
+ * Finds the configured system based on the provided target in ui5.yaml configuration.
63
+ *
64
+ * @param {AbapTarget} target - The target ABAP system.
65
+ * @returns {Promise<string>} The configured system.
66
+ */
67
+ private _findConfiguredSystem;
68
+ /**
69
+ * Shows an error notification with the provided message and aborts the generator execution.
70
+ *
71
+ * @param {string} message - The error message to display.
72
+ */
73
+ private _abortExecution;
74
+ /**
75
+ * Retrieves the error handler message for the provided error.
76
+ *
77
+ * @param {Error | AxiosError} error - The error to handle.
78
+ * @returns {ValidationLink | string | undefined} The validation link or error message.
79
+ */
80
+ private _getErrorHandlerMessage;
81
+ /**
82
+ * Checks if authentication is required based on the provided error.
83
+ *
84
+ * @param {Error | AxiosError} error - The error to check.
85
+ * @returns {boolean} True if authentication is required, false otherwise.
86
+ */
87
+ private _checkAuthRequired;
88
+ /**
89
+ * Configures logging for the generator.
90
+ */
91
+ private _setupLogging;
92
+ }
93
+ export type { FlpConfigOptions };
94
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,345 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ const yeoman_generator_1 = __importDefault(require("yeoman-generator"));
30
+ const path_1 = __importStar(require("path"));
31
+ const axios_extension_1 = require("@sap-ux/axios-extension");
32
+ const adp_tooling_1 = require("@sap-ux/adp-tooling");
33
+ const logger_1 = require("@sap-ux/logger");
34
+ const telemetryEvents_1 = require("../telemetryEvents");
35
+ const flp_config_inquirer_1 = require("@sap-ux/flp-config-inquirer");
36
+ const yeoman_ui_types_1 = require("@sap-devx/yeoman-ui-types");
37
+ const fiori_generator_shared_1 = require("@sap-ux/fiori-generator-shared");
38
+ const feature_toggle_1 = require("@sap-ux/feature-toggle");
39
+ const project_access_1 = require("@sap-ux/project-access");
40
+ const logger_2 = __importDefault(require("../utils/logger"));
41
+ const i18n_1 = require("../utils/i18n");
42
+ const inquirer_common_1 = require("@sap-ux/inquirer-common");
43
+ const system_access_1 = require("@sap-ux/system-access");
44
+ const btp_utils_1 = require("@sap-ux/btp-utils");
45
+ /**
46
+ * Generator for adding a FLP configuration to an adaptation project.
47
+ *
48
+ * @extends Generator
49
+ */
50
+ class default_1 extends yeoman_generator_1.default {
51
+ setPromptsCallback;
52
+ prompts;
53
+ // Flag to determine if the generator was launched as a sub-generator or standalone
54
+ launchAsSubGen;
55
+ appWizard;
56
+ vscode;
57
+ toolsLogger;
58
+ projectRootPath = '';
59
+ manifest;
60
+ answers;
61
+ logger;
62
+ authenticationRequired = false;
63
+ // Flag to determine if the generator was aborted
64
+ abort = false;
65
+ configuredSystem;
66
+ ui5Yaml;
67
+ credentials;
68
+ /**
69
+ * Creates an instance of the generator.
70
+ *
71
+ * @param {string | string[]} args - The arguments passed to the generator.
72
+ * @param {FlpConfigOptions} opts - The options for the generator.
73
+ */
74
+ constructor(args, opts) {
75
+ super(args, opts);
76
+ this.appWizard = opts.appWizard ?? yeoman_ui_types_1.AppWizard.create(opts);
77
+ this.launchAsSubGen = !!opts.launchAsSubGen;
78
+ this.manifest = opts.manifest;
79
+ this.toolsLogger = new logger_1.ToolsLogger();
80
+ this.projectRootPath = opts.data?.projectRootPath ?? this.destinationRoot();
81
+ this.options = opts;
82
+ this.vscode = opts.vscode;
83
+ this._setupPrompts();
84
+ this._setupLogging();
85
+ }
86
+ async initializing() {
87
+ await (0, i18n_1.initI18n)();
88
+ // Check if the project is supported
89
+ if ((await (0, project_access_1.getAppType)(this.projectRootPath)) !== 'Fiori Adaptation' || (0, adp_tooling_1.isCFEnvironment)(this.projectRootPath)) {
90
+ throw new Error((0, i18n_1.t)('error.projectNotSupported'));
91
+ }
92
+ // Force the generator to overwrite existing files without additional prompting
93
+ if (this.env.conflicter) {
94
+ this.env.conflicter.force = this.options.force ?? true;
95
+ }
96
+ this._setupFLPConfigPage();
97
+ this.ui5Yaml = await (0, adp_tooling_1.getAdpConfig)(this.projectRootPath, (0, path_1.join)(this.projectRootPath, project_access_1.FileName.Ui5Yaml));
98
+ this.configuredSystem = await this._findConfiguredSystem(this.ui5Yaml.target);
99
+ if (!this.configuredSystem) {
100
+ return;
101
+ }
102
+ if (!this.manifest) {
103
+ try {
104
+ this.manifest = await this._getManifest();
105
+ }
106
+ catch (error) {
107
+ this.authenticationRequired = this._checkAuthRequired(error);
108
+ if (this.authenticationRequired) {
109
+ return;
110
+ }
111
+ this._handleFetchingError(error);
112
+ }
113
+ }
114
+ // Add telemetry to be sent once adp-flp-config is generated
115
+ await fiori_generator_shared_1.TelemetryHelper.initTelemetrySettings({
116
+ consumerModule: {
117
+ name: '@sap/generator-fiori-deployment:adp-flp-config',
118
+ version: this.rootGeneratorVersion()
119
+ },
120
+ internalFeature: (0, feature_toggle_1.isInternalFeaturesSettingEnabled)(),
121
+ watchTelemetrySettingStore: false
122
+ });
123
+ }
124
+ async prompting() {
125
+ if (this.authenticationRequired) {
126
+ await this._promptAuthentication();
127
+ }
128
+ if (this.abort) {
129
+ return;
130
+ }
131
+ const inbounds = (0, adp_tooling_1.getInboundsFromManifest)(this.manifest);
132
+ const appId = (0, adp_tooling_1.getRegistrationIdFromManifest)(this.manifest);
133
+ const prompts = await (0, flp_config_inquirer_1.getPrompts)(inbounds, appId, {
134
+ overwrite: { hide: true },
135
+ createAnotherInbound: { hide: true },
136
+ emptyInboundsInfo: { hide: (0, fiori_generator_shared_1.isCli)() }
137
+ });
138
+ this.answers = await this.prompt(prompts);
139
+ }
140
+ async writing() {
141
+ if (this.abort) {
142
+ return;
143
+ }
144
+ try {
145
+ await (0, adp_tooling_1.generateInboundConfig)(this.projectRootPath, this.answers, this.fs);
146
+ }
147
+ catch (error) {
148
+ this.logger.error(`Writing phase failed: ${error}`);
149
+ throw new Error((0, i18n_1.t)('error.updatingApp'));
150
+ }
151
+ }
152
+ end() {
153
+ if (this.abort) {
154
+ return;
155
+ }
156
+ if (!this.launchAsSubGen) {
157
+ this.appWizard?.showInformation((0, i18n_1.t)('info.flpConfigAdded'), yeoman_ui_types_1.MessageType.notification);
158
+ }
159
+ const telemetryData = fiori_generator_shared_1.TelemetryHelper.createTelemetryData({
160
+ appType: 'adp-flp-config',
161
+ ...this.options.telemetryData
162
+ }) ?? {};
163
+ if (telemetryData) {
164
+ (0, fiori_generator_shared_1.sendTelemetry)(telemetryEvents_1.EventName.ADP_FLP_CONFIG_ADDED, telemetryData, this.projectRootPath).catch((error) => {
165
+ this.logger.error((0, i18n_1.t)('error.telemetry', { error }));
166
+ });
167
+ }
168
+ }
169
+ /**
170
+ * Retrieves the merged manifest for the project.
171
+ *
172
+ * @returns {Promise<Manifest>} The project manifest.
173
+ */
174
+ async _getManifest() {
175
+ const { target, ignoreCertErrors = false } = this.ui5Yaml;
176
+ const requestOptions = { ignoreCertErrors };
177
+ if (this.credentials) {
178
+ requestOptions['auth'] = { username: this.credentials.username, password: this.credentials.password };
179
+ }
180
+ const provider = await (0, system_access_1.createAbapServiceProvider)(target, requestOptions, false, this.toolsLogger);
181
+ const variant = (0, adp_tooling_1.getVariant)(this.projectRootPath);
182
+ const manifestService = await adp_tooling_1.ManifestService.initMergedManifest(provider, this.projectRootPath, variant, this.toolsLogger);
183
+ return manifestService.getManifest();
184
+ }
185
+ /**
186
+ * Prompts the user for authentication credentials.
187
+ *
188
+ * @returns {void}
189
+ */
190
+ async _promptAuthentication() {
191
+ const prompts = await (0, inquirer_common_1.getCredentialsPrompts)(async (credentials) => {
192
+ this.credentials = credentials;
193
+ try {
194
+ this.manifest = await this._getManifest();
195
+ }
196
+ catch (error) {
197
+ if (!(0, axios_extension_1.isAxiosError)(error)) {
198
+ this.logger.error(`Manifest fetching failed: ${error}`);
199
+ throw new Error((0, i18n_1.t)('error.fetchingManifest'));
200
+ }
201
+ this.authenticationRequired = this._checkAuthRequired(error);
202
+ if (this.authenticationRequired) {
203
+ return (0, i18n_1.t)('error.authenticationFailed');
204
+ }
205
+ return this._getErrorHandlerMessage(error) ?? false;
206
+ }
207
+ return true;
208
+ });
209
+ this.prompts.splice(0, 0, [
210
+ {
211
+ name: (0, i18n_1.t)('yuiNavSteps.flpCredentialsName'),
212
+ description: (0, i18n_1.t)('yuiNavSteps.flpCredentialsDesc', { system: this.configuredSystem })
213
+ }
214
+ ]);
215
+ await this.prompt(prompts);
216
+ }
217
+ /**
218
+ * Handles errors that occur during the fetching of the manifest.
219
+ *
220
+ * @param {Error | AxiosError} error - The error that occurred.
221
+ */
222
+ _handleFetchingError(error) {
223
+ if ((0, axios_extension_1.isAxiosError)(error)) {
224
+ this.logger.error(`Manifest fetching failed: ${error}. Status: ${error.response?.status}. URI: ${error.request?.path}`);
225
+ const errorHelp = this._getErrorHandlerMessage(error);
226
+ if (errorHelp) {
227
+ this._abortExecution(typeof errorHelp === 'string'
228
+ ? errorHelp
229
+ : `${errorHelp?.message} ([${errorHelp.link.text}](${errorHelp.link.url}))`);
230
+ }
231
+ return;
232
+ }
233
+ this.logger.error(`Manifest fetching failed: ${error}`);
234
+ throw new Error((0, i18n_1.t)('error.fetchingManifest'));
235
+ }
236
+ /**
237
+ * Adds navigations steps and callback function for the generator prompts.
238
+ */
239
+ _setupFLPConfigPage() {
240
+ // if launched as a sub-generator, the navigation steps will be set by the parent generator
241
+ if (!this.launchAsSubGen) {
242
+ this.prompts.splice(0, 0, [
243
+ {
244
+ name: (0, i18n_1.t)('yuiNavSteps.flpConfigName'),
245
+ description: (0, i18n_1.t)('yuiNavSteps.flpConfigDesc', { projectName: path_1.default.basename(this.projectRootPath) })
246
+ }
247
+ ]);
248
+ }
249
+ }
250
+ /**
251
+ * Sets up the prompts for the generator.
252
+ */
253
+ _setupPrompts() {
254
+ // If launched as a sub-generator, the prompts will be set by the parent generator
255
+ if (!this.launchAsSubGen) {
256
+ this.prompts = new yeoman_ui_types_1.Prompts([]);
257
+ this.setPromptsCallback = (fn) => {
258
+ if (this.prompts) {
259
+ this.prompts.setCallback(fn);
260
+ }
261
+ };
262
+ }
263
+ }
264
+ /**
265
+ * Finds the configured system based on the provided target in ui5.yaml configuration.
266
+ *
267
+ * @param {AbapTarget} target - The target ABAP system.
268
+ * @returns {Promise<string>} The configured system.
269
+ */
270
+ async _findConfiguredSystem(target) {
271
+ let configuredSystem;
272
+ if ((0, btp_utils_1.isAppStudio)()) {
273
+ configuredSystem = target?.destination;
274
+ if (!configuredSystem) {
275
+ this._abortExecution((0, i18n_1.t)('error.destinationNotFound'));
276
+ return;
277
+ }
278
+ const destinations = await (0, btp_utils_1.listDestinations)();
279
+ if (!(configuredSystem in destinations)) {
280
+ this._abortExecution((0, i18n_1.t)('error.destinationNotFoundInStore', { destination: configuredSystem }));
281
+ return;
282
+ }
283
+ }
284
+ else {
285
+ const url = target?.url;
286
+ if (!url) {
287
+ this._abortExecution((0, i18n_1.t)('error.systemNotFound'));
288
+ return;
289
+ }
290
+ configuredSystem = (await (0, system_access_1.getCredentialsFromStore)(target, this.toolsLogger))?.name;
291
+ if (!configuredSystem) {
292
+ this._abortExecution((0, i18n_1.t)('error.systemNotFoundInStore', { systemUrl: url }));
293
+ return;
294
+ }
295
+ }
296
+ return configuredSystem;
297
+ }
298
+ /**
299
+ * Shows an error notification with the provided message and aborts the generator execution.
300
+ *
301
+ * @param {string} message - The error message to display.
302
+ */
303
+ _abortExecution(message) {
304
+ if ((0, fiori_generator_shared_1.isCli)()) {
305
+ this.toolsLogger.error(message);
306
+ }
307
+ else {
308
+ this.vscode.window.showErrorMessage(message);
309
+ }
310
+ this.abort = true;
311
+ }
312
+ /**
313
+ * Retrieves the error handler message for the provided error.
314
+ *
315
+ * @param {Error | AxiosError} error - The error to handle.
316
+ * @returns {ValidationLink | string | undefined} The validation link or error message.
317
+ */
318
+ _getErrorHandlerMessage(error) {
319
+ const errorHandler = new inquirer_common_1.ErrorHandler();
320
+ return errorHandler.getValidationErrorHelp(error);
321
+ }
322
+ /**
323
+ * Checks if authentication is required based on the provided error.
324
+ *
325
+ * @param {Error | AxiosError} error - The error to check.
326
+ * @returns {boolean} True if authentication is required, false otherwise.
327
+ */
328
+ _checkAuthRequired(error) {
329
+ if ((0, axios_extension_1.isAxiosError)(error)) {
330
+ if (error.response?.status === 401) {
331
+ return true;
332
+ }
333
+ }
334
+ return false;
335
+ }
336
+ /**
337
+ * Configures logging for the generator.
338
+ */
339
+ _setupLogging() {
340
+ logger_2.default.configureLogging(this.options.logger, this.rootGeneratorName(), this.log, this.options.vscode, this.options.logLevel, this.options.logWrapper);
341
+ this.logger = logger_2.default.logger;
342
+ }
343
+ }
344
+ exports.default = default_1;
345
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,37 @@
1
+ import type { AppWizard } from '@sap-devx/yeoman-ui-types';
2
+ import type { Manifest } from '@sap-ux/project-access';
3
+ import type Generator from 'yeoman-generator';
4
+ import type { TelemetryData } from '@sap-ux/fiori-generator-shared';
5
+ export interface FlpConfigOptions extends Generator.GeneratorOptions {
6
+ /**
7
+ * VSCode instance
8
+ */
9
+ vscode?: unknown;
10
+ /**
11
+ * Option to force the conflicter property of the yeoman environment (prevents additional prompt for overwriting files)
12
+ */
13
+ force?: boolean;
14
+ /**
15
+ * AppWizard instance
16
+ */
17
+ appWizard?: AppWizard;
18
+ /**
19
+ * Whether the generator is launched as a subgenerator
20
+ */
21
+ launchAsSubGen?: boolean;
22
+ /**
23
+ * The manifest of the base application
24
+ */
25
+ manifest: Manifest;
26
+ /**
27
+ * Telemetry data to be send after deployment configuration has been added
28
+ */
29
+ telemetryData?: TelemetryData;
30
+ /**
31
+ * Additional data for the generator
32
+ */
33
+ data?: {
34
+ projectRootPath: string;
35
+ };
36
+ }
37
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Event names for telemetry for the adaptation project fiori launchpad configuration generator
3
+ */
4
+ export declare enum EventName {
5
+ ADP_FLP_CONFIG_ADDED = "ADP_FLP_CONFIG_ADDED"
6
+ }
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EventName = void 0;
4
+ /**
5
+ * Event names for telemetry for the adaptation project fiori launchpad configuration generator
6
+ */
7
+ var EventName;
8
+ (function (EventName) {
9
+ EventName["ADP_FLP_CONFIG_ADDED"] = "ADP_FLP_CONFIG_ADDED";
10
+ })(EventName || (exports.EventName = EventName = {}));
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,24 @@
1
+ {
2
+ "yuiNavSteps": {
3
+ "flpCredentialsName": "FLP Configuration - Credentials",
4
+ "flpCredentialsDesc": "Enter credentials for your adaptation project's system ({{- system}})",
5
+ "sysConfirmDesc": "Validates connection to configured system",
6
+ "flpConfigName": "FLP Configuration",
7
+ "flpConfigDesc": "FLP Configuration for {{- projectName}}"
8
+ },
9
+ "info": {
10
+ "flpConfigAdded": "FLP Configuration added successfully"
11
+ },
12
+ "error": {
13
+ "projectNotSupported": "Unable to find a supported adaptation project",
14
+ "fetchingManifest": "Error fetching merged manifest for base application",
15
+ "destinationNotFound": "Missing destination configuration in ui5.yaml",
16
+ "destinationNotInSubaccount": "Destination not found in the subaccount: {{- destination}}",
17
+ "systemNotFound": "Missing system configuration in ui5.yaml",
18
+ "systemNotFoundInStore": "System not found in the system store: {{- systemUrl}}",
19
+ "writingPhase": "Error in writing phase of the adaptation project FLP configuration",
20
+ "telemetry": "Error sending telemetry data: {{- error}}",
21
+ "updatingApp": "Error updating app with FLP configuration. Inspect the logs for full error.",
22
+ "authenticationFailed": "Authentication failed."
23
+ }
24
+ }
@@ -0,0 +1,14 @@
1
+ import type { TOptions } from 'i18next';
2
+ /**
3
+ * Initialize i18next with the translations for this module.
4
+ */
5
+ export declare function initI18n(): Promise<void>;
6
+ /**
7
+ * Helper function facading the call to i18next. Unless a namespace option is provided the local namespace will be used.
8
+ *
9
+ * @param key i18n key
10
+ * @param options additional options
11
+ * @returns {string} localized string stored for the given key
12
+ */
13
+ export declare function t(key: string, options?: TOptions): string;
14
+ //# sourceMappingURL=i18n.d.ts.map
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.t = exports.initI18n = void 0;
7
+ const i18next_1 = __importDefault(require("i18next"));
8
+ const adp_flp_config_sub_generator_i18n_json_1 = __importDefault(require("../translations/adp-flp-config-sub-generator.i18n.json"));
9
+ const inquirer_common_1 = require("@sap-ux/inquirer-common");
10
+ const adpFlpConfigI18nNamespace = 'adp-flp-config-sub-generator';
11
+ /**
12
+ * Initialize i18next with the translations for this module.
13
+ */
14
+ async function initI18n() {
15
+ await i18next_1.default.init({ lng: 'en', fallbackLng: 'en' }, () => i18next_1.default.addResourceBundle('en', adpFlpConfigI18nNamespace, adp_flp_config_sub_generator_i18n_json_1.default));
16
+ (0, inquirer_common_1.addi18nResourceBundle)();
17
+ }
18
+ exports.initI18n = initI18n;
19
+ /**
20
+ * Helper function facading the call to i18next. Unless a namespace option is provided the local namespace will be used.
21
+ *
22
+ * @param key i18n key
23
+ * @param options additional options
24
+ * @returns {string} localized string stored for the given key
25
+ */
26
+ function t(key, options) {
27
+ if (!options?.ns) {
28
+ options = Object.assign(options ?? {}, { ns: adpFlpConfigI18nNamespace });
29
+ }
30
+ return i18next_1.default.t(key, options);
31
+ }
32
+ exports.t = t;
33
+ initI18n().catch(() => {
34
+ // Needed for lint
35
+ });
36
+ //# sourceMappingURL=i18n.js.map
@@ -0,0 +1,33 @@
1
+ import { LogWrapper, type ILogWrapper } from '@sap-ux/fiori-generator-shared';
2
+ import type { Logger } from 'yeoman-environment';
3
+ import type { IVSCodeExtLogger, LogLevel } from '@vscode-logging/logger';
4
+ /**
5
+ * Static logger prevents passing of logger references through all functions, as this is a cross-cutting concern.
6
+ */
7
+ export default class AdpFlpConfigLogger {
8
+ private static _logger;
9
+ /**
10
+ * Get the logger.
11
+ *
12
+ * @returns the logger
13
+ */
14
+ static get logger(): ILogWrapper;
15
+ /**
16
+ * Set the logger.
17
+ *
18
+ * @param value the logger to set
19
+ */
20
+ static set logger(value: ILogWrapper);
21
+ /**
22
+ * Configures the vscode logger.
23
+ *
24
+ * @param vscLogger - the vscode logger
25
+ * @param loggerName - the logger name
26
+ * @param yoLogger - the yeoman logger
27
+ * @param vscode - the vscode instance
28
+ * @param logLevel - the log level
29
+ * @param logWrapper - log wrapper instance
30
+ */
31
+ static configureLogging(vscLogger: IVSCodeExtLogger, loggerName: string, yoLogger: Logger, vscode?: unknown, logLevel?: LogLevel, logWrapper?: LogWrapper): void;
32
+ }
33
+ //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const fiori_generator_shared_1 = require("@sap-ux/fiori-generator-shared");
4
+ /**
5
+ * Static logger prevents passing of logger references through all functions, as this is a cross-cutting concern.
6
+ */
7
+ class AdpFlpConfigLogger {
8
+ static _logger = fiori_generator_shared_1.DefaultLogger;
9
+ /**
10
+ * Get the logger.
11
+ *
12
+ * @returns the logger
13
+ */
14
+ static get logger() {
15
+ return AdpFlpConfigLogger._logger;
16
+ }
17
+ /**
18
+ * Set the logger.
19
+ *
20
+ * @param value the logger to set
21
+ */
22
+ static set logger(value) {
23
+ AdpFlpConfigLogger._logger = value;
24
+ }
25
+ /**
26
+ * Configures the vscode logger.
27
+ *
28
+ * @param vscLogger - the vscode logger
29
+ * @param loggerName - the logger name
30
+ * @param yoLogger - the yeoman logger
31
+ * @param vscode - the vscode instance
32
+ * @param logLevel - the log level
33
+ * @param logWrapper - log wrapper instance
34
+ */
35
+ static configureLogging(vscLogger, loggerName, yoLogger, vscode, logLevel, logWrapper) {
36
+ const logger = logWrapper ?? new fiori_generator_shared_1.LogWrapper(loggerName, yoLogger, logLevel, vscLogger, vscode);
37
+ AdpFlpConfigLogger.logger = logger;
38
+ }
39
+ }
40
+ exports.default = AdpFlpConfigLogger;
41
+ //# sourceMappingURL=logger.js.map
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@sap-ux/adp-flp-config-sub-generator",
3
+ "description": "Generator for adding FLP configuration to an Adaptation Project",
4
+ "version": "0.0.2",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/SAP/open-ux-tools.git",
8
+ "directory": "packages/adp-flp-config-sub-generator"
9
+ },
10
+ "bugs": {
11
+ "url": "https://github.com/SAP/open-ux-tools/issues?q=is%3Aopen+is%3Aissue"
12
+ },
13
+ "license": "Apache-2.0",
14
+ "main": "generators/app/index.js",
15
+ "files": [
16
+ "LICENSE",
17
+ "generators",
18
+ "!generators/*.map",
19
+ "!generators/**/*.map"
20
+ ],
21
+ "dependencies": {
22
+ "@sap-devx/yeoman-ui-types": "1.14.4",
23
+ "i18next": "23.5.1",
24
+ "yeoman-generator": "5.10.0",
25
+ "@sap-ux/adp-tooling": "0.12.125",
26
+ "@sap-ux/axios-extension": "1.18.5",
27
+ "@sap-ux/btp-utils": "1.0.1",
28
+ "@sap-ux/feature-toggle": "0.2.3",
29
+ "@sap-ux/fiori-generator-shared": "0.7.27",
30
+ "@sap-ux/flp-config-inquirer": "0.2.31",
31
+ "@sap-ux/inquirer-common": "0.6.14",
32
+ "@sap-ux/logger": "0.6.0",
33
+ "@sap-ux/project-access": "1.29.5",
34
+ "@sap-ux/store": "1.0.0",
35
+ "@sap-ux/system-access": "0.5.30"
36
+ },
37
+ "devDependencies": {
38
+ "@jest/types": "29.6.3",
39
+ "@types/fs-extra": "9.0.13",
40
+ "@types/inquirer": "8.2.6",
41
+ "@types/vscode": "1.73.1",
42
+ "@types/yeoman-environment": "2.10.11",
43
+ "@types/yeoman-generator": "5.2.11",
44
+ "@types/yeoman-test": "4.0.6",
45
+ "@vscode-logging/logger": "2.0.0",
46
+ "fs-extra": "10.0.0",
47
+ "rimraf": "5.0.5",
48
+ "typescript": "5.3.3",
49
+ "yeoman-test": "6.3.0"
50
+ },
51
+ "engines": {
52
+ "node": ">=18.x"
53
+ },
54
+ "scripts": {
55
+ "build": "tsc --build",
56
+ "clean": "rimraf --glob generators test/test-output coverage *.tsbuildinfo",
57
+ "watch": "tsc --watch",
58
+ "lint": "eslint . --ext .ts",
59
+ "lint:fix": "eslint . --ext .ts --fix",
60
+ "test": "jest --ci --forceExit --detectOpenHandles --colors --passWithNoTests",
61
+ "test-u": "jest --ci --forceExit --detectOpenHandles --colors -u",
62
+ "link": "pnpm link --global",
63
+ "unlink": "pnpm unlink --global"
64
+ }
65
+ }