@sap-ux/inquirer-common 0.4.6 → 0.4.7

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/dist/i18n.js CHANGED
@@ -3,7 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.t = exports.initI18nInquirerCommon = void 0;
6
+ exports.initI18nInquirerCommon = initI18nInquirerCommon;
7
+ exports.t = t;
7
8
  const i18next_1 = __importDefault(require("i18next"));
8
9
  const inquirer_common_i18n_json_1 = __importDefault(require("./translations/inquirer-common.i18n.json"));
9
10
  const inquirerCommonI18nNamespace = 'inquirer-common';
@@ -13,7 +14,6 @@ const inquirerCommonI18nNamespace = 'inquirer-common';
13
14
  async function initI18nInquirerCommon() {
14
15
  await i18next_1.default.init({ lng: 'en', fallbackLng: 'en' }, () => i18next_1.default.addResourceBundle('en', inquirerCommonI18nNamespace, inquirer_common_i18n_json_1.default));
15
16
  }
16
- exports.initI18nInquirerCommon = initI18nInquirerCommon;
17
17
  /**
18
18
  * Helper function facading the call to i18next. Unless a namespace option is provided the local namespace will be used.
19
19
  *
@@ -27,7 +27,6 @@ function t(key, options) {
27
27
  }
28
28
  return i18next_1.default.t(key, options);
29
29
  }
30
- exports.t = t;
31
30
  initI18nInquirerCommon().catch(() => {
32
31
  // Needed for lint
33
32
  });
@@ -3,7 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.extendWithOptions = exports.withCondition = exports.applyExtensionFunction = exports.extendValidate = exports.extendAdditionalMessages = void 0;
6
+ exports.extendAdditionalMessages = extendAdditionalMessages;
7
+ exports.extendValidate = extendValidate;
8
+ exports.applyExtensionFunction = applyExtensionFunction;
9
+ exports.withCondition = withCondition;
10
+ exports.extendWithOptions = extendWithOptions;
7
11
  const cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
8
12
  /**
9
13
  * Extends an additionalMessages function.
@@ -27,7 +31,6 @@ function extendAdditionalMessages(question, addMsgFunc, promptState) {
27
31
  return typeof addMsgs === 'function' ? addMsgs(value, previousAnswers) : undefined;
28
32
  };
29
33
  }
30
- exports.extendAdditionalMessages = extendAdditionalMessages;
31
34
  /**
32
35
  * Extends a validate function. The extended function will be called first.
33
36
  *
@@ -48,7 +51,6 @@ function extendValidate(question, validateFunc, promptState) {
48
51
  return typeof validate === 'function' ? validate(value, previousAnswers) : true;
49
52
  };
50
53
  }
51
- exports.extendValidate = extendValidate;
52
54
  /**
53
55
  * Extend the existing prompt property function with the one specified in prompt options or add as new.
54
56
  *
@@ -69,7 +71,6 @@ function applyExtensionFunction(question, promptOption, funcName, promptState) {
69
71
  question = Object.assign(question, { [funcName]: extendedFunc });
70
72
  return question;
71
73
  }
72
- exports.applyExtensionFunction = applyExtensionFunction;
73
74
  /**
74
75
  * Adds additional conditions to the provided questions.
75
76
  *
@@ -104,7 +105,6 @@ function withCondition(questions, condition) {
104
105
  });
105
106
  return questions;
106
107
  }
107
- exports.withCondition = withCondition;
108
108
  /**
109
109
  * Updates questions with extensions for specific properties. Only `validate`, `default` and `additionalMessages` are currently supported.
110
110
  *
@@ -133,5 +133,4 @@ function extendWithOptions(questions, promptOptions, promptState) {
133
133
  });
134
134
  return questions;
135
135
  }
136
- exports.extendWithOptions = extendWithOptions;
137
136
  //# sourceMappingURL=helpers.js.map
@@ -23,17 +23,18 @@ export declare function searchChoices(searchVal: string, searchList: ListChoiceO
23
23
  *
24
24
  * @param versions ui5Versions
25
25
  * @param includeSeparators Include a separator to visually identify groupings, if false then grouping info is included in each entry as additional name text
26
- * @param defaultChoice optional, provides an additional version choice entry that is added as the first entry in the version choices and sets as the default
26
+ * @param defaultChoice optional, provides an additional version choice entry that is added as the first entry in the version choices (if it does not already exist in the version list) and sets as the default
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
30
  /**
31
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.
32
+ * Note, if the provided version is a snapshot version, the closest provided version is returned.
33
+ * Otherwise if the default choice is not found in the provided versions, it will still be returned.
33
34
  *
34
35
  * @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
36
+ * @param defaultChoice - optional default choice to be used
37
+ * @returns The default UI5 version choice or the latest provided version
37
38
  */
38
39
  export declare function getDefaultUI5VersionChoice(ui5Versions: UI5Version[], defaultChoice?: UI5VersionChoice): UI5VersionChoice | undefined;
39
40
  //# sourceMappingURL=utility.d.ts.map
@@ -23,7 +23,10 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.getDefaultUI5VersionChoice = exports.ui5VersionsGrouped = exports.searchChoices = exports.getUI5ThemesChoices = void 0;
26
+ exports.getUI5ThemesChoices = getUI5ThemesChoices;
27
+ exports.searchChoices = searchChoices;
28
+ exports.ui5VersionsGrouped = ui5VersionsGrouped;
29
+ exports.getDefaultUI5VersionChoice = getDefaultUI5VersionChoice;
27
30
  const ui5_info_1 = require("@sap-ux/ui5-info");
28
31
  const fuzzy = __importStar(require("fuzzy"));
29
32
  const semver_1 = require("semver");
@@ -42,7 +45,6 @@ function getUI5ThemesChoices(ui5Version) {
42
45
  value: theme.id
43
46
  }));
44
47
  }
45
- exports.getUI5ThemesChoices = getUI5ThemesChoices;
46
48
  /**
47
49
  * Finds the search value in the provided list using `fuzzy` search.
48
50
  *
@@ -60,14 +62,13 @@ function searchChoices(searchVal, searchList) {
60
62
  .map((el) => el.original)
61
63
  : searchList;
62
64
  }
63
- exports.searchChoices = searchChoices;
64
65
  /**
65
66
  * Creates a list of UI5 Versions prompt choices, adding additional maintenance info for use in prompts
66
67
  * and grouping according to maintenance status.
67
68
  *
68
69
  * @param versions ui5Versions
69
70
  * @param includeSeparators Include a separator to visually identify groupings, if false then grouping info is included in each entry as additional name text
70
- * @param defaultChoice optional, provides an additional version choice entry that is added as the first entry in the version choices and sets as the default
71
+ * @param defaultChoice optional, provides an additional version choice entry that is added as the first entry in the version choices (if it does not already exist in the version list) and sets as the default
71
72
  * @returns Array of ui5 version choices and separators if applicable, grouped by maintenance state
72
73
  */
73
74
  function ui5VersionsGrouped(versions, includeSeparators = false, defaultChoice) {
@@ -98,24 +99,52 @@ function ui5VersionsGrouped(versions, includeSeparators = false, defaultChoice)
98
99
  }
99
100
  const versionChoices = [...maintChoices, ...notMaintChoices];
100
101
  if (defaultChoice) {
101
- versionChoices.unshift(defaultChoice);
102
+ const index = versionChoices.findIndex((choice) => choice.value === defaultChoice.value);
103
+ if (index === -1) {
104
+ // adds default choice to the top of the list
105
+ versionChoices.unshift(defaultChoice);
106
+ }
102
107
  }
103
108
  return versionChoices;
104
109
  }
105
- exports.ui5VersionsGrouped = ui5VersionsGrouped;
110
+ /**
111
+ * Will either return the UI5 version that is the closest to the default choice version or simply the version that is passed to it.
112
+ *
113
+ * @param ui5Versions - UI5 versions ordered by version descending latest first
114
+ * @param useClosestVersion - whether to use the closest available version to the default choice
115
+ * @param defaultChoiceVersion - default version chosen
116
+ * @returns - ui5 version to be used as default
117
+ */
118
+ function findDefaultUI5Version(ui5Versions, useClosestVersion, defaultChoiceVersion) {
119
+ let version;
120
+ if (useClosestVersion) {
121
+ version = ui5Versions.find((ui5Ver) => (0, semver_1.lte)(ui5Ver.version, defaultChoiceVersion));
122
+ }
123
+ else {
124
+ version = {
125
+ version: defaultChoiceVersion.version
126
+ };
127
+ }
128
+ return version;
129
+ }
106
130
  /**
107
131
  * 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.
132
+ * Note, if the provided version is a snapshot version, the closest provided version is returned.
133
+ * Otherwise if the default choice is not found in the provided versions, it will still be returned.
109
134
  *
110
135
  * @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
136
+ * @param defaultChoice - optional default choice to be used
137
+ * @returns The default UI5 version choice or the latest provided version
113
138
  */
114
139
  function getDefaultUI5VersionChoice(ui5Versions, defaultChoice) {
140
+ let useClosestVersion = false;
115
141
  if (defaultChoice) {
142
+ if (defaultChoice.value.toLowerCase().endsWith('snapshot')) {
143
+ useClosestVersion = true;
144
+ }
116
145
  const defaultChoiceVersion = (0, semver_1.coerce)(defaultChoice.value);
117
146
  if (defaultChoiceVersion !== null) {
118
- const version = ui5Versions.find((ui5Ver) => (0, semver_1.lte)(ui5Ver.version, defaultChoiceVersion));
147
+ const version = findDefaultUI5Version(ui5Versions, useClosestVersion, defaultChoiceVersion);
119
148
  if (version) {
120
149
  // if the versions are an exact match use the name (UI label) from the default choice as this may use a custom name
121
150
  return {
@@ -135,5 +164,4 @@ function getDefaultUI5VersionChoice(ui5Versions, defaultChoice) {
135
164
  }
136
165
  return undefined;
137
166
  }
138
- exports.getDefaultUI5VersionChoice = getDefaultUI5VersionChoice;
139
167
  //# sourceMappingURL=utility.js.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.4.6",
4
+ "version": "0.4.7",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/SAP/open-ux-tools.git",