cds-plugin-ui5 0.1.0 → 0.1.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/CHANGELOG.md +20 -2
- package/cds-plugin.js +93 -17
- package/package.json +9 -8
package/CHANGELOG.md
CHANGED
|
@@ -3,9 +3,27 @@
|
|
|
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
|
-
|
|
6
|
+
## [0.1.2](https://github.com/ui5-community/ui5-ecosystem-showcase/compare/cds-plugin-ui5@0.1.1...cds-plugin-ui5@0.1.2) (2023-06-15)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* update dependencies ([#754](https://github.com/ui5-community/ui5-ecosystem-showcase/issues/754)) ([3893473](https://github.com/ui5-community/ui5-ecosystem-showcase/commit/389347300795cfed881dc8be72eeb59d1bf45fff))
|
|
12
|
+
|
|
13
|
+
|
|
7
14
|
|
|
8
15
|
|
|
16
|
+
|
|
17
|
+
## [0.1.1](https://github.com/ui5-community/ui5-ecosystem-showcase/compare/cds-plugin-ui5@0.1.0...cds-plugin-ui5@0.1.1) (2023-06-03)
|
|
18
|
+
|
|
19
|
+
### Bug Fixes
|
|
20
|
+
|
|
21
|
+
- **cds-plugin-ui5:** disable gzip encoding when livereload is used by CAP ([#750](https://github.com/ui5-community/ui5-ecosystem-showcase/issues/750)) ([b131efa](https://github.com/ui5-community/ui5-ecosystem-showcase/commit/b131efaa239b66d55350dab573d6a0a9ef978625))
|
|
22
|
+
- **cds-plugin-ui5:** inject UI5 app pages ([#752](https://github.com/ui5-community/ui5-ecosystem-showcase/issues/752)) ([0d7415d](https://github.com/ui5-community/ui5-ecosystem-showcase/commit/0d7415d0630d33f851dd816015f3a2f394ce59d3))
|
|
23
|
+
- update dependencies ([#749](https://github.com/ui5-community/ui5-ecosystem-showcase/issues/749)) ([b1c8cfb](https://github.com/ui5-community/ui5-ecosystem-showcase/commit/b1c8cfb4da1dcd0ae91bee181f539684d767d067))
|
|
24
|
+
|
|
25
|
+
# 0.1.0 (2023-05-26)
|
|
26
|
+
|
|
9
27
|
### Features
|
|
10
28
|
|
|
11
|
-
|
|
29
|
+
- **cds-plugin-ui5:** initial poc for UI5 cds-plugin ([#746](https://github.com/ui5-community/ui5-ecosystem-showcase/issues/746)) ([70a7477](https://github.com/ui5-community/ui5-ecosystem-showcase/commit/70a7477410ef8a75bc994f117cc0d7fcffef2fed))
|
package/cds-plugin.js
CHANGED
|
@@ -11,20 +11,41 @@ const applyUI5Middleware = require("./lib/applyUI5Middleware");
|
|
|
11
11
|
// to disable the ui5-middleware-cap if used in apps
|
|
12
12
|
process.env["cds-plugin-ui5"] = true;
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
/**
|
|
15
|
+
* helper to log colorful messages
|
|
16
|
+
* @param {string} type the type of the message
|
|
17
|
+
* @param {string} message the message text
|
|
18
|
+
*/
|
|
19
|
+
function log(type, message) {
|
|
20
|
+
const colors = {
|
|
21
|
+
log: "\x1b[0m", // default
|
|
22
|
+
info: "\x1b[32m", // green
|
|
23
|
+
debug: "\x1b[34m", // blue
|
|
24
|
+
warn: "\x1b[33m", // yellow
|
|
25
|
+
error: "\x1b[31m", // red
|
|
26
|
+
};
|
|
27
|
+
if (!console[type]) {
|
|
28
|
+
type = "log";
|
|
29
|
+
}
|
|
30
|
+
console[type](`\x1b[36m[cds-ui5-plugin]\x1b[0m %s[%s]\x1b[0m %s`, colors[type], type, message);
|
|
31
|
+
}
|
|
16
32
|
|
|
17
|
-
|
|
18
|
-
|
|
33
|
+
cds.on("bootstrap", async function bootstrap(app) {
|
|
34
|
+
log("debug", "bootstrap");
|
|
19
35
|
|
|
20
|
-
// lookup the app folder
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
36
|
+
// lookup the app folder to determine local apps and ui5 app directories
|
|
37
|
+
const localApps = new Set(),
|
|
38
|
+
appDirs = [];
|
|
39
|
+
fs.readdirSync(path.join(process.cwd(), "app"), { withFileTypes: true })
|
|
40
|
+
.filter((f) => f.isDirectory())
|
|
41
|
+
.forEach((d) => localApps.add(d.name));
|
|
42
|
+
localApps.forEach((e) => {
|
|
43
|
+
const d = path.join(process.cwd(), "app", e);
|
|
44
|
+
if (fs.existsSync(path.join(d, "ui5.yaml"))) {
|
|
45
|
+
localApps.delete(e);
|
|
46
|
+
appDirs.push(d);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
28
49
|
|
|
29
50
|
// lookup the UI5 dependencies
|
|
30
51
|
const pkgJson = require(path.join(process.cwd(), "package.json"));
|
|
@@ -49,6 +70,7 @@ cds.on("bootstrap", async (app) => {
|
|
|
49
70
|
// if apps are available, attach the middlewares of the UI5 apps
|
|
50
71
|
// to the express of the CAP server via a express router
|
|
51
72
|
if (appDirs) {
|
|
73
|
+
const links = [];
|
|
52
74
|
for await (const appDir of appDirs) {
|
|
53
75
|
// read the ui5.yaml file to extract the configuration
|
|
54
76
|
const ui5YamlPath = require.resolve(path.join(appDir, "ui5.yaml"), {
|
|
@@ -60,7 +82,7 @@ cds.on("bootstrap", async (app) => {
|
|
|
60
82
|
ui5Configs = yaml.loadAll(content);
|
|
61
83
|
} catch (err) {
|
|
62
84
|
if (err.name === "YAMLException") {
|
|
63
|
-
|
|
85
|
+
log("error", `Failed to read ${ui5YamlPath}!`);
|
|
64
86
|
}
|
|
65
87
|
throw err;
|
|
66
88
|
}
|
|
@@ -74,12 +96,19 @@ cds.on("bootstrap", async (app) => {
|
|
|
74
96
|
}
|
|
75
97
|
|
|
76
98
|
// mounting the Router for the application to the CAP server
|
|
77
|
-
|
|
99
|
+
log("info", `Mounting ${mountPath} to UI5 app ${appDir}`);
|
|
78
100
|
const modulePath = path.dirname(ui5YamlPath);
|
|
79
101
|
|
|
80
102
|
// create the router and get rid of the mount path
|
|
81
103
|
const router = new Router();
|
|
82
104
|
router.use(function (req, res, next) {
|
|
105
|
+
// disable the compression when livereload is used
|
|
106
|
+
// for loading html-related content (via accept header)
|
|
107
|
+
const accept = req.headers["accept"]?.indexOf("html");
|
|
108
|
+
if (accept && res._livereload) {
|
|
109
|
+
req.headers["accept-encoding"] = "identity";
|
|
110
|
+
}
|
|
111
|
+
// remove the mount path from the url
|
|
83
112
|
req.originalUrl = req.url;
|
|
84
113
|
req.baseUrl = "/";
|
|
85
114
|
next();
|
|
@@ -96,18 +125,65 @@ cds.on("bootstrap", async (app) => {
|
|
|
96
125
|
pages.forEach((page) => {
|
|
97
126
|
const prefix = mountPath !== "/" ? mountPath : "";
|
|
98
127
|
links.push(`${prefix}${page.getPath()}`);
|
|
99
|
-
console.log(`${prefix}${page.getPath()}`);
|
|
100
128
|
});
|
|
101
129
|
|
|
102
130
|
// mount the router to the determined mount path
|
|
103
131
|
app.use(`${mountPath}`, router);
|
|
104
132
|
}
|
|
133
|
+
|
|
134
|
+
// register the custom middleware (similar like in @sap/cds/server.js)
|
|
135
|
+
app.get("/", function appendLinksToIndex(req, res, next) {
|
|
136
|
+
var send = res.send;
|
|
137
|
+
res.send = function (content) {
|
|
138
|
+
// the first <ul> element contains the links to the
|
|
139
|
+
// application pages which is fully under control of
|
|
140
|
+
// our plugin now and we keep all links to static
|
|
141
|
+
// pages to ensure coop with classic apps
|
|
142
|
+
const HTMLParser = require("node-html-parser");
|
|
143
|
+
const doc = new HTMLParser.parse(content);
|
|
144
|
+
const ul = doc.getElementsByTagName("ul")?.[0];
|
|
145
|
+
if (ul) {
|
|
146
|
+
const newLis = [];
|
|
147
|
+
const lis = ul.getElementsByTagName("li");
|
|
148
|
+
lis?.forEach((li) => {
|
|
149
|
+
const appDir = li.firstChild?.text?.split("/")?.[1];
|
|
150
|
+
if (localApps.has(appDir)) {
|
|
151
|
+
newLis.push(li.toString());
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
newLis.push(...links.map((link) => `<li><a href="${link}">${link}</a></li>`));
|
|
155
|
+
ul.innerHTML = newLis.join("\n");
|
|
156
|
+
content = doc.toString();
|
|
157
|
+
} else {
|
|
158
|
+
log("warn", `Failed to inject application links into CAP index page!`);
|
|
159
|
+
}
|
|
160
|
+
send.apply(this, arguments);
|
|
161
|
+
};
|
|
162
|
+
//log("debug", req.url);
|
|
163
|
+
next();
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
// move our middleware before the CAP index serve middleware to
|
|
167
|
+
// allow that we can intercept the response and modify it to
|
|
168
|
+
// inject our application pages an remove the exitsing ones
|
|
169
|
+
const middlewareStack = app?._router?.stack;
|
|
170
|
+
if (Array.isArray(middlewareStack)) {
|
|
171
|
+
const cmw = middlewareStack.pop();
|
|
172
|
+
const idxOfServeStatic = middlewareStack.findIndex((layer) => layer.name === "serveStatic");
|
|
173
|
+
if (idxOfServeStatic !== -1) {
|
|
174
|
+
middlewareStack.splice(idxOfServeStatic, 0, cmw);
|
|
175
|
+
} else {
|
|
176
|
+
log("error", `Failed to determine CAP overview page middleware! You need to manually open the application pages!`);
|
|
177
|
+
}
|
|
178
|
+
} else {
|
|
179
|
+
log("error", `Failed to inject application pages to CAP overview page! You need to manually open the application pages!`);
|
|
180
|
+
}
|
|
105
181
|
}
|
|
106
182
|
});
|
|
107
183
|
|
|
108
|
-
//
|
|
184
|
+
// return callback for plugin activation
|
|
109
185
|
module.exports = {
|
|
110
186
|
activate: function activate(conf) {
|
|
111
|
-
|
|
187
|
+
log("debug", "activate", conf);
|
|
112
188
|
},
|
|
113
189
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cds-plugin-ui5",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
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",
|
|
@@ -10,18 +10,19 @@
|
|
|
10
10
|
"directory": "packages/cds-plugin-ui5"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@ui5/fs": "^3.0.
|
|
14
|
-
"@ui5/project": "^3.3.
|
|
15
|
-
"@ui5/server": "^3.1.
|
|
16
|
-
"js-yaml": "^4.1.0"
|
|
13
|
+
"@ui5/fs": "^3.0.4",
|
|
14
|
+
"@ui5/project": "^3.3.2",
|
|
15
|
+
"@ui5/server": "^3.1.3",
|
|
16
|
+
"js-yaml": "^4.1.0",
|
|
17
|
+
"node-html-parser": "^6.1.5"
|
|
17
18
|
},
|
|
18
19
|
"devDependencies": {
|
|
19
|
-
"@sap/cds": "^6.8.
|
|
20
|
+
"@sap/cds": "^6.8.4",
|
|
20
21
|
"express": "^4.18.2"
|
|
21
22
|
},
|
|
22
23
|
"peerDependencies": {
|
|
23
|
-
"@sap/cds": ">=6.8.
|
|
24
|
+
"@sap/cds": ">=6.8.2",
|
|
24
25
|
"express": ">=4.18.2"
|
|
25
26
|
},
|
|
26
|
-
"gitHead": "
|
|
27
|
+
"gitHead": "84c3a3e5f36915ecd2ba1325c74635a9b6fab09d"
|
|
27
28
|
}
|