@sap-ux/ui5-library-inquirer 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -15,7 +15,7 @@ Pnpm
15
15
 
16
16
  ## Usage
17
17
 
18
- Example with Yeoman generator :
18
+ Example with Yeoman generator no options, e.g. cli prompting only :
19
19
 
20
20
  ```javascript
21
21
  import Generator from 'yeoman-generator';
@@ -51,6 +51,51 @@ export default class UI5LibraryGenerator extends Generator {
51
51
  }
52
52
  ```
53
53
 
54
+ Example with Yeoman generator passing options with adapter, e.g. @sap-devx/yeoman-ui integration :
55
+
56
+ ```javascript
57
+ import Generator from 'yeoman-generator';
58
+ import { generate, type UI5LibConfig } from '@sap-ux/ui5-library-writer';
59
+ import { prompt, type UI5LibraryAnswers } from '@sap-ux/ui5-library-inquirer';
60
+
61
+ export default class UI5LibraryGenerator extends Generator {
62
+ answers: UI5LibraryAnswers = {};
63
+ targetFolder: string;
64
+
65
+ constructor(args: string | string[], opts: Generator.GeneratorOptions) {
66
+ super(args, opts);
67
+ this.targetFolder = opts.targetFolder;
68
+ }
69
+
70
+ public async prompting(): Promise<void> {
71
+ const answers = await prompt(
72
+ {
73
+ targetFolder: this.targetFolder,
74
+ includeSeparators: true,
75
+ useAutocomplete: false
76
+ },
77
+ this.env?.adapter
78
+ );
79
+ Object.assign(this.answers, answers);
80
+ }
81
+
82
+ public async writing(): Promise<void> {
83
+ const ui5Lib: UI5LibConfig = {
84
+ libraryName: this.answers.libraryName,
85
+ namespace: this.answers.namespace,
86
+ framework: 'SAPUI5',
87
+ frameworkVersion: this.answers.ui5Version,
88
+ author: 'Fiori tools',
89
+ typescript: this.answers.enableTypescript
90
+ };
91
+
92
+ try {
93
+ await generate(this.answers.targetFolder, ui5Lib, this.fs);
94
+ } catch (e) {}
95
+ }
96
+ }
97
+ ```
98
+
54
99
  ## Keywords
55
100
  SAP Fiori Elements
56
101
  Yeoman
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { type Question } from 'inquirer';
2
- import type { UI5LibraryAnswers, UI5LibraryPromptOptions } from './types';
2
+ import type { InquirerAdapter, UI5LibraryAnswers, UI5LibraryPromptOptions } from './types';
3
3
  /**
4
4
  * Get the inquirer prompts for ui5 library inquirer.
5
5
  *
@@ -10,9 +10,10 @@ declare function getPrompts(promptOptions?: UI5LibraryPromptOptions): Promise<Qu
10
10
  /**
11
11
  * Prompt for ui5 library generation inputs.
12
12
  *
13
- * @param promptOptions - options that can control some of the prompt behaviour. See {@link UI5LibraryPromptOptions} for details
13
+ * @param promptOptions - options that can control some of the prompt behavior. See {@link UI5LibraryPromptOptions} for details
14
+ * @param adapter - optionally provide references to a calling inquirer instance, this supports integration to Yeoman generators, for example
14
15
  * @returns the prompt answers
15
16
  */
16
- declare function prompt(promptOptions?: UI5LibraryPromptOptions): Promise<UI5LibraryAnswers>;
17
+ declare function prompt(promptOptions?: UI5LibraryPromptOptions, adapter?: InquirerAdapter): Promise<UI5LibraryAnswers>;
17
18
  export { getPrompts, prompt, type UI5LibraryPromptOptions, type UI5LibraryAnswers };
18
19
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -42,16 +42,18 @@ exports.getPrompts = getPrompts;
42
42
  /**
43
43
  * Prompt for ui5 library generation inputs.
44
44
  *
45
- * @param promptOptions - options that can control some of the prompt behaviour. See {@link UI5LibraryPromptOptions} for details
45
+ * @param promptOptions - options that can control some of the prompt behavior. See {@link UI5LibraryPromptOptions} for details
46
+ * @param adapter - optionally provide references to a calling inquirer instance, this supports integration to Yeoman generators, for example
46
47
  * @returns the prompt answers
47
48
  */
48
- function prompt(promptOptions) {
49
+ function prompt(promptOptions, adapter) {
49
50
  return __awaiter(this, void 0, void 0, function* () {
50
51
  const ui5LibPrompts = yield exports.getPrompts(promptOptions);
52
+ const pm = adapter ? adapter.promptModule : inquirer_1.default;
51
53
  if (promptOptions === null || promptOptions === void 0 ? void 0 : promptOptions.useAutocomplete) {
52
- inquirer_1.default.registerPrompt('autocomplete', inquirer_autocomplete_prompt_1.default);
54
+ pm.registerPrompt('autocomplete', inquirer_autocomplete_prompt_1.default);
53
55
  }
54
- return inquirer_1.default.prompt(ui5LibPrompts);
56
+ return adapter ? adapter.prompt(ui5LibPrompts) : inquirer_1.default.prompt(ui5LibPrompts);
55
57
  });
56
58
  }
57
59
  exports.prompt = prompt;
package/dist/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { ConfirmQuestion as BaseConfirmQuestion, InputQuestion as BaseInputQuestion, ListQuestion as BaseListQuestion, Answers, ListChoiceOptions } from 'inquirer';
1
+ import type { ConfirmQuestion as BaseConfirmQuestion, InputQuestion as BaseInputQuestion, ListQuestion as BaseListQuestion, Answers, ListChoiceOptions, PromptFunction, PromptModule } from 'inquirer';
2
2
  export interface UI5LibraryAnswers {
3
3
  libraryName?: string;
4
4
  namespace?: string;
@@ -23,6 +23,10 @@ export interface UI5LibraryPromptOptions {
23
23
  export interface UI5VersionChoice extends ListChoiceOptions {
24
24
  value: string;
25
25
  }
26
+ export interface InquirerAdapter {
27
+ prompt: PromptFunction;
28
+ promptModule: PromptModule;
29
+ }
26
30
  /**
27
31
  *
28
32
  * Remove when YUI specific types are available from `"@sap-devx/yeoman-ui-types`
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sap-ux/ui5-library-inquirer",
3
3
  "description": "Prompts module that can provide prompts for UI5 library writer",
4
- "version": "0.1.1",
4
+ "version": "0.2.0",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/SAP/open-ux-tools.git",
@@ -25,11 +25,11 @@
25
25
  "inquirer": "8.2.6",
26
26
  "inquirer-autocomplete-prompt": "2.0.1",
27
27
  "@sap-ux/project-input-validator": "0.2.1",
28
- "@sap-ux/ui5-info": "0.2.0"
28
+ "@sap-ux/ui5-info": "0.2.1"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@types/inquirer-autocomplete-prompt": "2.0.1",
32
- "@types/inquirer": "8.2.7"
32
+ "@types/inquirer": "8.2.6"
33
33
  },
34
34
  "engines": {
35
35
  "pnpm": ">=6.26.1 < 7.0.0 || >=7.1.0",