@sap-ux/odata-service-writer 0.20.5 → 0.21.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.
@@ -15,7 +15,7 @@ function getAnnotationNamespaces({ metadata, annotations }) {
15
15
  // Enhance service with annotations namespaces
16
16
  const schemaNamespaces = metadata ? getNamespaces(metadata) : [];
17
17
  const edmxAnnotations = annotations;
18
- if (edmxAnnotations === null || edmxAnnotations === void 0 ? void 0 : edmxAnnotations.xml) {
18
+ if (edmxAnnotations?.xml) {
19
19
  // Parse once
20
20
  const annotationsJson = xmlToJson(edmxAnnotations.xml);
21
21
  return schemaNamespaces.map((schema) => {
@@ -60,9 +60,8 @@ function xmlToJson(xml) {
60
60
  * @returns Array of namespaces and their aliases
61
61
  */
62
62
  function getNamespaces(metadata) {
63
- var _a, _b;
64
63
  const jsonMetadata = xmlToJson(metadata);
65
- let schema = (_b = (_a = jsonMetadata['edmx:Edmx']) === null || _a === void 0 ? void 0 : _a['edmx:DataServices']) === null || _b === void 0 ? void 0 : _b['Schema'];
64
+ let schema = jsonMetadata['edmx:Edmx']?.['edmx:DataServices']?.['Schema'];
66
65
  if (!schema) {
67
66
  return [];
68
67
  }
@@ -85,13 +84,12 @@ function getNamespaces(metadata) {
85
84
  * @returns An alias for the specified namespace or empty string
86
85
  */
87
86
  function getAliasFromAnnotation(annotations, namespace) {
88
- var _a, _b;
89
- let references = (_a = annotations['edmx:Edmx']) === null || _a === void 0 ? void 0 : _a['edmx:Reference'];
87
+ let references = annotations['edmx:Edmx']?.['edmx:Reference'];
90
88
  // Can be array or single item
91
89
  if (!Array.isArray(references)) {
92
90
  references = [references];
93
91
  }
94
- const annoNamespace = references.find((ref) => { var _a, _b; return ((_a = ref['edmx:Include']) === null || _a === void 0 ? void 0 : _a['Namespace']) === namespace && ((_b = ref['edmx:Include']) === null || _b === void 0 ? void 0 : _b['Alias']); });
95
- return annoNamespace ? (_b = annoNamespace['edmx:Include']) === null || _b === void 0 ? void 0 : _b['Alias'] : '';
92
+ const annoNamespace = references.find((ref) => ref['edmx:Include']?.['Namespace'] === namespace && ref['edmx:Include']?.['Alias']);
93
+ return annoNamespace ? annoNamespace['edmx:Include']?.['Alias'] : '';
96
94
  }
97
95
  //# sourceMappingURL=annotations.js.map
@@ -11,8 +11,7 @@ const constants_1 = require("./constants");
11
11
  * @param {OdataService} service - The service object whose path needs to be set or modified.
12
12
  */
13
13
  function setDefaultServicePath(service) {
14
- var _a, _b;
15
- service.path = ((_a = service.path) === null || _a === void 0 ? void 0 : _a.endsWith('/')) ? service.path : ((_b = service.path) !== null && _b !== void 0 ? _b : '') + '/';
14
+ service.path = service.path?.endsWith('/') ? service.path : (service.path ?? '') + '/';
16
15
  }
17
16
  /**
18
17
  * Sets the default name for a given service.
@@ -21,8 +20,7 @@ function setDefaultServicePath(service) {
21
20
  * @param {OdataService} service - The service object whose name needs to be set or modified.
22
21
  */
23
22
  function setDefaultServiceName(service) {
24
- var _a;
25
- service.name = (_a = service.name) !== null && _a !== void 0 ? _a : constants_1.DEFAULT_DATASOURCE_NAME;
23
+ service.name = service.name ?? constants_1.DEFAULT_DATASOURCE_NAME;
26
24
  }
27
25
  /**
28
26
  * Sets the default model for a given service.
@@ -31,8 +29,7 @@ function setDefaultServiceName(service) {
31
29
  * @param {OdataService} service - The service object whose model needs to be set or modified.
32
30
  */
33
31
  function setDefaultServiceModel(service) {
34
- var _a;
35
- service.model = (_a = service.model) !== null && _a !== void 0 ? _a : ''; // Default UI5 model
32
+ service.model = service.model ?? ''; // Default UI5 model
36
33
  }
37
34
  /**
38
35
  * Sets the default annotations name for a given service.
@@ -42,7 +39,6 @@ function setDefaultServiceModel(service) {
42
39
  * @param {OdataService} service - The service object whose annotations name needs to be set or modified.
43
40
  */
44
41
  function setDefaultAnnotationsName(service) {
45
- var _a, _b;
46
42
  /**
47
43
  * In the manifest EJS template, annotation names are referred to for adding annotations to the manifest.json.
48
44
  * For CAP projects, annotations are added to the annotations.cds file and not to the manifest.json.
@@ -51,8 +47,8 @@ function setDefaultAnnotationsName(service) {
51
47
  return;
52
48
  }
53
49
  const annotations = service.annotations;
54
- if ((annotations === null || annotations === void 0 ? void 0 : annotations.technicalName) && !annotations.name) {
55
- annotations.name = (_b = (_a = annotations === null || annotations === void 0 ? void 0 : annotations.technicalName) === null || _a === void 0 ? void 0 : _a.replace(/\//g, '_')) === null || _b === void 0 ? void 0 : _b.replace(/^_/, '');
50
+ if (annotations?.technicalName && !annotations.name) {
51
+ annotations.name = annotations?.technicalName?.replace(/\//g, '_')?.replace(/^_/, '');
56
52
  }
57
53
  }
58
54
  /**
@@ -62,7 +58,6 @@ function setDefaultAnnotationsName(service) {
62
58
  * @param {OdataService} service - the OData service object
63
59
  */
64
60
  function enhanceData(service) {
65
- var _a, _b;
66
61
  setDefaultServicePath(service);
67
62
  setDefaultServiceName(service);
68
63
  setDefaultServiceModel(service);
@@ -70,7 +65,7 @@ function enhanceData(service) {
70
65
  // enhance preview settings with service configuration
71
66
  service.previewSettings = service.previewSettings || {};
72
67
  service.previewSettings.path =
73
- service.previewSettings.path || `/${(_b = (_a = service.path) === null || _a === void 0 ? void 0 : _a.split('/').filter((s) => s !== '')[0]) !== null && _b !== void 0 ? _b : ''}`;
68
+ service.previewSettings.path || `/${service.path?.split('/').filter((s) => s !== '')[0] ?? ''}`;
74
69
  service.previewSettings.url = service.previewSettings.url || service.url || 'http://localhost';
75
70
  if (service.client && !service.previewSettings.client) {
76
71
  service.previewSettings.client = service.client;
package/dist/i18n.js CHANGED
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -19,19 +10,17 @@ const NS = 'odata-service-writer';
19
10
  /**
20
11
  * Initialize i18next with the translations for this module.
21
12
  */
22
- function initI18n() {
23
- return __awaiter(this, void 0, void 0, function* () {
24
- yield i18next_1.default.init({
25
- resources: {
26
- en: {
27
- [NS]: odata_service_writer_i18n_json_1.default
28
- }
29
- },
30
- lng: 'en',
31
- fallbackLng: 'en',
32
- defaultNS: NS,
33
- ns: [NS]
34
- });
13
+ async function initI18n() {
14
+ await i18next_1.default.init({
15
+ resources: {
16
+ en: {
17
+ [NS]: odata_service_writer_i18n_json_1.default
18
+ }
19
+ },
20
+ lng: 'en',
21
+ fallbackLng: 'en',
22
+ defaultNS: NS,
23
+ ns: [NS]
35
24
  });
36
25
  }
37
26
  exports.initI18n = initI18n;
package/dist/index.js CHANGED
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -47,22 +38,20 @@ function ensureExists(basePath, files, fs) {
47
38
  * @param {Editor} [fs] - the memfs editor instance
48
39
  * @returns an object with the optional locations of the package.json and ui5.yaml
49
40
  */
50
- function findProjectFiles(basePath, fs) {
51
- return __awaiter(this, void 0, void 0, function* () {
52
- const files = {};
53
- const parts = basePath.split(path_1.sep);
54
- while (parts.length > 0 && (!files.packageJson || !files.ui5Yaml)) {
55
- const path = parts.join(path_1.sep);
56
- if (!files.packageJson && fs.exists((0, path_1.join)(path, 'package.json'))) {
57
- files.packageJson = (0, path_1.join)(path, 'package.json');
58
- }
59
- if (!files.ui5Yaml && fs.exists((0, path_1.join)(path, 'ui5.yaml'))) {
60
- files.ui5Yaml = (0, path_1.join)(path, 'ui5.yaml');
61
- }
62
- parts.pop();
41
+ async function findProjectFiles(basePath, fs) {
42
+ const files = {};
43
+ const parts = basePath.split(path_1.sep);
44
+ while (parts.length > 0 && (!files.packageJson || !files.ui5Yaml)) {
45
+ const path = parts.join(path_1.sep);
46
+ if (!files.packageJson && fs.exists((0, path_1.join)(path, 'package.json'))) {
47
+ files.packageJson = (0, path_1.join)(path, 'package.json');
63
48
  }
64
- return files;
65
- });
49
+ if (!files.ui5Yaml && fs.exists((0, path_1.join)(path, 'ui5.yaml'))) {
50
+ files.ui5Yaml = (0, path_1.join)(path, 'ui5.yaml');
51
+ }
52
+ parts.pop();
53
+ }
54
+ return files;
66
55
  }
67
56
  exports.findProjectFiles = findProjectFiles;
68
57
  /**
@@ -74,83 +63,81 @@ exports.findProjectFiles = findProjectFiles;
74
63
  * @throws {Error} - if required UI5 project files are not found
75
64
  * @returns {Promise<Editor>} the updated memfs editor instance
76
65
  */
77
- function generate(basePath, service, fs) {
78
- return __awaiter(this, void 0, void 0, function* () {
79
- if (!fs) {
80
- fs = (0, mem_fs_editor_1.create)((0, mem_fs_1.create)());
66
+ async function generate(basePath, service, fs) {
67
+ if (!fs) {
68
+ fs = (0, mem_fs_editor_1.create)((0, mem_fs_1.create)());
69
+ }
70
+ const paths = await findProjectFiles(basePath, fs);
71
+ ensureExists(basePath, ['webapp/manifest.json'], fs);
72
+ (0, data_1.enhanceData)(service);
73
+ // merge content into existing files
74
+ const templateRoot = (0, path_1.join)(__dirname, '../templates');
75
+ // update cds files with annotations only if service type is CDS and annotations are provided
76
+ if ((0, updates_1.serviceIsCds)(service) && service.annotations) {
77
+ await (0, updates_1.updateCdsFilesWithAnnotations)(service.annotations, fs);
78
+ }
79
+ // manifest.json
80
+ (0, updates_1.updateManifest)(basePath, service, fs, templateRoot);
81
+ // update ui5.yaml if it exists
82
+ let ui5Config;
83
+ let ui5LocalConfig;
84
+ let ui5LocalConfigPath;
85
+ if (!(0, updates_1.serviceIsCds)(service) && paths.ui5Yaml) {
86
+ // Dont extend backend middlewares if service type is CDS
87
+ ui5Config = await ui5_config_1.UI5Config.newInstance(fs.read(paths.ui5Yaml));
88
+ try {
89
+ ui5Config.addBackendToFioriToolsProxydMiddleware(service.previewSettings);
81
90
  }
82
- const paths = yield findProjectFiles(basePath, fs);
83
- ensureExists(basePath, ['webapp/manifest.json'], fs);
84
- (0, data_1.enhanceData)(service);
85
- // merge content into existing files
86
- const templateRoot = (0, path_1.join)(__dirname, '../templates');
87
- // update cds files with annotations only if service type is CDS and annotations are provided
88
- if ((0, updates_1.serviceIsCds)(service) && service.annotations) {
89
- yield (0, updates_1.updateCdsFilesWithAnnotations)(service.annotations, fs);
90
- }
91
- // manifest.json
92
- (0, updates_1.updateManifest)(basePath, service, fs, templateRoot);
93
- // update ui5.yaml if it exists
94
- let ui5Config;
95
- let ui5LocalConfig;
96
- let ui5LocalConfigPath;
97
- if (!(0, updates_1.serviceIsCds)(service) && paths.ui5Yaml) {
98
- // Dont extend backend middlewares if service type is CDS
99
- ui5Config = yield ui5_config_1.UI5Config.newInstance(fs.read(paths.ui5Yaml));
100
- try {
101
- ui5Config.addBackendToFioriToolsProxydMiddleware(service.previewSettings);
102
- }
103
- catch (error) {
104
- if (error instanceof ui5_config_1.YAMLError && error.code === ui5_config_1.yamlErrorCode.nodeNotFound) {
105
- ui5Config.addFioriToolsProxydMiddleware({ backend: [service.previewSettings] });
106
- }
107
- else {
108
- throw error;
109
- }
91
+ catch (error) {
92
+ if (error instanceof ui5_config_1.YAMLError && error.code === ui5_config_1.yamlErrorCode.nodeNotFound) {
93
+ ui5Config.addFioriToolsProxydMiddleware({ backend: [service.previewSettings] });
110
94
  }
111
- fs.write(paths.ui5Yaml, ui5Config.toString());
112
- // ui5-local.yaml
113
- ui5LocalConfigPath = (0, path_1.join)((0, path_1.dirname)(paths.ui5Yaml), 'ui5-local.yaml');
114
- if (fs.exists(ui5LocalConfigPath)) {
115
- ui5LocalConfig = yield ui5_config_1.UI5Config.newInstance(fs.read(ui5LocalConfigPath));
116
- ui5LocalConfig.addFioriToolsProxydMiddleware({ backend: [service.previewSettings] });
95
+ else {
96
+ throw error;
117
97
  }
118
98
  }
119
- // Add mockserver entries
120
- if (!(0, updates_1.serviceIsCds)(service) && service.metadata) {
121
- // mockserver entries are not required if service type is CDS
122
- // copy existing `ui5.yaml` as starting point for ui5-mock.yaml
123
- if (paths.ui5Yaml && ui5Config) {
124
- const webappPath = yield (0, project_access_1.getWebappPath)(basePath, fs);
125
- const config = {
126
- webappPath: webappPath,
127
- ui5MockYamlConfig: { path: service.path }
128
- };
129
- yield (0, mockserver_config_writer_1.generateMockserverConfig)(basePath, config, fs);
130
- // add mockserver middleware to ui5-local.yaml
131
- if (ui5LocalConfig) {
132
- ui5LocalConfig.addMockServerMiddleware(service.path);
133
- }
134
- }
135
- // create local copy of metadata and annotations
136
- fs.write((0, path_1.join)(basePath, 'webapp', 'localService', 'metadata.xml'), (0, prettify_xml_1.default)(service.metadata, { indent: 4 }));
137
- // Adds local annotations to datasources section of manifest.json and writes the annotations file
138
- if (service.localAnnotationsName) {
139
- const namespaces = (0, data_1.getAnnotationNamespaces)(service);
140
- fs.copyTpl((0, path_1.join)(templateRoot, 'add', 'annotation.xml'), (0, path_1.join)(basePath, 'webapp', 'annotations', `${service.localAnnotationsName}.xml`), Object.assign(Object.assign({}, service), { namespaces }));
141
- }
99
+ fs.write(paths.ui5Yaml, ui5Config.toString());
100
+ // ui5-local.yaml
101
+ ui5LocalConfigPath = (0, path_1.join)((0, path_1.dirname)(paths.ui5Yaml), 'ui5-local.yaml');
102
+ if (fs.exists(ui5LocalConfigPath)) {
103
+ ui5LocalConfig = await ui5_config_1.UI5Config.newInstance(fs.read(ui5LocalConfigPath));
104
+ ui5LocalConfig.addFioriToolsProxydMiddleware({ backend: [service.previewSettings] });
142
105
  }
143
- // update package.json if required
144
- if (paths.packageJson && paths.ui5Yaml) {
145
- (0, updates_1.updatePackageJson)(paths.packageJson, fs, !!service.metadata);
106
+ }
107
+ // Add mockserver entries
108
+ if (!(0, updates_1.serviceIsCds)(service) && service.metadata) {
109
+ // mockserver entries are not required if service type is CDS
110
+ // copy existing `ui5.yaml` as starting point for ui5-mock.yaml
111
+ if (paths.ui5Yaml && ui5Config) {
112
+ const webappPath = await (0, project_access_1.getWebappPath)(basePath, fs);
113
+ const config = {
114
+ webappPath: webappPath,
115
+ ui5MockYamlConfig: { path: service.path }
116
+ };
117
+ await (0, mockserver_config_writer_1.generateMockserverConfig)(basePath, config, fs);
118
+ // add mockserver middleware to ui5-local.yaml
119
+ if (ui5LocalConfig) {
120
+ ui5LocalConfig.addMockServerMiddleware(service.path);
121
+ }
146
122
  }
147
- if (ui5LocalConfigPath && ui5LocalConfig) {
148
- fs.write(ui5LocalConfigPath, ui5LocalConfig.toString());
123
+ // create local copy of metadata and annotations
124
+ fs.write((0, path_1.join)(basePath, 'webapp', 'localService', 'metadata.xml'), (0, prettify_xml_1.default)(service.metadata, { indent: 4 }));
125
+ // Adds local annotations to datasources section of manifest.json and writes the annotations file
126
+ if (service.localAnnotationsName) {
127
+ const namespaces = (0, data_1.getAnnotationNamespaces)(service);
128
+ fs.copyTpl((0, path_1.join)(templateRoot, 'add', 'annotation.xml'), (0, path_1.join)(basePath, 'webapp', 'annotations', `${service.localAnnotationsName}.xml`), { ...service, namespaces });
149
129
  }
150
- // Write annotation xml if annotations are provided and service type is EDMX
151
- (0, updates_1.writeAnnotationXmlFiles)(fs, basePath, service);
152
- return fs;
153
- });
130
+ }
131
+ // update package.json if required
132
+ if (paths.packageJson && paths.ui5Yaml) {
133
+ (0, updates_1.updatePackageJson)(paths.packageJson, fs, !!service.metadata);
134
+ }
135
+ if (ui5LocalConfigPath && ui5LocalConfig) {
136
+ fs.write(ui5LocalConfigPath, ui5LocalConfig.toString());
137
+ }
138
+ // Write annotation xml if annotations are provided and service type is EDMX
139
+ (0, updates_1.writeAnnotationXmlFiles)(fs, basePath, service);
140
+ return fs;
154
141
  }
155
142
  exports.generate = generate;
156
143
  //# sourceMappingURL=index.js.map
package/dist/updates.js CHANGED
@@ -22,15 +22,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
35
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
36
27
  };
@@ -51,7 +42,7 @@ const prettify_xml_1 = __importDefault(require("prettify-xml"));
51
42
  function serviceIsCds(service) {
52
43
  // if service type is not defined, set EDMX as default
53
44
  let serviceType = service.type;
54
- serviceType || (serviceType = types_1.ServiceType.EDMX);
45
+ serviceType ||= types_1.ServiceType.EDMX;
55
46
  if (serviceType === types_1.ServiceType.CDS) {
56
47
  return true;
57
48
  }
@@ -67,18 +58,17 @@ exports.serviceIsCds = serviceIsCds;
67
58
  * @param templateRoot - root folder contain the ejs templates
68
59
  */
69
60
  function updateManifest(basePath, service, fs, templateRoot) {
70
- var _a, _b, _c;
71
61
  const manifestPath = (0, path_1.join)(basePath, 'webapp', 'manifest.json');
72
62
  // Get component app id
73
63
  const manifest = fs.readJSON(manifestPath);
74
64
  const appProp = 'sap.app';
75
- const appid = (_a = manifest === null || manifest === void 0 ? void 0 : manifest[appProp]) === null || _a === void 0 ? void 0 : _a.id;
65
+ const appid = manifest?.[appProp]?.id;
76
66
  // Throw if required property is not found manifest.json
77
67
  if (!appid) {
78
68
  throw new Error((0, i18n_1.t)('error.requiredProjectPropertyNotFound', { property: `'${appProp}'.id`, path: manifestPath }));
79
69
  }
80
70
  const manifestJsonExt = fs.read((0, path_1.join)(templateRoot, 'extend', `manifest.json`));
81
- const minUI5Version = (_c = (_b = manifest['sap.ui5']) === null || _b === void 0 ? void 0 : _b.dependencies) === null || _c === void 0 ? void 0 : _c.minUI5Version;
71
+ const minUI5Version = manifest['sap.ui5']?.dependencies?.minUI5Version;
82
72
  const manifestSettings = Object.assign(service, getModelSettings(minUI5Version));
83
73
  // If the service object includes ejs options, for example 'client' (see: https://ejs.co/#docs),
84
74
  // resulting in unexpected behaviour and problems when webpacking. Passing an empty options object prevents this.
@@ -94,26 +84,23 @@ exports.updateManifest = updateManifest;
94
84
  * @param {CdsAnnotationsInfo} annotations - The cds annotations info.
95
85
  * @returns {Promise<void>} A promise that resolves when the cds files have been updated.
96
86
  */
97
- function updateCdsIndexOrServiceFile(fs, annotations) {
98
- var _a, _b;
99
- return __awaiter(this, void 0, void 0, function* () {
100
- const dirPath = (0, path_1.join)(annotations.projectName, 'annotations');
101
- const annotationPath = path_1.default.normalize(dirPath).split(/[\\/]/g).join(path_1.default.posix.sep);
102
- const annotationConfig = `\nusing from './${annotationPath}';`;
103
- // get index and service file paths
104
- const indexFilePath = (0, path_1.join)(annotations.projectPath, (_a = annotations.appPath) !== null && _a !== void 0 ? _a : '', 'index.cds');
105
- const serviceFilePath = (0, path_1.join)(annotations.projectPath, (_b = annotations.appPath) !== null && _b !== void 0 ? _b : '', 'services.cds');
106
- // extend index or service file with annotation config
107
- if (indexFilePath && fs.exists(indexFilePath)) {
108
- fs.append(indexFilePath, annotationConfig);
109
- }
110
- else if (fs.exists(serviceFilePath)) {
111
- fs.append(serviceFilePath, annotationConfig);
112
- }
113
- else {
114
- fs.write(serviceFilePath, annotationConfig);
115
- }
116
- });
87
+ async function updateCdsIndexOrServiceFile(fs, annotations) {
88
+ const dirPath = (0, path_1.join)(annotations.projectName, 'annotations');
89
+ const annotationPath = path_1.default.normalize(dirPath).split(/[\\/]/g).join(path_1.default.posix.sep);
90
+ const annotationConfig = `\nusing from './${annotationPath}';`;
91
+ // get index and service file paths
92
+ const indexFilePath = (0, path_1.join)(annotations.projectPath, annotations.appPath ?? '', 'index.cds');
93
+ const serviceFilePath = (0, path_1.join)(annotations.projectPath, annotations.appPath ?? '', 'services.cds');
94
+ // extend index or service file with annotation config
95
+ if (indexFilePath && fs.exists(indexFilePath)) {
96
+ fs.append(indexFilePath, annotationConfig);
97
+ }
98
+ else if (fs.exists(serviceFilePath)) {
99
+ fs.append(serviceFilePath, annotationConfig);
100
+ }
101
+ else {
102
+ fs.write(serviceFilePath, annotationConfig);
103
+ }
117
104
  }
118
105
  /**
119
106
  * Writes annotation XML files.
@@ -128,7 +115,7 @@ function writeAnnotationXmlFiles(fs, basePath, service) {
128
115
  }
129
116
  // Write annotation xml if annotations are provided and service type is EDMX
130
117
  const annotations = service.annotations;
131
- if (annotations === null || annotations === void 0 ? void 0 : annotations.xml) {
118
+ if (annotations?.xml) {
132
119
  fs.write((0, path_1.join)(basePath, 'webapp', 'localService', `${annotations.technicalName}.xml`), (0, prettify_xml_1.default)(annotations.xml, { indent: 4 }));
133
120
  }
134
121
  }
@@ -142,14 +129,11 @@ exports.writeAnnotationXmlFiles = writeAnnotationXmlFiles;
142
129
  * @param {Editor} fs - The memfs editor instance
143
130
  * @returns {Promise<void>} A promise that resolves when the cds files have been updated.
144
131
  */
145
- function updateCdsFilesWithAnnotations(annotations, fs) {
146
- var _a;
147
- return __awaiter(this, void 0, void 0, function* () {
148
- const annotationCdsPath = (0, path_1.join)(annotations.projectPath, (_a = annotations.appPath) !== null && _a !== void 0 ? _a : '', annotations.projectName, 'annotations.cds');
149
- // write into annotations.cds file
150
- fs.write(annotationCdsPath, annotations.cdsFileContents);
151
- yield updateCdsIndexOrServiceFile(fs, annotations);
152
- });
132
+ async function updateCdsFilesWithAnnotations(annotations, fs) {
133
+ const annotationCdsPath = (0, path_1.join)(annotations.projectPath, annotations.appPath ?? '', annotations.projectName, 'annotations.cds');
134
+ // write into annotations.cds file
135
+ fs.write(annotationCdsPath, annotations.cdsFileContents);
136
+ await updateCdsIndexOrServiceFile(fs, annotations);
153
137
  }
154
138
  exports.updateCdsFilesWithAnnotations = updateCdsFilesWithAnnotations;
155
139
  /**
@@ -173,12 +157,11 @@ function getModelSettings(minUI5Version) {
173
157
  * @param addMockServer true if the mocksever middleware needs to be added as well
174
158
  */
175
159
  function updatePackageJson(path, fs, addMockServer) {
176
- var _a, _b, _c;
177
160
  const packageJson = JSON.parse(fs.read(path));
178
- packageJson.devDependencies = (_a = packageJson.devDependencies) !== null && _a !== void 0 ? _a : {};
161
+ packageJson.devDependencies = packageJson.devDependencies ?? {};
179
162
  if (!hasUI5CliV3(packageJson.devDependencies)) {
180
- packageJson.ui5 = (_b = packageJson.ui5) !== null && _b !== void 0 ? _b : {};
181
- packageJson.ui5.dependencies = (_c = packageJson.ui5.dependencies) !== null && _c !== void 0 ? _c : [];
163
+ packageJson.ui5 = packageJson.ui5 ?? {};
164
+ packageJson.ui5.dependencies = packageJson.ui5.dependencies ?? [];
182
165
  if (!packageJson.ui5.dependencies.includes('@sap/ux-ui5-tooling')) {
183
166
  packageJson.ui5.dependencies.push('@sap/ux-ui5-tooling');
184
167
  }
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.20.5",
12
+ "version": "0.21.0",
13
13
  "license": "Apache-2.0",
14
14
  "main": "dist/index.js",
15
15
  "files": [
@@ -27,8 +27,8 @@
27
27
  "mem-fs-editor": "9.4.0",
28
28
  "prettify-xml": "1.2.0",
29
29
  "semver": "7.5.4",
30
- "@sap-ux/mockserver-config-writer": "0.5.8",
31
- "@sap-ux/ui5-config": "0.22.10"
30
+ "@sap-ux/mockserver-config-writer": "0.6.0",
31
+ "@sap-ux/ui5-config": "0.23.0"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@types/ejs": "3.1.2",
@@ -38,7 +38,7 @@
38
38
  "@types/semver": "7.5.2",
39
39
  "fs-extra": "10.0.0",
40
40
  "lodash": "4.17.21",
41
- "@sap-ux/project-access": "1.22.3"
41
+ "@sap-ux/project-access": "1.23.0"
42
42
  },
43
43
  "engines": {
44
44
  "node": ">=18.x"