@sap-ux/fiori-generator-shared 0.12.16 → 0.13.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/dist/index.d.ts CHANGED
@@ -7,7 +7,7 @@ export * from './logging/logWrapper';
7
7
  export * from './types';
8
8
  export { getPackageScripts } from './npm-package-scripts/getPackageScripts';
9
9
  export { getBootstrapResourceUrls } from './ui5/ui5';
10
- export { getDefaultTargetFolder, isExtensionInstalled } from './vscode-helpers/vscode-helpers';
10
+ export { getDefaultTargetFolder, isExtensionInstalled, isCommandRegistered } from './vscode-helpers/vscode-helpers';
11
11
  export { generateAppGenInfo } from './app-gen-info';
12
12
  export { getHostEnvironment } from './environment';
13
13
  export { getFlpId, getSemanticObject } from './app-helpers/app-helpers';
package/dist/index.js CHANGED
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.getSemanticObject = exports.getFlpId = exports.getHostEnvironment = exports.generateAppGenInfo = exports.isExtensionInstalled = exports.getDefaultTargetFolder = exports.getBootstrapResourceUrls = exports.getPackageScripts = void 0;
17
+ exports.getSemanticObject = exports.getFlpId = exports.getHostEnvironment = exports.generateAppGenInfo = exports.isCommandRegistered = exports.isExtensionInstalled = exports.getDefaultTargetFolder = exports.getBootstrapResourceUrls = exports.getPackageScripts = void 0;
18
18
  __exportStar(require("./cap"), exports);
19
19
  __exportStar(require("./constants"), exports);
20
20
  __exportStar(require("./environment"), exports);
@@ -29,6 +29,7 @@ Object.defineProperty(exports, "getBootstrapResourceUrls", { enumerable: true, g
29
29
  var vscode_helpers_1 = require("./vscode-helpers/vscode-helpers");
30
30
  Object.defineProperty(exports, "getDefaultTargetFolder", { enumerable: true, get: function () { return vscode_helpers_1.getDefaultTargetFolder; } });
31
31
  Object.defineProperty(exports, "isExtensionInstalled", { enumerable: true, get: function () { return vscode_helpers_1.isExtensionInstalled; } });
32
+ Object.defineProperty(exports, "isCommandRegistered", { enumerable: true, get: function () { return vscode_helpers_1.isCommandRegistered; } });
32
33
  var app_gen_info_1 = require("./app-gen-info");
33
34
  Object.defineProperty(exports, "generateAppGenInfo", { enumerable: true, get: function () { return app_gen_info_1.generateAppGenInfo; } });
34
35
  var environment_1 = require("./environment");
@@ -7,13 +7,22 @@ export declare const YEOMANUI_TARGET_FOLDER_CONFIG_PROP = "ApplicationWizard.Tar
7
7
  */
8
8
  export declare function getDefaultTargetFolder(vscode: any): string | undefined;
9
9
  /**
10
- * Check for an installed extension, optionally specifying a minimum version.
11
- * Note, this does not check for activation state of specified extension.
10
+ * Check for an installed extension, optionally specifying a minimum version and activation state.
11
+ * Note, this does not check for activation state unless `isActive` is specified.
12
12
  *
13
13
  * @param vscode - vscode instance
14
14
  * @param extensionId - the id of the extension to find
15
15
  * @param minVersion - the minimum version of the specified extension, lower versions will not be returned. Must be a valid SemVer string.
16
- * @returns true if the extension is installed and the version is >= minVersion (if provided), false otherwise
16
+ * @param isActive - If `true`, the function will only return `true` if the extension is also active. Defaults to `true`.
17
+ * @returns true if the extension is installed, the version is >= minVersion, and is active, false otherwise
17
18
  */
18
- export declare function isExtensionInstalled(vscode: any, extensionId: string, minVersion?: string): boolean;
19
+ export declare function isExtensionInstalled(vscode: any, extensionId: string, minVersion?: string, isActive?: boolean): boolean;
20
+ /**
21
+ * Check if a specific command is registered in VS Code.
22
+ *
23
+ * @param vscode - vscode instance
24
+ * @param commandId - the id of the command to check
25
+ * @returns true if the command is registered, else false
26
+ */
27
+ export declare function isCommandRegistered(vscode: any, commandId: string): Promise<boolean>;
19
28
  //# sourceMappingURL=vscode-helpers.d.ts.map
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.YEOMANUI_TARGET_FOLDER_CONFIG_PROP = void 0;
7
7
  exports.getDefaultTargetFolder = getDefaultTargetFolder;
8
8
  exports.isExtensionInstalled = isExtensionInstalled;
9
+ exports.isCommandRegistered = isCommandRegistered;
9
10
  const fs_1 = require("fs");
10
11
  const os_1 = __importDefault(require("os"));
11
12
  const path_1 = require("path");
@@ -40,23 +41,42 @@ function getDefaultTargetFolder(vscode) {
40
41
  return (0, fs_1.existsSync)(DEFAULT_PROJECTS_FOLDER) ? DEFAULT_PROJECTS_FOLDER : undefined;
41
42
  }
42
43
  /**
43
- * Check for an installed extension, optionally specifying a minimum version.
44
- * Note, this does not check for activation state of specified extension.
44
+ * Check for an installed extension, optionally specifying a minimum version and activation state.
45
+ * Note, this does not check for activation state unless `isActive` is specified.
45
46
  *
46
47
  * @param vscode - vscode instance
47
48
  * @param extensionId - the id of the extension to find
48
49
  * @param minVersion - the minimum version of the specified extension, lower versions will not be returned. Must be a valid SemVer string.
49
- * @returns true if the extension is installed and the version is >= minVersion (if provided), false otherwise
50
+ * @param isActive - If `true`, the function will only return `true` if the extension is also active. Defaults to `true`.
51
+ * @returns true if the extension is installed, the version is >= minVersion, and is active, false otherwise
50
52
  */
51
- function isExtensionInstalled(vscode, extensionId, minVersion) {
53
+ function isExtensionInstalled(vscode, extensionId, minVersion, isActive = true) {
52
54
  const foundExt = vscode?.extensions?.getExtension(extensionId);
53
55
  if (foundExt) {
54
56
  const extVersion = (0, semver_1.coerce)(foundExt.packageJSON.version);
55
57
  if (extVersion) {
56
- // Check installed ver is >= minVersion or return true if minVersion is not specified
57
- return !(minVersion && (0, semver_1.lt)(extVersion, minVersion));
58
+ // If a minimum version is specified and the extension's version is less than it, return false.
59
+ if (minVersion && (0, semver_1.lt)(extVersion, minVersion)) {
60
+ return false;
61
+ }
62
+ // If the caller explicitly requires the extension to check if active, and it's not then return false.
63
+ if (isActive && !foundExt.isActive) {
64
+ return false;
65
+ }
66
+ return true;
58
67
  }
59
68
  }
60
69
  return false;
61
70
  }
71
+ /**
72
+ * Check if a specific command is registered in VS Code.
73
+ *
74
+ * @param vscode - vscode instance
75
+ * @param commandId - the id of the command to check
76
+ * @returns true if the command is registered, else false
77
+ */
78
+ async function isCommandRegistered(vscode, commandId) {
79
+ const commands = await vscode.commands.getCommands();
80
+ return commands.includes(commandId);
81
+ }
62
82
  //# sourceMappingURL=vscode-helpers.js.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sap-ux/fiori-generator-shared",
3
3
  "description": "Commonly used shared functionality and types to support the fiori generator.",
4
- "version": "0.12.16",
4
+ "version": "0.13.0",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/SAP/open-ux-tools.git",