@sap-ux/odata-service-writer 0.27.35 → 0.27.37

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.
Files changed (2) hide show
  1. package/dist/update.js +53 -26
  2. package/package.json +3 -3
package/dist/update.js CHANGED
@@ -63,49 +63,73 @@ function extendBackendMiddleware(fs, service, ui5Config, ui5ConfigPath, update =
63
63
  fs.write(ui5ConfigPath, ui5Config.toString());
64
64
  }
65
65
  /**
66
- * Adds services data to ui5-*.yaml files.
67
- * Mockserver configuration for services and annotations are written using dataSources from manifest.json.
68
- * At the end, XML files for service annotations are created.
66
+ * Updates UI5 YAML configurations with backend middleware.
69
67
  *
70
- * @param {string} basePath - the root path of an existing UI5 application
71
- * @param {ProjectPaths} paths - paths to the project files (package.json, ui5.yaml, ui5-local.yaml and ui5-mock.yaml)
72
- * @param {string} templateRoot - path to the file templates
73
- * @param {EdmxOdataService} service - the OData service instance
74
- * @param {Editor} fs - the memfs editor instance
68
+ * @param fs - the memfs editor instance
69
+ * @param service - the OData service instance
70
+ * @param paths - paths to the project files
71
+ * @returns Object containing ui5Config and ui5LocalConfig instances
75
72
  */
76
- async function addServicesData(basePath, paths, templateRoot, service, fs) {
73
+ async function updateUI5YamlConfigs(fs, service, paths) {
77
74
  let ui5Config;
78
75
  let ui5LocalConfig;
79
- let ui5MockConfig;
80
76
  if (paths.ui5Yaml) {
81
77
  ui5Config = await ui5_config_1.UI5Config.newInstance(fs.read(paths.ui5Yaml));
82
- // Update ui5.yaml with backend middleware
83
78
  extendBackendMiddleware(fs, service, ui5Config, paths.ui5Yaml);
84
- // Update ui5-local.yaml with backend middleware
85
79
  if (paths.ui5LocalYaml) {
86
80
  ui5LocalConfig = await ui5_config_1.UI5Config.newInstance(fs.read(paths.ui5LocalYaml));
87
81
  extendBackendMiddleware(fs, service, ui5LocalConfig, paths.ui5LocalYaml);
88
82
  }
89
83
  }
84
+ return { ui5Config, ui5LocalConfig };
85
+ }
86
+ /**
87
+ * Generates mockserver configuration and updates related YAML files.
88
+ *
89
+ * @param basePath - the root path of an existing UI5 application
90
+ * @param paths - paths to the project files
91
+ * @param service - the OData service instance
92
+ * @param webappPath - path to webapp folder
93
+ * @param ui5LocalConfig - ui5-local.yaml configuration
94
+ * @param fs - the memfs editor instance
95
+ */
96
+ async function generateAndUpdateMockserverConfig(basePath, paths, service, webappPath, ui5LocalConfig, fs) {
97
+ const config = {
98
+ webappPath: webappPath,
99
+ ui5MockYamlConfig: {}
100
+ };
101
+ if (config.ui5MockYamlConfig && service.name && service.externalServices?.length) {
102
+ config.ui5MockYamlConfig.resolveExternalServiceReferences = {
103
+ [service.name]: true
104
+ };
105
+ }
106
+ await (0, mockserver_config_writer_1.generateMockserverConfig)(basePath, config, fs);
107
+ await generateMockserverMiddlewareBasedOnUi5MockYaml(fs, paths.ui5Yaml, paths.ui5LocalYaml, ui5LocalConfig);
108
+ if (paths.ui5MockYaml) {
109
+ const ui5MockConfig = await ui5_config_1.UI5Config.newInstance(fs.read(paths.ui5MockYaml));
110
+ extendBackendMiddleware(fs, service, ui5MockConfig, paths.ui5MockYaml);
111
+ }
112
+ }
113
+ /**
114
+ * Adds services data to ui5-*.yaml files.
115
+ * Mockserver configuration for services and annotations are written using dataSources from manifest.json.
116
+ * At the end, XML files for service annotations are created.
117
+ *
118
+ * @param {string} basePath - the root path of an existing UI5 application
119
+ * @param {ProjectPaths} paths - paths to the project files (package.json, ui5.yaml, ui5-local.yaml and ui5-mock.yaml)
120
+ * @param {string} templateRoot - path to the file templates
121
+ * @param {EdmxOdataService} service - the OData service instance
122
+ * @param {Editor} fs - the memfs editor instance
123
+ */
124
+ async function addServicesData(basePath, paths, templateRoot, service, fs) {
125
+ const { ui5Config, ui5LocalConfig } = await updateUI5YamlConfigs(fs, service, paths);
126
+ const webappPath = await (0, project_access_1.getWebappPath)(basePath, fs);
90
127
  if (service.metadata) {
91
- const webappPath = await (0, project_access_1.getWebappPath)(basePath, fs);
92
128
  if (paths.ui5Yaml && ui5Config) {
93
- const config = {
94
- webappPath: webappPath
95
- };
96
- // Generate mockserver middleware for ui5-mock.yaml
97
- await (0, mockserver_config_writer_1.generateMockserverConfig)(basePath, config, fs);
98
- // Update ui5-local.yaml with mockserver middleware from newly created/updated ui5-mock.yaml
99
- await generateMockserverMiddlewareBasedOnUi5MockYaml(fs, paths.ui5Yaml, paths.ui5LocalYaml, ui5LocalConfig);
100
- // Update ui5-mock.yaml with backend middleware
101
- if (paths.ui5MockYaml) {
102
- ui5MockConfig = await ui5_config_1.UI5Config.newInstance(fs.read(paths.ui5MockYaml));
103
- extendBackendMiddleware(fs, service, ui5MockConfig, paths.ui5MockYaml);
104
- }
129
+ await generateAndUpdateMockserverConfig(basePath, paths, service, webappPath, ui5LocalConfig, fs);
105
130
  }
106
131
  await (0, annotations_1.writeLocalServiceAnnotationXMLFiles)(fs, webappPath, templateRoot, service);
107
132
  }
108
- // Service is being added - update the package.json update as well, service update should not run the updates of the package.json
109
133
  if (paths.packageJson && paths.ui5Yaml) {
110
134
  (0, package_1.updatePackageJson)(paths.packageJson, fs, !!service.metadata);
111
135
  }
@@ -113,6 +137,9 @@ async function addServicesData(basePath, paths, templateRoot, service, fs) {
113
137
  fs.write(paths.ui5LocalYaml, ui5LocalConfig.toString());
114
138
  }
115
139
  await (0, annotations_1.writeRemoteServiceAnnotationXmlFiles)(fs, basePath, service.name ?? 'mainService', service.annotations);
140
+ if (service.externalServices && webappPath) {
141
+ (0, data_1.writeExternalServiceMetadata)(fs, webappPath, service.externalServices, service.name, service.path);
142
+ }
116
143
  }
117
144
  /**
118
145
  * Updates services data in ui5-*.yaml files.
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "bugs": {
10
10
  "url": "https://github.com/SAP/open-ux-tools/issues?q=is%3Aopen+is%3Aissue+label%3Abug+label%3Aodata-service-writer"
11
11
  },
12
- "version": "0.27.35",
12
+ "version": "0.27.37",
13
13
  "license": "Apache-2.0",
14
14
  "main": "dist/index.js",
15
15
  "files": [
@@ -29,8 +29,8 @@
29
29
  "mem-fs-editor": "9.4.0",
30
30
  "prettify-xml": "1.2.0",
31
31
  "semver": "7.5.4",
32
- "@sap-ux/mockserver-config-writer": "0.9.31",
33
- "@sap-ux/project-access": "1.32.14",
32
+ "@sap-ux/mockserver-config-writer": "0.9.32",
33
+ "@sap-ux/project-access": "1.32.15",
34
34
  "@sap-ux/ui5-config": "0.29.10"
35
35
  },
36
36
  "devDependencies": {