cds-plugin-ui5 0.2.3 → 0.4.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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,28 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [0.4.0](https://github.com/ui5-community/ui5-ecosystem-showcase/compare/cds-plugin-ui5@0.3.0...cds-plugin-ui5@0.4.0) (2023-08-21)
7
+
8
+
9
+ ### Features
10
+
11
+ * **cds-plugin-ui5:** allow to attach custom app pages to cds server ([#800](https://github.com/ui5-community/ui5-ecosystem-showcase/issues/800)) ([0670b5e](https://github.com/ui5-community/ui5-ecosystem-showcase/commit/0670b5e9d01175ecf9d1f0db332963b8c9fec007)), closes [#785](https://github.com/ui5-community/ui5-ecosystem-showcase/issues/785)
12
+
13
+
14
+
15
+
16
+
17
+ # [0.3.0](https://github.com/ui5-community/ui5-ecosystem-showcase/compare/cds-plugin-ui5@0.2.3...cds-plugin-ui5@0.3.0) (2023-08-17)
18
+
19
+
20
+ ### Features
21
+
22
+ * include moduleId in return value to increase reuseability of fu… ([#796](https://github.com/ui5-community/ui5-ecosystem-showcase/issues/796)) ([ae69ed4](https://github.com/ui5-community/ui5-ecosystem-showcase/commit/ae69ed44070f72b0460893904729b49cf4341ffe))
23
+
24
+
25
+
26
+
27
+
6
28
  ## [0.2.3](https://github.com/ui5-community/ui5-ecosystem-showcase/compare/cds-plugin-ui5@0.2.2...cds-plugin-ui5@0.2.3) (2023-08-12)
7
29
 
8
30
  **Note:** Version bump only for package cds-plugin-ui5
package/README.md CHANGED
@@ -21,6 +21,34 @@ npm add cds-plugin-ui5 -D
21
21
 
22
22
  That's it!
23
23
 
24
+ ## Info for UI5 Tooling Extension Developers
25
+
26
+ Custom middlewares may generate virtual app pages which should also be listed as web applications in the welcome page of the `@sap/cds` server. This is possible by assigning a static `getAppPages` function to the middleware function. The following snippet show-cases how this can be done:
27
+
28
+ ```js
29
+ // the middleware factory function
30
+ module.exports = async ({ log, resources, options }) => {
31
+ // create the middleware function
32
+ const mwFn = (req, res, next) => {
33
+ [...]
34
+ };
35
+
36
+ /**
37
+ * Returns an array of app pages to be added to the welcome
38
+ * page of the <code>@sap/cds</code> server.
39
+ * @returns {undefined|string[]} array of app pages
40
+ */
41
+ mwFn.getAppPages = function() {
42
+ return ["/test.html"];
43
+ };
44
+
45
+ // finally return the middleware function
46
+ return mwFn;
47
+ };
48
+ ```
49
+
50
+ The returned app pages will be added to the welcome page within the respective mount path.
51
+
24
52
  ## Support
25
53
 
26
54
  Please use the GitHub bug tracking system to post questions, bug reports or to create pull requests.
package/cds-plugin.js CHANGED
@@ -59,7 +59,7 @@ cds.on("bootstrap", async function bootstrap(app) {
59
59
  // append the HTML pages to the links
60
60
  appInfo.pages.forEach((page) => {
61
61
  const prefix = mountPath !== "/" ? mountPath : "";
62
- links.push(`${prefix}${page.getPath()}`);
62
+ links.push(`${prefix}${page}`);
63
63
  });
64
64
  }
65
65
 
@@ -1,5 +1,7 @@
1
1
  const path = require("path");
2
2
 
3
+ const log = require("./log");
4
+
3
5
  /**
4
6
  * @typedef UI5AppInfo
5
7
  * @type {object}
@@ -69,7 +71,25 @@ module.exports = async function applyUI5Middleware(router, { basePath, configPat
69
71
  });
70
72
  await middlewareManager.applyMiddleware(router);
71
73
 
74
+ // collect app pages from workspace
75
+ const pages = (await rootReader.byGlob("**/*.html")).map((resource) => resource.getPath());
76
+
77
+ // collect app pages from middlewares implementing the getAppPages
78
+ middlewareManager.middlewareExecutionOrder?.map((name) => {
79
+ const { middleware } = middlewareManager.middleware?.[name] || {};
80
+ if (typeof middleware?.getAppPages === "function") {
81
+ const customAppPages = middleware.getAppPages();
82
+ if (Array.isArray(customAppPages)) {
83
+ pages.push(...customAppPages);
84
+ } else {
85
+ if (customAppPages) {
86
+ log.warn(`The middleware ${name} returns an unexpected value for "getAppPages". The value must be either undefined or string[]! Ignoring app pages from middleware!`);
87
+ }
88
+ }
89
+ }
90
+ });
91
+
72
92
  return {
73
- pages: await rootReader.byGlob("**/*.html"),
93
+ pages,
74
94
  };
75
95
  };
@@ -112,7 +112,21 @@ module.exports = async function findUI5Modules({ cwd, skipLocalApps, skipDeps })
112
112
 
113
113
  // determine the module path based on the location of the ui5.yaml
114
114
  const modulePath = path.dirname(ui5YamlPath);
115
- apps.push({ modulePath, mountPath });
115
+
116
+ // manually get the module name as defined in package.json
117
+ // skipDeps is only true if we are looking for UI5 apps inside a CAP server project
118
+ // in all other cases the module name equals the appDir
119
+ let moduleName;
120
+ if (skipDeps) {
121
+ const packageJsonPath = require.resolve(path.join(appDir, "package.json"), {
122
+ paths: [cwd],
123
+ });
124
+ const packageJsonContent = fs.readFileSync(packageJsonPath, "utf-8");
125
+ moduleName = JSON.parse(packageJsonContent).name;
126
+ }
127
+ const moduleId = moduleName || appDir;
128
+
129
+ apps.push({ moduleId, modulePath, mountPath });
116
130
  }
117
131
  }
118
132
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cds-plugin-ui5",
3
- "version": "0.2.3",
3
+ "version": "0.4.0",
4
4
  "description": "A CAP server cds-plugin to inject the middlewares of all related UI5 tooling based projects.",
5
5
  "author": "Peter Muessig",
6
6
  "license": "Apache-2.0",
@@ -24,5 +24,5 @@
24
24
  "@sap/cds": ">=6.8.2",
25
25
  "express": ">=4.18.2"
26
26
  },
27
- "gitHead": "6233f8b4d2bfaf7e7f2b32afe4320acb7fab521a"
27
+ "gitHead": "f187f504307eafdf24b94374264d298774331ab3"
28
28
  }