@cap-js/ord 1.3.0 → 1.3.1

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 (3) hide show
  1. package/README.md +18 -0
  2. package/lib/build.js +40 -8
  3. package/package.json +7 -3
package/README.md CHANGED
@@ -145,6 +145,24 @@ cds compile <path to srv folder> --to ord [-o] [destinationFilePath]
145
145
 
146
146
  You can find more information, such as how to customize the ORD Document, in this [document](./docs/ord.md).
147
147
 
148
+ ## How to setup dev environment and run xmpl locally
149
+
150
+ 1. **Install dependency**
151
+ ```sh
152
+ npm i
153
+ ```
154
+ 2. **Run xmpl application**
155
+
156
+ ```sh
157
+ cd xmpl/
158
+
159
+ # watch xmpl application
160
+ cds watch
161
+
162
+ # build resources files
163
+ cds build --for ord
164
+ ```
165
+
148
166
  ## Support, Feedback, Contributing
149
167
 
150
168
  This project is open to feature requests/suggestions, bug reports etc. via [GitHub issues](https://github.com/cap-js/ord/issues). Contribution and feedback are encouraged and always welcome. For more information about how to contribute, the project structure, as well as additional contribution information, see our [Contribution Guidelines](CONTRIBUTING.md).
package/lib/build.js CHANGED
@@ -1,6 +1,7 @@
1
1
  const cds = require("@sap/cds");
2
2
  const cds_dk = require("@sap/cds-dk");
3
- const { path } = cds.utils;
3
+ const path = require("path");
4
+ const _ = require("lodash");
4
5
  const { ord, getMetadata } = require("./index");
5
6
  const { BUILD_DEFAULT_PATH, ORD_SERVICE_NAME, ORD_DOCUMENT_FILE_NAME } = require("./constants");
6
7
 
@@ -17,16 +18,14 @@ module.exports = class OrdBuildPlugin extends cds_dk.build.Plugin {
17
18
  continue;
18
19
  }
19
20
 
20
- const subDir = path.join(this.task.dest, resource.ordId);
21
-
22
21
  for (const resourceDefinition of resource.resourceDefinitions) {
23
22
  const url = resourceDefinition.url;
24
- const fileName = url.split("/").pop();
23
+ const fileName = path.join(resource.ordId, url.split("/").pop());
25
24
  try {
26
25
  const { _, response } = await getMetadata(url, model); // eslint-disable-line no-unused-vars
27
26
  promises.push(
28
27
  this.write(response)
29
- .to(path.join(subDir, fileName))
28
+ .to(fileName.replace(/:/g, "_"))
30
29
  .catch((err) => {
31
30
  console.log("Error", `Failed to write file ${fileName}: ${err.message}`);
32
31
  }),
@@ -38,15 +37,48 @@ module.exports = class OrdBuildPlugin extends cds_dk.build.Plugin {
38
37
  }
39
38
  }
40
39
 
40
+ postProcess(ordDocument) {
41
+ const clonedOrdDocument = _.cloneDeep(ordDocument);
42
+ const _updateResourceUrls = (resources) => {
43
+ for (const resource of resources || []) {
44
+ if (resource.resourceDefinitions) {
45
+ for (const resourceDefinition of resource.resourceDefinitions) {
46
+ let url = resourceDefinition.url;
47
+ url = this._createRelativePath(url);
48
+ resourceDefinition.url = url;
49
+ }
50
+ }
51
+ }
52
+ };
53
+
54
+ _updateResourceUrls(clonedOrdDocument.apiResources);
55
+ _updateResourceUrls(clonedOrdDocument.eventResources);
56
+
57
+ return clonedOrdDocument;
58
+ }
59
+
60
+ _createRelativePath(url) {
61
+ let relative = url.split("/ord/v1").pop();
62
+ if (relative.startsWith("/")) relative = relative.slice(1);
63
+ relative = relative.replace(/:/g, "_");
64
+ return path.join(...relative.split("/"));
65
+ }
66
+
41
67
  async build() {
42
68
  const model = await this.model();
43
69
  const ordDocument = ord(model);
70
+ const postProcessedOrdDocument = this.postProcess(ordDocument);
44
71
 
45
72
  const promises = [];
46
- promises.push(this.write(ordDocument).to(ORD_DOCUMENT_FILE_NAME));
73
+ promises.push(this.write(postProcessedOrdDocument).to(ORD_DOCUMENT_FILE_NAME));
47
74
 
48
- await this._writeResourcesFiles(ordDocument.apiResources, model, promises);
49
- await this._writeResourcesFiles(ordDocument.eventResources, model, promises);
75
+ if (ordDocument.apiResources && ordDocument.apiResources.length > 0) {
76
+ await this._writeResourcesFiles(ordDocument.apiResources, model, promises);
77
+ }
78
+
79
+ if (ordDocument.eventResources && ordDocument.eventResources.length > 0) {
80
+ await this._writeResourcesFiles(ordDocument.eventResources, model, promises);
81
+ }
50
82
 
51
83
  return Promise.all(promises);
52
84
  }
package/package.json CHANGED
@@ -1,13 +1,17 @@
1
1
  {
2
2
  "name": "@cap-js/ord",
3
- "version": "1.3.0",
3
+ "version": "1.3.1",
4
4
  "description": "CAP Plugin for generating ORD document.",
5
5
  "repository": "cap-js/ord",
6
6
  "author": "SAP SE (https://www.sap.com)",
7
7
  "homepage": "https://cap.cloud.sap/",
8
8
  "license": "Apache-2.0",
9
+ "workspaces": [
10
+ "xmpl"
11
+ ],
9
12
  "main": "cds-plugin.js",
10
13
  "files": [
14
+ "cds-plugin.js",
11
15
  "lib",
12
16
  "data",
13
17
  "LICENSES"
@@ -24,8 +28,8 @@
24
28
  "prettier": "3.5.3"
25
29
  },
26
30
  "peerDependencies": {
27
- "@sap/cds": "^8.1.1",
28
- "@sap/cds-dk": "^8.9.3"
31
+ "@sap/cds": ">=9",
32
+ "@sap/cds-dk": ">=9"
29
33
  },
30
34
  "dependencies": {
31
35
  "@cap-js/asyncapi": "^1.0.3",