@sap-ux/mockserver-config-writer 0.2.2 → 0.3.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.
@@ -10,9 +10,10 @@ export declare function getMainServiceDataSource(manifest: Manifest): ManifestNa
10
10
  * Get the data sources of type 'OData' from manifest.
11
11
  *
12
12
  * @param manifest - the parsed manifest.json
13
+ * @param dataSourceType - optional to specify the type of OData sources to filter
13
14
  * @returns data sources of type 'OData'
14
15
  */
15
- export declare function getODataSources(manifest: Manifest): {
16
+ export declare function getODataSources(manifest: Manifest, dataSourceType?: ManifestNamespace.DataSourceEnum['type']): {
16
17
  [k: string]: ManifestNamespace.DataSource;
17
18
  };
18
19
  //# sourceMappingURL=app-info.d.ts.map
package/dist/app-info.js CHANGED
@@ -24,14 +24,15 @@ exports.getMainServiceDataSource = getMainServiceDataSource;
24
24
  * Get the data sources of type 'OData' from manifest.
25
25
  *
26
26
  * @param manifest - the parsed manifest.json
27
+ * @param dataSourceType - optional to specify the type of OData sources to filter
27
28
  * @returns data sources of type 'OData'
28
29
  */
29
- function getODataSources(manifest) {
30
+ function getODataSources(manifest, dataSourceType = 'OData') {
30
31
  var _a;
31
32
  const result = {};
32
33
  const dataSources = ((_a = manifest['sap.app']) === null || _a === void 0 ? void 0 : _a.dataSources) || {};
33
34
  for (const dataSource in dataSources) {
34
- if (dataSources[dataSource].uri && dataSources[dataSource].type === 'OData') {
35
+ if (dataSources[dataSource].uri && dataSources[dataSource].type === dataSourceType) {
35
36
  result[dataSource] = dataSources[dataSource];
36
37
  }
37
38
  }
@@ -40,13 +40,21 @@ function enhanceYaml(fs, basePath, webappPath, config) {
40
40
  let mockConfig;
41
41
  const manifest = fs.readJSON((0, path_1.join)(webappPath, 'manifest.json'));
42
42
  const mockserverPath = (config === null || config === void 0 ? void 0 : config.path) || ((_a = (0, app_info_1.getMainServiceDataSource)(manifest)) === null || _a === void 0 ? void 0 : _a.uri);
43
+ const annotationSource = Object.values((0, app_info_1.getODataSources)(manifest, 'ODataAnnotation'));
44
+ const annotationsConfig = annotationSource.map((annotation) => {
45
+ var _a;
46
+ return ({
47
+ localPath: `./webapp/${(_a = annotation.settings) === null || _a === void 0 ? void 0 : _a.localUri}`,
48
+ urlPath: annotation.uri
49
+ });
50
+ });
43
51
  if (fs.exists(ui5MockYamlPath)) {
44
52
  mockConfig = yield updateUi5MockYamlConfig(fs, ui5MockYamlPath, mockserverPath);
45
53
  }
46
54
  else {
47
55
  mockConfig = fs.exists((0, path_1.join)(basePath, 'ui5.yaml'))
48
56
  ? yield generateUi5MockYamlBasedOnUi5Yaml(fs, basePath, mockserverPath)
49
- : yield generateNewUi5MockYamlConfig(((_b = manifest['sap.app']) === null || _b === void 0 ? void 0 : _b.id) || '', mockserverPath);
57
+ : yield generateNewUi5MockYamlConfig(((_b = manifest['sap.app']) === null || _b === void 0 ? void 0 : _b.id) || '', mockserverPath, annotationsConfig);
50
58
  }
51
59
  const yaml = mockConfig.toString();
52
60
  fs.write(ui5MockYamlPath, yaml);
@@ -89,16 +97,17 @@ function generateUi5MockYamlBasedOnUi5Yaml(fs, basePath, path) {
89
97
  *
90
98
  * @param appId - application id
91
99
  * @param [path] - optional url path the mockserver listens to
100
+ * @param annotationsConfig - optional annotations config to add to mockserver middleware
92
101
  * @returns {*} {Promise<UI5Config>} - Update Yaml Doc
93
102
  */
94
- function generateNewUi5MockYamlConfig(appId, path) {
103
+ function generateNewUi5MockYamlConfig(appId, path, annotationsConfig) {
95
104
  return __awaiter(this, void 0, void 0, function* () {
96
105
  const ui5MockYaml = yield ui5_config_1.UI5Config.newInstance('# yaml-language-server: $schema=https://sap.github.io/ui5-tooling/schema/ui5.yaml.json\n\nspecVersion: "2.5"');
97
106
  ui5MockYaml.setMetadata({ name: appId });
98
107
  ui5MockYaml.setType('application');
99
108
  ui5MockYaml.addFioriToolsProxydMiddleware({ ui5: {} });
100
109
  ui5MockYaml.addFioriToolsAppReloadMiddleware();
101
- ui5MockYaml.addMockServerMiddleware(path);
110
+ ui5MockYaml.addMockServerMiddleware(path, annotationsConfig);
102
111
  return ui5MockYaml;
103
112
  });
104
113
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sap-ux/mockserver-config-writer",
3
3
  "description": "Add or update configuration for SAP Fiori tools mockserver",
4
- "version": "0.2.2",
4
+ "version": "0.3.0",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/SAP/open-ux-tools.git",
@@ -22,17 +22,16 @@
22
22
  "i18next": "20.6.1",
23
23
  "mem-fs": "2.1.0",
24
24
  "mem-fs-editor": "9.4.0",
25
- "@sap-ux/ui5-config": "0.21.0"
25
+ "@sap-ux/ui5-config": "0.22.0"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@types/mem-fs": "1.1.2",
29
29
  "@types/mem-fs-editor": "7.0.1",
30
30
  "@types/prompts": "2.4.4",
31
31
  "prompts": "2.4.2",
32
- "@sap-ux/project-access": "1.17.0"
32
+ "@sap-ux/project-access": "1.19.2"
33
33
  },
34
34
  "engines": {
35
- "pnpm": ">=6.26.1 < 7.0.0 || >=7.1.0",
36
35
  "node": ">=18.x"
37
36
  },
38
37
  "scripts": {