@sap-ux/inquirer-common 0.2.2 → 0.2.4

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,4 +27,13 @@ export declare function searchChoices(searchVal: string, searchList: ListChoiceO
27
27
  * @returns Array of ui5 version choices and separators if applicable, grouped by maintenance state
28
28
  */
29
29
  export declare function ui5VersionsGrouped(versions: UI5Version[], includeSeparators?: boolean, defaultChoice?: UI5VersionChoice): (UI5VersionChoice | Separator)[];
30
+ /**
31
+ * Get the default UI5 version choice that should be selected based on the provided default choice.
32
+ * Note that if the default choice is not found in the provided versions, the closest provided version is returned.
33
+ *
34
+ * @param ui5Versions - UI5 versions ordered by version descending latest first
35
+ * @param [defaultChoice] - optional default choice to use if found in the provided versions, otherwise the closest provided version is returned
36
+ * @returns The default UI5 version choice that is closest to the provided default choice or the latest provided version
37
+ */
38
+ export declare function getDefaultUI5VersionChoice(ui5Versions: UI5Version[], defaultChoice?: UI5VersionChoice): UI5VersionChoice | undefined;
30
39
  //# sourceMappingURL=utility.d.ts.map
@@ -23,11 +23,12 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.ui5VersionsGrouped = exports.searchChoices = exports.getUI5ThemesChoices = void 0;
26
+ exports.getDefaultUI5VersionChoice = exports.ui5VersionsGrouped = exports.searchChoices = exports.getUI5ThemesChoices = void 0;
27
27
  const fuzzy = __importStar(require("fuzzy"));
28
28
  const i18n_1 = require("../i18n");
29
29
  const ui5_info_1 = require("@sap-ux/ui5-info");
30
30
  const separator_1 = require("./separator");
31
+ const semver_1 = require("semver");
31
32
  /**
32
33
  * Get the UI5 themes as prompt choices applicable for the specified UI5 version.
33
34
  *
@@ -102,4 +103,38 @@ function ui5VersionsGrouped(versions, includeSeparators = false, defaultChoice)
102
103
  return versionChoices;
103
104
  }
104
105
  exports.ui5VersionsGrouped = ui5VersionsGrouped;
106
+ /**
107
+ * Get the default UI5 version choice that should be selected based on the provided default choice.
108
+ * Note that if the default choice is not found in the provided versions, the closest provided version is returned.
109
+ *
110
+ * @param ui5Versions - UI5 versions ordered by version descending latest first
111
+ * @param [defaultChoice] - optional default choice to use if found in the provided versions, otherwise the closest provided version is returned
112
+ * @returns The default UI5 version choice that is closest to the provided default choice or the latest provided version
113
+ */
114
+ function getDefaultUI5VersionChoice(ui5Versions, defaultChoice) {
115
+ var _a;
116
+ if (defaultChoice) {
117
+ const defaultChoiceVersion = (0, semver_1.coerce)(defaultChoice.value);
118
+ if (defaultChoiceVersion !== null) {
119
+ const version = ui5Versions.find((ui5Ver) => (0, semver_1.lte)(ui5Ver.version, defaultChoiceVersion));
120
+ if (version) {
121
+ // if the versions are an exact match use the name (UI label) from the default choice as this may use a custom name
122
+ return {
123
+ name: (0, semver_1.eq)(version.version, defaultChoice.value) ? defaultChoice.name : version.version,
124
+ value: version.version
125
+ };
126
+ }
127
+ }
128
+ }
129
+ // defaultChoice was not coercable, not found or not provided, return the latest version from the ui5 versions provided
130
+ const defaultVersion = (_a = ui5Versions.find((ui5Ver) => ui5Ver.default && ui5Ver.version)) === null || _a === void 0 ? void 0 : _a.version;
131
+ if (defaultVersion) {
132
+ return {
133
+ name: defaultVersion,
134
+ value: defaultVersion
135
+ };
136
+ }
137
+ return undefined;
138
+ }
139
+ exports.getDefaultUI5VersionChoice = getDefaultUI5VersionChoice;
105
140
  //# sourceMappingURL=utility.js.map
package/dist/types.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { type IMessageSeverity } from '@sap-devx/yeoman-ui-types';
2
- import type { Answers, ConfirmQuestion as BaseConfirmQuestion, InputQuestion as BaseInputQuestion, ListQuestion as BaseListQuestion, ListChoiceOptions, PromptFunction, PromptModule, Question } from 'inquirer';
2
+ import type { Answers, ConfirmQuestion as BaseConfirmQuestion, InputQuestion as BaseInputQuestion, ListQuestion as BaseListQuestion, CheckboxQuestion as BaseCheckBoxQuestion, ListChoiceOptions, PromptFunction, PromptModule, Question } from 'inquirer';
3
3
  export interface UI5VersionChoice extends ListChoiceOptions {
4
4
  /**
5
5
  * UI5 semantic version
@@ -62,4 +62,8 @@ export interface InputQuestion<A extends Answers = Answers> extends BaseInputQue
62
62
  name: YUIQuestion['name'];
63
63
  guiOptions?: YUIQuestion['guiOptions'];
64
64
  }
65
+ export interface CheckBoxQuestion<A extends Answers = Answers> extends BaseCheckBoxQuestion<A> {
66
+ name: YUIQuestion['name'];
67
+ guiOptions?: YUIQuestion['guiOptions'];
68
+ }
65
69
  //# sourceMappingURL=types.d.ts.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sap-ux/inquirer-common",
3
3
  "description": "Commonly used shared functionality and types to support inquirer modules.",
4
- "version": "0.2.2",
4
+ "version": "0.2.4",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/SAP/open-ux-tools.git",
@@ -23,11 +23,13 @@
23
23
  "i18next": "23.5.1",
24
24
  "chalk": "4.1.2",
25
25
  "figures": "3.2.0",
26
+ "semver": "7.5.4",
26
27
  "@sap-ux/ui5-info": "0.3.3"
27
28
  },
28
29
  "devDependencies": {
29
30
  "@sap-devx/yeoman-ui-types": "1.14.4",
30
- "@types/inquirer": "8.2.6"
31
+ "@types/inquirer": "8.2.6",
32
+ "@types/semver": "7.5.4"
31
33
  },
32
34
  "engines": {
33
35
  "node": ">=18.x"