@sap-ux/odata-service-writer 0.24.0 → 0.24.2

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.js CHANGED
@@ -219,7 +219,7 @@ async function generate(basePath, service, fs) {
219
219
  // Prepare template folder for manifest and xml updates
220
220
  const templateRoot = (0, path_1.join)(__dirname, '../templates');
221
221
  // Update manifest.json
222
- (0, updates_1.updateManifest)(basePath, service, fs, templateRoot);
222
+ await (0, updates_1.updateManifest)(basePath, service, fs, templateRoot);
223
223
  // Dont extend backend and mockserver middlewares if service type is CDS
224
224
  if (isServiceTypeEdmx) {
225
225
  await writeEDMXServiceFiles(fs, basePath, paths, templateRoot, service);
package/dist/types.d.ts CHANGED
@@ -66,7 +66,7 @@ export interface OdataService {
66
66
  * Annotations can either be EDMX annotations or CDS annotations.
67
67
  */
68
68
  annotations?: EdmxAnnotationsInfo | EdmxAnnotationsInfo[] | CdsAnnotationsInfo | CdsAnnotationsInfo[];
69
- localAnnotationsName?: string;
69
+ localAnnotationsName?: string | string[];
70
70
  previewSettings?: Partial<ProxyBackend>;
71
71
  /**
72
72
  * Indicates whether certificate errors should be ignored.
package/dist/updates.d.ts CHANGED
@@ -8,7 +8,7 @@ import type { OdataService, CdsAnnotationsInfo, EdmxAnnotationsInfo } from './ty
8
8
  * @param fs - the memfs editor instance
9
9
  * @param templateRoot - root folder contain the ejs templates
10
10
  */
11
- export declare function updateManifest(basePath: string, service: OdataService, fs: Editor, templateRoot: string): void;
11
+ export declare function updateManifest(basePath: string, service: OdataService, fs: Editor, templateRoot: string): Promise<void>;
12
12
  /**
13
13
  * Writes annotation XML files for EDMX service annotations.
14
14
  *
package/dist/updates.js CHANGED
@@ -13,6 +13,58 @@ const i18n_1 = require("./i18n");
13
13
  const semver_1 = __importDefault(require("semver"));
14
14
  const prettify_xml_1 = __importDefault(require("prettify-xml"));
15
15
  const project_access_1 = require("@sap-ux/project-access");
16
+ /**
17
+ * Modifies service in manifest.json and service files in a way that is supported by multiple services.
18
+ * If service files are defined in 'localService' folder then those files are moved to respective service folder and service configuration URI are modified in manifest.json.
19
+ *
20
+ * @param {string} webappPath - the webapp path of an existing UI5 application
21
+ * @param {string} dataSourceKey - dataSource key in manifest.json
22
+ * @param {Manifest} dataSource - dataSource configuration from manifest.json
23
+ * @param {Editor} fs - the memfs editor instance
24
+ */
25
+ function updateExistingService(webappPath, dataSourceKey, dataSource, fs) {
26
+ const settings = dataSource.settings;
27
+ if (settings) {
28
+ // "localService/metadata.xml"
29
+ const localUri = settings.localUri;
30
+ // -> ["localService", "metadata.xml"]
31
+ const localUriParts = localUri ? localUri.split('/') : undefined;
32
+ if (localUriParts && localUriParts[0] === project_access_1.DirName.LocalService && localUriParts.length === 2) {
33
+ const localFileName = localUriParts[localUriParts.length - 1];
34
+ settings.localUri = `${project_access_1.DirName.LocalService}/${dataSourceKey}/${localFileName}`;
35
+ // move related files to service folder
36
+ const fromFilePath = (0, path_1.join)(webappPath, localUriParts.join(path_1.sep));
37
+ const toFilePath = (0, path_1.join)(webappPath, project_access_1.DirName.LocalService, dataSourceKey, localFileName);
38
+ if (fs.exists(fromFilePath)) {
39
+ fs.move(fromFilePath, toFilePath);
40
+ }
41
+ }
42
+ }
43
+ }
44
+ /**
45
+ * Modifies services in manifest.json and services files in a way that is supported by multiple services.
46
+ *
47
+ * @param {string} webappPath - the webapp path of an existing UI5 application
48
+ * @param {Manifest} manifest - the manifest.json of the application
49
+ * @param {Editor} fs - the memfs editor instance
50
+ */
51
+ async function updateExistingServices(webappPath, manifest, fs) {
52
+ const dataSources = manifest?.['sap.app']?.dataSources;
53
+ for (const dataSourceKey in dataSources) {
54
+ const dataSource = dataSources[dataSourceKey];
55
+ if (dataSource.type === 'OData') {
56
+ updateExistingService(webappPath, dataSourceKey, dataSource, fs);
57
+ const annotations = dataSource.settings?.annotations;
58
+ if (annotations) {
59
+ annotations.forEach((annotationName) => {
60
+ const annotationDataSource = dataSources[annotationName];
61
+ updateExistingService(webappPath, dataSourceKey, annotationDataSource, fs);
62
+ });
63
+ }
64
+ }
65
+ }
66
+ fs.writeJSON((0, path_1.join)(webappPath, 'manifest.json'), manifest);
67
+ }
16
68
  /**
17
69
  * Internal function that updates the manifest.json based on the given service configuration.
18
70
  *
@@ -21,18 +73,22 @@ const project_access_1 = require("@sap-ux/project-access");
21
73
  * @param fs - the memfs editor instance
22
74
  * @param templateRoot - root folder contain the ejs templates
23
75
  */
24
- function updateManifest(basePath, service, fs, templateRoot) {
25
- const manifestPath = (0, path_1.join)(basePath, 'webapp', 'manifest.json');
76
+ async function updateManifest(basePath, service, fs, templateRoot) {
77
+ const webappPath = await (0, project_access_1.getWebappPath)(basePath, fs);
78
+ const manifestPath = (0, path_1.join)(webappPath, 'manifest.json');
26
79
  // Get component app id
27
80
  const manifest = fs.readJSON(manifestPath);
28
81
  const appProp = 'sap.app';
29
82
  const appid = manifest?.[appProp]?.id;
83
+ // Check and update existing services
84
+ await updateExistingServices(webappPath, manifest, fs);
85
+ const modifiedManifest = fs.readJSON(manifestPath);
30
86
  // Throw if required property is not found manifest.json
31
87
  if (!appid) {
32
88
  throw new Error((0, i18n_1.t)('error.requiredProjectPropertyNotFound', { property: `'${appProp}'.id`, path: manifestPath }));
33
89
  }
34
90
  const manifestJsonExt = fs.read((0, path_1.join)(templateRoot, 'extend', `manifest.json`));
35
- const manifestSettings = Object.assign(service, getModelSettings((0, project_access_1.getMinimumUI5Version)(manifest)));
91
+ const manifestSettings = Object.assign(service, getModelSettings((0, project_access_1.getMinimumUI5Version)(modifiedManifest)));
36
92
  // If the service object includes ejs options, for example 'client' (see: https://ejs.co/#docs),
37
93
  // resulting in unexpected behaviour and problems when webpacking. Passing an empty options object prevents this.
38
94
  fs.extendJSON(manifestPath, JSON.parse((0, ejs_1.render)(manifestJsonExt, manifestSettings, {})));
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.24.0",
12
+ "version": "0.24.2",
13
13
  "license": "Apache-2.0",
14
14
  "main": "dist/index.js",
15
15
  "files": [
@@ -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.28.8"
41
+ "@sap-ux/project-access": "1.28.9"
42
42
  },
43
43
  "engines": {
44
44
  "node": ">=18.x"
@@ -10,15 +10,20 @@
10
10
  <% if (annotations.length) { %>
11
11
  <% annotations.forEach(function(annotation, index) { %>
12
12
  <% if (annotation.technicalName) { %>
13
- "<%= annotation.name %>"<% if (index < annotations.length - 1) { %>,<% } %>
13
+ "<%= annotation.name %>"<% if (index < annotations.length - 1 || locals.localAnnotationsName && (!locals.localAnnotationsName.length || locals.localAnnotationsName.length > 0)) { %>,<% } %>
14
14
  <% } %>
15
15
  <% }); %>
16
16
  <% } else if (annotations.technicalName) { %>
17
- "<%= annotations.name %>"
17
+ "<%= annotations.name %>"<% if (locals.localAnnotationsName && (!locals.localAnnotationsName.length || locals.localAnnotationsName.length > 0)) {%>,<%}%><% } %>
18
+ <% } %>
19
+ <% if (locals.localAnnotationsName && typeof localAnnotationsName !== 'undefined') { %>
20
+ <% if (Array.isArray(localAnnotationsName)) { %>
21
+ <% localAnnotationsName.forEach(function(localAnnotation, index) { %>
22
+ "<%- localAnnotation %>"<% if (index < localAnnotationsName.length - 1){ %>,<% } %>
23
+ <% }); %>
24
+ <% } else if (localAnnotationsName) { %>
25
+ "<%- localAnnotationsName %>"
18
26
  <% } %>
19
- <% if (locals.localAnnotationsName) {%>,<%}%><% } %>
20
- <% if (locals.localAnnotationsName) { %>
21
- "<%- localAnnotationsName %>"
22
27
  <% } %>
23
28
  ]
24
29
  <% if (locals.metadata) { %>,
@@ -50,14 +55,28 @@
50
55
  }
51
56
  <% } %>
52
57
  <% } %>
53
- <% if (locals.localAnnotationsName) { %>,
54
- "<%- localAnnotationsName %>": {
55
- "type": "ODataAnnotation",
56
- "uri": "annotations/<%- localAnnotationsName %>.xml",
57
- "settings": {
58
- "localUri": "annotations/<%- localAnnotationsName %>.xml"
59
- }
60
- } <% } %>
58
+ <% if (locals.localAnnotationsName && typeof localAnnotationsName !== 'undefined') { %>,
59
+ <% if (locals.localAnnotationsName && typeof localAnnotationsName !== 'undefined') { %>
60
+ <% if (Array.isArray(localAnnotationsName)) { %>
61
+ <% localAnnotationsName.forEach(function(localAnnotation, index) { %>
62
+ "<%- localAnnotation %>": {
63
+ "type": "ODataAnnotation",
64
+ "uri": "annotations/<%- localAnnotation %>.xml",
65
+ "settings": {
66
+ "localUri": "annotations/<%- localAnnotation %>.xml"
67
+ }
68
+ }<% if (index < localAnnotationsName.length - 1){ %>,<% } %>
69
+ <% }); %>
70
+ <% } else if (localAnnotationsName) { %>
71
+ "<%- localAnnotationsName %>": {
72
+ "type": "ODataAnnotation",
73
+ "uri": "annotations/<%- localAnnotationsName %>.xml",
74
+ "settings": {
75
+ "localUri": "annotations/<%- localAnnotationsName %>.xml"
76
+ }
77
+ } <% } %>
78
+ <% } %>
79
+ <% } %>
61
80
  }
62
81
  },
63
82
  "sap.ui5": {