@sap-ux/flp-config-inquirer 0.1.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 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,85 @@
1
+ # @sap-ux/flp-config-inquirer
2
+
3
+ Provides Inquirer-based prompting to allow input and validation of data required to generate an **FLP** (*Fiori Launchpad*) configuration.
4
+
5
+ ## Installation
6
+
7
+ Npm
8
+ `npm install --save @sap-ux/flp-config-inquirer`
9
+
10
+ Yarn
11
+ `yarn add @sap-ux/flp-config-inquirer`
12
+
13
+ Pnpm
14
+ `pnpm add @sap-ux/flp-config-inquirer`
15
+
16
+ ## Explainer
17
+
18
+ The `@sap-ux/flp-config-inquirer` package provides a set of prompts for collecting user input required to generate FLP configuration. It leverages [Inquirer.js](https://www.npmjs.com/package/inquirer) for interactive command-line user interfaces.
19
+
20
+ You can retrieve the prompts using `getPrompts` and execute them with your own prompting mechanism. However, it is recommended to use the `prompt` function, which handles assigning default values to unanswered prompts based on provided prompt options. This ensures that hidden prompts or those not executed due to conditional logic are correctly populated.
21
+
22
+ Configurability of prompts is entirely controlled using the `FLPConfigPromptOptions` parameter.
23
+
24
+ - **Prompt Options**: Use `FLPConfigPromptOptions` to customize prompts, such as setting default values, hiding prompts, or adding validation.
25
+ - **Defaults Handling**: When prompts are hidden or not executed, default values or functions can be provided to ensure all required answers are available.
26
+ - **Conditional Prompts**: Some prompts may be conditionally displayed based on previous answers. The `prompt` function handles these conditions and default assignments.
27
+
28
+ ### Inquirer usage example:
29
+
30
+ In the following example, the prompts are customized as follows:
31
+
32
+ - Sets a default `semanticObject` of `'MySemanticObject'`.
33
+ - Sets a default `action` of `'display'`.
34
+ - Hides the `title` prompt and provides a default value of `'My Application Title'`.
35
+
36
+ ```ts
37
+ import { prompt, promptNames, type FLPConfigPromptOptions, type FLPConfigAnswers } from '@sap-ux/flp-config-inquirer';
38
+ import { type InquirerAdapter } from '@sap-ux/inquirer-common';
39
+ import inquirer from 'inquirer';
40
+
41
+ const promptOptions: FLPConfigPromptOptions = {
42
+ // Provides a default semantic object
43
+ [promptNames.semanticObject]: {
44
+ default: 'MySemanticObject'
45
+ },
46
+ // Provides a default action
47
+ [promptNames.action]: {
48
+ default: 'display'
49
+ },
50
+ // Hide the title prompt and provide a default value
51
+ [promptNames.title]: {
52
+ hide: true,
53
+ default: 'My Application Title'
54
+ }
55
+ };
56
+
57
+ const inquirerAdapter: InquirerAdapter = {
58
+ prompt: inquirer.prompt
59
+ };
60
+
61
+ // Assume there are no existing inbound keys
62
+ const inboundKeys: string[] = [];
63
+
64
+ // flpConfigAnswers will contain all values required to generate an FLP configuration
65
+ const flpConfigAnswers: FLPConfigAnswers = await prompt(
66
+ inquirerAdapter,
67
+ inboundKeys,
68
+ promptOptions
69
+ );
70
+
71
+ // Use flpConfigAnswers as needed
72
+ console.log('FLP Configuration Answers:', flpConfigAnswers);
73
+ ```
74
+
75
+ ## License
76
+
77
+ Read [License](./LICENSE).
78
+
79
+ ## Keywords
80
+
81
+ SAP Fiori Launchpad
82
+ FLP Configuration
83
+ Inquirer
84
+ Prompting
85
+ Generator
package/dist/i18n.d.ts ADDED
@@ -0,0 +1,20 @@
1
+ import type { TOptions } from 'i18next';
2
+ export declare const FLP_CONFIG_NAMESPACE = "flp-config-inquirer";
3
+ /**
4
+ * Adds the `flp-config-inquirer` resource bundle to i18next.
5
+ * May be required to load i18n translations after initialising in the consumer module.
6
+ */
7
+ export declare function addi18nResourceBundle(): void;
8
+ /**
9
+ * Initialize i18next with the translations for this module.
10
+ */
11
+ export declare function initI18n(): Promise<void>;
12
+ /**
13
+ * Helper function facading the call to i18next. Unless a namespace option is provided the local namespace will be used.
14
+ *
15
+ * @param key i18n key
16
+ * @param options additional options
17
+ * @returns {string} localized string stored for the given key
18
+ */
19
+ export declare function t(key: string, options?: TOptions): string;
20
+ //# sourceMappingURL=i18n.d.ts.map
package/dist/i18n.js ADDED
@@ -0,0 +1,46 @@
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.FLP_CONFIG_NAMESPACE = void 0;
7
+ exports.addi18nResourceBundle = addi18nResourceBundle;
8
+ exports.initI18n = initI18n;
9
+ exports.t = t;
10
+ const i18next_1 = __importDefault(require("i18next"));
11
+ const project_input_validator_1 = require("@sap-ux/project-input-validator");
12
+ const flp_config_inquirer_i18n_json_1 = __importDefault(require("./translations/flp-config-inquirer.i18n.json"));
13
+ exports.FLP_CONFIG_NAMESPACE = 'flp-config-inquirer';
14
+ /**
15
+ * Adds the `flp-config-inquirer` resource bundle to i18next.
16
+ * May be required to load i18n translations after initialising in the consumer module.
17
+ */
18
+ function addi18nResourceBundle() {
19
+ i18next_1.default.addResourceBundle('en', exports.FLP_CONFIG_NAMESPACE, flp_config_inquirer_i18n_json_1.default);
20
+ }
21
+ /**
22
+ * Initialize i18next with the translations for this module.
23
+ */
24
+ async function initI18n() {
25
+ await i18next_1.default.init({ lng: 'en', fallbackLng: 'en' });
26
+ addi18nResourceBundle();
27
+ // add the project-input-validator i18n resource bundle to ensure all translations are available
28
+ (0, project_input_validator_1.addi18nResourceBundle)();
29
+ }
30
+ /**
31
+ * Helper function facading the call to i18next. Unless a namespace option is provided the local namespace will be used.
32
+ *
33
+ * @param key i18n key
34
+ * @param options additional options
35
+ * @returns {string} localized string stored for the given key
36
+ */
37
+ function t(key, options) {
38
+ if (!options?.ns) {
39
+ options = Object.assign(options ?? {}, { ns: exports.FLP_CONFIG_NAMESPACE });
40
+ }
41
+ return i18next_1.default.t(key, options);
42
+ }
43
+ initI18n().catch(() => {
44
+ // Needed for lint
45
+ });
46
+ //# sourceMappingURL=i18n.js.map
@@ -0,0 +1,22 @@
1
+ import type { InquirerAdapter, PromptDefaultValue } from '@sap-ux/inquirer-common';
2
+ import { promptNames } from './types';
3
+ import type { FLPConfigAnswers, FLPConfigQuestion, FLPConfigPromptOptions } from './types';
4
+ /**
5
+ * Get the inquirer prompts for the FLP configuration inquirer.
6
+ *
7
+ * @param inboundKeys - array of existing inbound keys to check for duplicates
8
+ * @param promptOptions - options that can control some of the prompt behavior. See {@link FLPConfigPromptOptions} for details
9
+ * @returns the prompts used to provide input for FLP configuration
10
+ */
11
+ declare function getPrompts(inboundKeys?: string[], promptOptions?: FLPConfigPromptOptions): Promise<FLPConfigQuestion[]>;
12
+ /**
13
+ * Prompt for FLP configuration inputs.
14
+ *
15
+ * @param adapter - an instance of InquirerAdapter to handle prompting
16
+ * @param inboundKeys - array of existing inbound keys to check for duplicates
17
+ * @param promptOptions - options that can control some of the prompt behavior. See {@link FLPConfigPromptOptions} for details
18
+ * @returns the prompt answers
19
+ */
20
+ declare function prompt(adapter: InquirerAdapter, inboundKeys?: string[], promptOptions?: FLPConfigPromptOptions): Promise<FLPConfigAnswers>;
21
+ export { getPrompts, prompt, promptNames, type InquirerAdapter, type PromptDefaultValue, type FLPConfigAnswers, type FLPConfigPromptOptions };
22
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js ADDED
@@ -0,0 +1,81 @@
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.promptNames = void 0;
7
+ exports.getPrompts = getPrompts;
8
+ exports.prompt = prompt;
9
+ const isNil_1 = __importDefault(require("lodash/isNil"));
10
+ const i18n_1 = require("./i18n");
11
+ const types_1 = require("./types");
12
+ Object.defineProperty(exports, "promptNames", { enumerable: true, get: function () { return types_1.promptNames; } });
13
+ const prompts_1 = require("./prompts");
14
+ /**
15
+ * Get the inquirer prompts for the FLP configuration inquirer.
16
+ *
17
+ * @param inboundKeys - array of existing inbound keys to check for duplicates
18
+ * @param promptOptions - options that can control some of the prompt behavior. See {@link FLPConfigPromptOptions} for details
19
+ * @returns the prompts used to provide input for FLP configuration
20
+ */
21
+ async function getPrompts(inboundKeys = [], promptOptions) {
22
+ await (0, i18n_1.initI18n)();
23
+ return (0, prompts_1.getQuestions)(inboundKeys, promptOptions);
24
+ }
25
+ /**
26
+ * Prompt for FLP configuration inputs.
27
+ *
28
+ * @param adapter - an instance of InquirerAdapter to handle prompting
29
+ * @param inboundKeys - array of existing inbound keys to check for duplicates
30
+ * @param promptOptions - options that can control some of the prompt behavior. See {@link FLPConfigPromptOptions} for details
31
+ * @returns the prompt answers
32
+ */
33
+ async function prompt(adapter, inboundKeys = [], promptOptions) {
34
+ const flpPrompts = await getPrompts(inboundKeys, promptOptions);
35
+ const answers = await adapter.prompt(flpPrompts);
36
+ // Apply default values to prompts in case they have not been executed
37
+ if (promptOptions) {
38
+ const defaultAnswers = applyPromptOptionDefaults(answers, flpPrompts, promptOptions);
39
+ Object.assign(answers, defaultAnswers);
40
+ }
41
+ return answers;
42
+ }
43
+ /**
44
+ * Apply prompt option default values to prompt answers in case they have not been executed by the user selections.
45
+ * This can occur where some prompts are hidden by conditions.
46
+ *
47
+ * @param answers the answers from previous prompting, only answers without a value will be considered for defaulting
48
+ * @param flpPrompts the prompts that were used to prompt the user, will be used to apply default values if not answered or no default provided
49
+ * @param promptOptions the prompt options which may provide default values or functions
50
+ * @returns the default values for the unanswered prompts, based on the prompt options
51
+ */
52
+ function applyPromptOptionDefaults(answers, flpPrompts, promptOptions) {
53
+ const defaultAnswers = {};
54
+ Object.entries(promptOptions).forEach(([key, promptOpt]) => {
55
+ const promptKey = key;
56
+ // Do we have an answer? If not, apply the default
57
+ const defaultValueOrFunc = promptOpt.default;
58
+ if ((0, isNil_1.default)(answers[promptKey]) && defaultValueOrFunc !== undefined) {
59
+ const defaultValue = getDefaultValue(answers, defaultValueOrFunc);
60
+ Object.assign(defaultAnswers, {
61
+ [promptKey]: defaultValue
62
+ });
63
+ }
64
+ });
65
+ return defaultAnswers;
66
+ }
67
+ /**
68
+ * Get the default value for a prompt based on the provided default value or function.
69
+ * If a function is provided, it will be called with the current answers to determine the default value.
70
+ *
71
+ * @param answers the current answers provided to default functions
72
+ * @param promptDefault the default value or function to determine the default value
73
+ * @returns the default value for the prompt or undefined if no default value is provided
74
+ */
75
+ function getDefaultValue(answers, promptDefault) {
76
+ if (typeof promptDefault === 'function') {
77
+ return promptDefault(answers);
78
+ }
79
+ return promptDefault;
80
+ }
81
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,2 @@
1
+ export * from './prompts';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,18 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./prompts"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,10 @@
1
+ import type { FLPConfigPromptOptions, FLPConfigQuestion } from '../types';
2
+ /**
3
+ * Generates a list of prompts for FLP (Fiori Launchpad) configuration.
4
+ *
5
+ * @param {string[]} [inboundKeys] - An array of existing inbound keys to check for duplicates.
6
+ * @param {FLPConfigPromptOptions} [promptOptions] - Optional configuration to control prompt behavior and defaults.
7
+ * @returns {FLPConfigQuestion[]} An array of FLPConfigQuestion objects to be used for prompting the user.
8
+ */
9
+ export declare function getQuestions(inboundKeys?: string[], promptOptions?: FLPConfigPromptOptions): FLPConfigQuestion[];
10
+ //# sourceMappingURL=prompts.d.ts.map
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getQuestions = getQuestions;
4
+ const fiori_generator_shared_1 = require("@sap-ux/fiori-generator-shared");
5
+ const basic_1 = require("./questions/basic");
6
+ const types_1 = require("../types");
7
+ /**
8
+ * Generates a list of prompts for FLP (Fiori Launchpad) configuration.
9
+ *
10
+ * @param {string[]} [inboundKeys] - An array of existing inbound keys to check for duplicates.
11
+ * @param {FLPConfigPromptOptions} [promptOptions] - Optional configuration to control prompt behavior and defaults.
12
+ * @returns {FLPConfigQuestion[]} An array of FLPConfigQuestion objects to be used for prompting the user.
13
+ */
14
+ function getQuestions(inboundKeys = [], promptOptions) {
15
+ const isCLI = (0, fiori_generator_shared_1.getHostEnvironment)() === fiori_generator_shared_1.hostEnvironment.cli;
16
+ const existingKeyRef = { value: false };
17
+ const silentOverwrite = promptOptions?.silentOverwrite ?? false;
18
+ const keyedPrompts = {
19
+ [types_1.promptNames.semanticObject]: (0, basic_1.getSemanticObjectPrompt)(isCLI, promptOptions?.[types_1.promptNames.semanticObject]),
20
+ [types_1.promptNames.action]: (0, basic_1.getActionPrompt)(isCLI, promptOptions?.[types_1.promptNames.action]),
21
+ [types_1.promptNames.overwrite]: (0, basic_1.getOverwritePrompt)(inboundKeys, isCLI, existingKeyRef, promptOptions?.[types_1.promptNames.overwrite]),
22
+ [types_1.promptNames.title]: (0, basic_1.getTitlePrompt)(existingKeyRef, silentOverwrite, isCLI, promptOptions?.[types_1.promptNames.title]),
23
+ [types_1.promptNames.subTitle]: (0, basic_1.getSubTitlePrompt)(existingKeyRef, silentOverwrite, promptOptions?.[types_1.promptNames.subTitle])
24
+ };
25
+ const questions = [
26
+ keyedPrompts[types_1.promptNames.semanticObject],
27
+ keyedPrompts[types_1.promptNames.action],
28
+ keyedPrompts[types_1.promptNames.overwrite],
29
+ keyedPrompts[types_1.promptNames.title],
30
+ keyedPrompts[types_1.promptNames.subTitle]
31
+ ];
32
+ return questions;
33
+ }
34
+ //# sourceMappingURL=prompts.js.map
@@ -0,0 +1,47 @@
1
+ import type { ActionPromptOptions, ExistingInboundRef, FLPConfigQuestion, OverwritePromptOptions, SemanticObjectPromptOptions, SubTitlePromptOptions, TitlePromptOptions } from '../../types';
2
+ /**
3
+ * Creates the 'semanticObject' prompt for FLP configuration.
4
+ *
5
+ * @param {boolean} isCLI - Indicates if the platform is CLI.
6
+ * @param {SemanticObjectPromptOptions} [options] - Optional configuration for the semantic object prompt, including default values.
7
+ * @returns {FLPConfigQuestion} The prompt configuration for the semantic object.
8
+ */
9
+ export declare function getSemanticObjectPrompt(isCLI: boolean, options?: SemanticObjectPromptOptions): FLPConfigQuestion;
10
+ /**
11
+ * Creates the 'action' prompt for FLP configuration.
12
+ *
13
+ * @param {boolean} isCLI - Indicates if the platform is CLI.
14
+ * @param {ActionPromptOptions} [options] - Optional configuration for the action prompt, including default values.
15
+ * @returns {FLPConfigQuestion} The prompt configuration for the action.
16
+ */
17
+ export declare function getActionPrompt(isCLI: boolean, options?: ActionPromptOptions): FLPConfigQuestion;
18
+ /**
19
+ * Creates the 'overwrite' prompt for FLP configuration.
20
+ *
21
+ * @param {string[]} inboundKeys - A list of existing inbound keys to check for duplicates.
22
+ * @param {boolean} isCLI - Indicates if the platform is CLI (affects message formatting).
23
+ * @param {ExistingInboundRef} existingKeyRef - A reference object to track whether a key conflict exists.
24
+ * @param {OverwritePromptOptions} [options] - Optional configuration for the overwrite prompt, including default behavior and visibility.
25
+ * @returns {FLPConfigQuestion} The prompt configuration for overwrite.
26
+ */
27
+ export declare function getOverwritePrompt(inboundKeys: string[], isCLI: boolean, existingKeyRef: ExistingInboundRef, options?: OverwritePromptOptions): FLPConfigQuestion;
28
+ /**
29
+ * Creates the 'title' prompt for FLP configuration.
30
+ *
31
+ * @param {ExistingInboundRef} existingKeyRef - A reference object to track whether an inbound id exists.
32
+ * @param {boolean} silentOverwrite - A flag indicating if overwrites should be silent.
33
+ * @param {boolean} isCLI - Indicates if the platform is CLI.
34
+ * @param {TitlePromptOptions} [options] - Optional configuration for the title prompt, including default values.
35
+ * @returns {FLPConfigQuestion} The prompt configuration for the title.
36
+ */
37
+ export declare function getTitlePrompt(existingKeyRef: ExistingInboundRef, silentOverwrite: boolean, isCLI: boolean, options?: TitlePromptOptions): FLPConfigQuestion;
38
+ /**
39
+ * Creates the 'subTitle' prompt for FLP configuration.
40
+ *
41
+ * @param {ExistingInboundRef} existingKeyRef - A reference object to track whether an inbound id exists.
42
+ * @param {boolean} silentOverwrite - A flag indicating if overwrites should be silent.
43
+ * @param {SubTitlePromptOptions} [options] - Optional configuration for the subtitle prompt, including default values.
44
+ * @returns {FLPConfigQuestion} The prompt configuration for the subtitle.
45
+ */
46
+ export declare function getSubTitlePrompt(existingKeyRef: ExistingInboundRef, silentOverwrite: boolean, options?: SubTitlePromptOptions): FLPConfigQuestion;
47
+ //# sourceMappingURL=basic.d.ts.map
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getSemanticObjectPrompt = getSemanticObjectPrompt;
4
+ exports.getActionPrompt = getActionPrompt;
5
+ exports.getOverwritePrompt = getOverwritePrompt;
6
+ exports.getTitlePrompt = getTitlePrompt;
7
+ exports.getSubTitlePrompt = getSubTitlePrompt;
8
+ const yeoman_ui_types_1 = require("@sap-devx/yeoman-ui-types");
9
+ const project_input_validator_1 = require("@sap-ux/project-input-validator");
10
+ const i18n_1 = require("../../i18n");
11
+ const types_1 = require("../../types");
12
+ /**
13
+ * Creates the 'semanticObject' prompt for FLP configuration.
14
+ *
15
+ * @param {boolean} isCLI - Indicates if the platform is CLI.
16
+ * @param {SemanticObjectPromptOptions} [options] - Optional configuration for the semantic object prompt, including default values.
17
+ * @returns {FLPConfigQuestion} The prompt configuration for the semantic object.
18
+ */
19
+ function getSemanticObjectPrompt(isCLI, options) {
20
+ return {
21
+ name: types_1.promptNames.semanticObject,
22
+ type: 'input',
23
+ guiOptions: {
24
+ mandatory: true,
25
+ breadcrumb: true
26
+ },
27
+ message: (0, i18n_1.t)('prompts.semanticObject'),
28
+ default: options?.default,
29
+ filter: (val) => val?.trim(),
30
+ validate: (val) => (0, project_input_validator_1.validateText)(val, isCLI, 30, ['_'])
31
+ };
32
+ }
33
+ /**
34
+ * Creates the 'action' prompt for FLP configuration.
35
+ *
36
+ * @param {boolean} isCLI - Indicates if the platform is CLI.
37
+ * @param {ActionPromptOptions} [options] - Optional configuration for the action prompt, including default values.
38
+ * @returns {FLPConfigQuestion} The prompt configuration for the action.
39
+ */
40
+ function getActionPrompt(isCLI, options) {
41
+ return {
42
+ name: types_1.promptNames.action,
43
+ type: 'input',
44
+ guiOptions: {
45
+ mandatory: true,
46
+ breadcrumb: true
47
+ },
48
+ message: (0, i18n_1.t)('prompts.action'),
49
+ default: options?.default,
50
+ filter: (val) => val?.trim(),
51
+ validate: (val) => (0, project_input_validator_1.validateText)(val, isCLI, 60, ['_'])
52
+ };
53
+ }
54
+ /**
55
+ * Creates the 'overwrite' prompt for FLP configuration.
56
+ *
57
+ * @param {string[]} inboundKeys - A list of existing inbound keys to check for duplicates.
58
+ * @param {boolean} isCLI - Indicates if the platform is CLI (affects message formatting).
59
+ * @param {ExistingInboundRef} existingKeyRef - A reference object to track whether a key conflict exists.
60
+ * @param {OverwritePromptOptions} [options] - Optional configuration for the overwrite prompt, including default behavior and visibility.
61
+ * @returns {FLPConfigQuestion} The prompt configuration for overwrite.
62
+ */
63
+ function getOverwritePrompt(inboundKeys, isCLI, existingKeyRef, options) {
64
+ return {
65
+ type: 'confirm',
66
+ name: types_1.promptNames.overwrite,
67
+ message: (previousAnswers) => `${isCLI
68
+ ? (0, i18n_1.t)('validators.inboundConfigKeyExists', {
69
+ inboundKey: `${previousAnswers.semanticObject}-${previousAnswers.action}`
70
+ })
71
+ : ''} ${(0, i18n_1.t)('validators.flpConfigOverwrite')}`,
72
+ guiOptions: {
73
+ applyDefaultWhenDirty: true
74
+ },
75
+ default: options?.default ?? (() => !existingKeyRef.value),
76
+ when: options?.hide
77
+ ? false
78
+ : (previousAnswers) => {
79
+ existingKeyRef.value =
80
+ inboundKeys.indexOf(`${previousAnswers.semanticObject}-${previousAnswers.action}`) > -1;
81
+ return existingKeyRef.value;
82
+ },
83
+ additionalMessages: (_, previousAnswers) => ({
84
+ message: (0, i18n_1.t)('validators.inboundConfigKeyExists', {
85
+ inboundKey: `${previousAnswers.semanticObject}-${previousAnswers.action}`
86
+ }),
87
+ severity: yeoman_ui_types_1.Severity.warning
88
+ })
89
+ };
90
+ }
91
+ /**
92
+ * Creates the 'title' prompt for FLP configuration.
93
+ *
94
+ * @param {ExistingInboundRef} existingKeyRef - A reference object to track whether an inbound id exists.
95
+ * @param {boolean} silentOverwrite - A flag indicating if overwrites should be silent.
96
+ * @param {boolean} isCLI - Indicates if the platform is CLI.
97
+ * @param {TitlePromptOptions} [options] - Optional configuration for the title prompt, including default values.
98
+ * @returns {FLPConfigQuestion} The prompt configuration for the title.
99
+ */
100
+ function getTitlePrompt(existingKeyRef, silentOverwrite, isCLI, options) {
101
+ return {
102
+ when: ({ overwrite }) => overwrite !== false || !existingKeyRef.value || silentOverwrite,
103
+ name: types_1.promptNames.title,
104
+ type: 'input',
105
+ guiOptions: {
106
+ mandatory: true,
107
+ breadcrumb: true
108
+ },
109
+ message: (0, i18n_1.t)('prompts.title'),
110
+ default: options?.default,
111
+ filter: (val) => val?.trim(),
112
+ validate: (val) => (0, project_input_validator_1.validateText)(val, isCLI, 0)
113
+ };
114
+ }
115
+ /**
116
+ * Creates the 'subTitle' prompt for FLP configuration.
117
+ *
118
+ * @param {ExistingInboundRef} existingKeyRef - A reference object to track whether an inbound id exists.
119
+ * @param {boolean} silentOverwrite - A flag indicating if overwrites should be silent.
120
+ * @param {SubTitlePromptOptions} [options] - Optional configuration for the subtitle prompt, including default values.
121
+ * @returns {FLPConfigQuestion} The prompt configuration for the subtitle.
122
+ */
123
+ function getSubTitlePrompt(existingKeyRef, silentOverwrite, options) {
124
+ return {
125
+ when: ({ overwrite }) => overwrite !== false || !existingKeyRef.value || silentOverwrite,
126
+ name: types_1.promptNames.subTitle,
127
+ type: 'input',
128
+ guiOptions: {
129
+ breadcrumb: (0, i18n_1.t)('prompts.subTitle')
130
+ },
131
+ message: (0, i18n_1.t)('prompts.subTitle'),
132
+ default: options?.default,
133
+ filter: (val) => val?.trim()
134
+ };
135
+ }
136
+ //# sourceMappingURL=basic.js.map
@@ -0,0 +1,2 @@
1
+ export * from './basic';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,18 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./basic"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,12 @@
1
+ {
2
+ "prompts": {
3
+ "semanticObject": "Semantic Object",
4
+ "action": "Action",
5
+ "title": "Title",
6
+ "subTitle": "Subtitle"
7
+ },
8
+ "validators": {
9
+ "inboundConfigKeyExists": "An inbound configuration with the key: '{{inboundKey}}' is already defined.",
10
+ "flpConfigOverwrite": "Overwrite existing configuration?"
11
+ }
12
+ }
@@ -0,0 +1,83 @@
1
+ import type { YUIQuestion, GuiOptions, PromptSeverityMessage } from '@sap-ux/inquirer-common';
2
+ /**
3
+ * Enumeration of prompt names used in the FLP configuration.
4
+ */
5
+ export declare enum promptNames {
6
+ semanticObject = "semanticObject",
7
+ action = "action",
8
+ overwrite = "overwrite",
9
+ title = "title",
10
+ subTitle = "subTitle"
11
+ }
12
+ /**
13
+ * Interface representing the answers collected from the FLP configuration prompts.
14
+ */
15
+ export interface FLPConfigAnswers {
16
+ [promptNames.semanticObject]: string;
17
+ [promptNames.action]: string;
18
+ [promptNames.overwrite]?: boolean;
19
+ [promptNames.title]?: string;
20
+ [promptNames.subTitle]?: string;
21
+ s4Continue?: boolean;
22
+ }
23
+ /**
24
+ * Boolean reference to already existing inbound id key.
25
+ */
26
+ export interface ExistingInboundRef {
27
+ value: boolean;
28
+ }
29
+ /**
30
+ * The question type specific to FLP configuration prompts.
31
+ */
32
+ export interface FLPConfigQuestion extends YUIQuestion<FLPConfigAnswers> {
33
+ name: promptNames;
34
+ guiOptions?: GuiOptions;
35
+ additionalMessages?: PromptSeverityMessage;
36
+ }
37
+ /**
38
+ * Options for the 'semanticObject' prompt.
39
+ */
40
+ export interface SemanticObjectPromptOptions {
41
+ default?: string;
42
+ }
43
+ /**
44
+ * Options for the 'action' prompt.
45
+ */
46
+ export interface ActionPromptOptions {
47
+ default?: string;
48
+ }
49
+ /**
50
+ * Options for the 'overwrite' prompt.
51
+ */
52
+ export interface OverwritePromptOptions {
53
+ hide?: boolean;
54
+ default?: boolean;
55
+ }
56
+ /**
57
+ * Options for the 'title' prompt.
58
+ */
59
+ export interface TitlePromptOptions {
60
+ default?: string;
61
+ }
62
+ /**
63
+ * Options for the 'subTitle' prompt.
64
+ */
65
+ export interface SubTitlePromptOptions {
66
+ default?: string;
67
+ }
68
+ /**
69
+ * The options which are common for the FLP config inquirer.
70
+ */
71
+ type FLPConfigCommonInquirerOptions = {
72
+ silentOverwrite?: boolean;
73
+ };
74
+ /**
75
+ * The options for the FLP config inquirer & the prompts.
76
+ */
77
+ type flpConfigPromptOptions = Record<promptNames.semanticObject, SemanticObjectPromptOptions> & Record<promptNames.action, ActionPromptOptions> & Record<promptNames.overwrite, OverwritePromptOptions> & Record<promptNames.title, TitlePromptOptions> & Record<promptNames.subTitle, SubTitlePromptOptions>;
78
+ /**
79
+ * The options for the FLP config inquirer & the prompts.
80
+ */
81
+ export type FLPConfigPromptOptions = Partial<flpConfigPromptOptions> & FLPConfigCommonInquirerOptions;
82
+ export {};
83
+ //# sourceMappingURL=types.d.ts.map
package/dist/types.js ADDED
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.promptNames = void 0;
4
+ /**
5
+ * Enumeration of prompt names used in the FLP configuration.
6
+ */
7
+ var promptNames;
8
+ (function (promptNames) {
9
+ promptNames["semanticObject"] = "semanticObject";
10
+ promptNames["action"] = "action";
11
+ promptNames["overwrite"] = "overwrite";
12
+ promptNames["title"] = "title";
13
+ promptNames["subTitle"] = "subTitle";
14
+ })(promptNames || (exports.promptNames = promptNames = {}));
15
+ //# sourceMappingURL=types.js.map
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@sap-ux/flp-config-inquirer",
3
+ "description": "Prompts module that can prompt users for inputs required for FLP configuration",
4
+ "version": "0.1.0",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/SAP/open-ux-tools.git",
8
+ "directory": "packages/flp-config-inquirer"
9
+ },
10
+ "bugs": {
11
+ "url": "https://github.com/SAP/open-ux-tools/issues?q=is%3Aopen+is%3Aissue+label%3Abug+label%3Aflp-config-inquirer"
12
+ },
13
+ "license": "Apache-2.0",
14
+ "main": "dist/index.js",
15
+ "files": [
16
+ "LICENSE",
17
+ "dist",
18
+ "!dist/*.map",
19
+ "!dist/**/*.map"
20
+ ],
21
+ "dependencies": {
22
+ "i18next": "23.5.1",
23
+ "lodash": "4.17.21",
24
+ "@sap-ux/inquirer-common": "0.5.4",
25
+ "@sap-ux/btp-utils": "0.17.0",
26
+ "@sap-ux/project-input-validator": "0.3.4",
27
+ "@sap-ux/fiori-generator-shared": "0.7.10"
28
+ },
29
+ "devDependencies": {
30
+ "@sap-devx/yeoman-ui-types": "1.14.4",
31
+ "@types/inquirer": "8.2.6",
32
+ "@types/lodash": "4.14.202",
33
+ "inquirer": "8.2.6"
34
+ },
35
+ "engines": {
36
+ "node": ">=18.x"
37
+ },
38
+ "scripts": {
39
+ "build": "tsc --build",
40
+ "clean": "rimraf --glob dist test/test-output coverage *.tsbuildinfo",
41
+ "watch": "tsc --watch",
42
+ "lint": "eslint . --ext .ts",
43
+ "lint:fix": "eslint . --ext .ts --fix",
44
+ "test": "jest --ci --forceExit --detectOpenHandles --colors --passWithNoTests",
45
+ "test-u": "jest --ci --forceExit --detectOpenHandles --colors -u",
46
+ "link": "pnpm link --global",
47
+ "unlink": "pnpm unlink --global"
48
+ }
49
+ }