cds-plugin-ui5 0.9.7 → 0.10.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 +22 -0
- package/README.md +9 -0
- package/cds-plugin.js +43 -21
- package/lib/applyUI5Middleware.js +3 -2
- package/lib/findUI5Modules.js +2 -3
- package/package.json +5 -5
- package/lib/log.js +0 -26
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.10.0](https://github.com/ui5-community/ui5-ecosystem-showcase/compare/cds-plugin-ui5@0.9.8...cds-plugin-ui5@0.10.0) (2024-08-29)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **cds-plugin-ui5:** use CAP logging, custom formatter using colors, allow log levels ([#1067](https://github.com/ui5-community/ui5-ecosystem-showcase/issues/1067)) ([4be3b08](https://github.com/ui5-community/ui5-ecosystem-showcase/commit/4be3b08e3a70e1f07b3ae4572928fcec840b7321))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## [0.9.8](https://github.com/ui5-community/ui5-ecosystem-showcase/compare/cds-plugin-ui5@0.9.7...cds-plugin-ui5@0.9.8) (2024-08-11)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Bug Fixes
|
|
21
|
+
|
|
22
|
+
* decouple tooling extensions from UI5 tooling version ([#1058](https://github.com/ui5-community/ui5-ecosystem-showcase/issues/1058)) ([6694c59](https://github.com/ui5-community/ui5-ecosystem-showcase/commit/6694c59422ac37d9aea971679de46f5f59b8025c)), closes [#1054](https://github.com/ui5-community/ui5-ecosystem-showcase/issues/1054)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
6
28
|
## [0.9.7](https://github.com/ui5-community/ui5-ecosystem-showcase/compare/cds-plugin-ui5@0.9.6...cds-plugin-ui5@0.9.7) (2024-07-23)
|
|
7
29
|
|
|
8
30
|
|
package/README.md
CHANGED
|
@@ -75,6 +75,15 @@ The configuration can also be injected with the environment variable `CDS_PLUGIN
|
|
|
75
75
|
CDS_PLUGIN_UI5_MODULES="{ \"ui5-bookshop\": { \"mountPath\": \"/the-bookshop\" } }" cds-serve
|
|
76
76
|
```
|
|
77
77
|
|
|
78
|
+
#### Logger
|
|
79
|
+
|
|
80
|
+
The `cds-plugin-ui5` uses the logger from CDS. By default, it adds coloring to the logs from CDS. This can be disabled in general by using the environment variable `NO_COLOR` for the logger overall or specifically for the `cds-plugin-ui5` by setting the environment variable `CDS_PLUGIN_UI5_NO_CUSTOM_LOGGER`.
|
|
81
|
+
|
|
82
|
+
```sh
|
|
83
|
+
# disable the colored logging extension of the cds-plugin-ui5
|
|
84
|
+
CDS_PLUGIN_UI5_NO_CUSTOM_LOGGER=1 cds watch
|
|
85
|
+
```
|
|
86
|
+
|
|
78
87
|
#### UI5 Server Middlewares
|
|
79
88
|
|
|
80
89
|
If you require to configure the UI5 server middlewares, you can do so by adding some selected configuration options in the `package.json` of the CDS server in the section: `cds/cds-plugin-ui5/modules/%moduleId%`
|
package/cds-plugin.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
const log = require("./lib/log");
|
|
2
|
-
|
|
3
1
|
// >> IMPORTANT <<
|
|
4
2
|
//
|
|
5
3
|
// JEST has issues with dynamic imports and will fail when they are used,
|
|
@@ -16,17 +14,40 @@ const log = require("./lib/log");
|
|
|
16
14
|
//
|
|
17
15
|
// To disable JEST we rely on env variables (see https://jestjs.io/docs/environment-variables)
|
|
18
16
|
if (process.env.NODE_ENV === "test" && process.env.JEST_WORKER_ID && process.env.CDS_PLUGIN_UI5_ACTIVE !== "true") {
|
|
19
|
-
log
|
|
17
|
+
console.log(
|
|
18
|
+
process.env.NO_COLOR ? "[%s] %s" : "\x1b[36m[%s]\x1b[0m \x1b[31m%s\x1b[0m",
|
|
19
|
+
"cds-plugin-ui5",
|
|
20
|
+
"Skip execution because JEST is running tests! To force the execution of the plugin set env var CDS_PLUGIN_UI5_ACTIVE=true..."
|
|
21
|
+
);
|
|
20
22
|
return;
|
|
21
23
|
}
|
|
22
24
|
if (process.env.CDS_PLUGIN_UI5_ACTIVE === "false") {
|
|
23
|
-
log.
|
|
25
|
+
console.log(process.env.NO_COLOR ? "[%s] %s" : "\x1b[36m[%s]\x1b[0m \x1b[31m%s\x1b[0m", "cds-plugin-ui5", "Skip execution because it has been disabled by env var CDS_PLUGIN_UI5_ACTIVE!");
|
|
24
26
|
return;
|
|
25
27
|
}
|
|
26
28
|
|
|
27
29
|
// @sap/cds/lib/index.js#138: global.cds = cds // REVISIT: using global.cds seems wrong
|
|
28
30
|
const cds = global.cds || require("@sap/cds"); // reuse already loaded cds!
|
|
29
31
|
|
|
32
|
+
// add color support to the logger
|
|
33
|
+
if (!(process.env.NO_COLOR || process.env.CDS_PLUGIN_UI5_NO_CUSTOM_LOGGER)) {
|
|
34
|
+
const LOG_COLORS = {
|
|
35
|
+
TRACE: "\x1b[0m", // default
|
|
36
|
+
DEBUG: "\x1b[34m", // blue
|
|
37
|
+
INFO: "\x1b[32m", // green
|
|
38
|
+
WARN: "\x1b[33m", // yellow
|
|
39
|
+
ERROR: "\x1b[31m", // red
|
|
40
|
+
};
|
|
41
|
+
const LOG_LEVEL_TO_COLOR = Object.fromEntries(Object.keys(LOG_COLORS).map((level) => [cds.log.levels[level], LOG_COLORS[level]]));
|
|
42
|
+
const LOG_LEVEL_TO_TEXT = Object.fromEntries(Object.keys(LOG_COLORS).map((level) => [cds.log.levels[level], level]));
|
|
43
|
+
cds.log.format = (label, level, ...args) => {
|
|
44
|
+
return ["\x1b[36m[%s]\x1b[0m %s[%s]\x1b[0m %s", label, LOG_LEVEL_TO_COLOR[level], LOG_LEVEL_TO_TEXT[level], ...args];
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// create a logger for the cds-plugin-ui5
|
|
49
|
+
const LOG = cds.log("cds-plugin-ui5");
|
|
50
|
+
|
|
30
51
|
const findUI5Modules = require("./lib/findUI5Modules");
|
|
31
52
|
const createPatchedRouter = require("./lib/createPatchedRouter");
|
|
32
53
|
const applyUI5Middleware = require("./lib/applyUI5Middleware");
|
|
@@ -35,10 +56,10 @@ const rewriteHTML = require("./lib/rewriteHTML");
|
|
|
35
56
|
// identify whether the execution should be skipped
|
|
36
57
|
let skip = false;
|
|
37
58
|
if (process.env["ui5-middleware-cap"]) {
|
|
38
|
-
|
|
59
|
+
LOG.info("Skip execution of plugin because is has been started via ui5-middleware-cap!");
|
|
39
60
|
skip = true;
|
|
40
61
|
} else if (process.env["dev-approuter"]) {
|
|
41
|
-
|
|
62
|
+
LOG.info("Skip execution of plugin because is has been started via dev-approuter!");
|
|
42
63
|
skip = true;
|
|
43
64
|
}
|
|
44
65
|
|
|
@@ -108,11 +129,11 @@ if (!skip) {
|
|
|
108
129
|
const cdsdkVersion = getCDSDKVersion();
|
|
109
130
|
|
|
110
131
|
// logging the version of the cds-plugin-ui5
|
|
111
|
-
|
|
132
|
+
LOG.info(`Running cds-plugin-ui5@${cdsPluginUI5Version} (@sap/cds-dk@${cdsdkVersion}, @sap/cds@${cds.version})`);
|
|
112
133
|
if (global.__cds_loaded_from?.size > 1) {
|
|
113
|
-
|
|
134
|
+
LOG.warn(" !! Multiple versions of @sap/cds loaded !!");
|
|
114
135
|
global.__cds_loaded_from.forEach((cdsPath) => {
|
|
115
|
-
|
|
136
|
+
LOG.warn(` => ${cdsPath}`);
|
|
116
137
|
});
|
|
117
138
|
}
|
|
118
139
|
|
|
@@ -127,19 +148,19 @@ if (!skip) {
|
|
|
127
148
|
// CDS server until the bootstrap is completed and the UI5
|
|
128
149
|
// middlewares for the UI5 applications are properly available
|
|
129
150
|
cds.on("served", async function served(/* cdsServices */) {
|
|
130
|
-
|
|
151
|
+
LOG.debug("served");
|
|
131
152
|
await bootstrapCompleted;
|
|
132
153
|
});
|
|
133
154
|
|
|
134
155
|
// hook into the "bootstrap" event to startup the UI5 middlewares
|
|
135
156
|
// for the available UI5 applications in the CDS server and its deps
|
|
136
157
|
cds.on("bootstrap", async function bootstrap(app) {
|
|
137
|
-
|
|
158
|
+
LOG.debug("bootstrap");
|
|
138
159
|
|
|
139
160
|
// only for cds serve or serving all services the cds-plugin-ui5 is active
|
|
140
161
|
if (cds.cli?.command === "serve" || cds.options?.service === "all") {
|
|
141
162
|
const cwd = cds.env?._home || process.cwd();
|
|
142
|
-
const ui5Modules = await findUI5Modules({ cwd, cds });
|
|
163
|
+
const ui5Modules = await findUI5Modules({ cwd, cds, LOG });
|
|
143
164
|
const { localApps, config } = ui5Modules;
|
|
144
165
|
|
|
145
166
|
const links = [];
|
|
@@ -149,7 +170,7 @@ if (!skip) {
|
|
|
149
170
|
const { moduleId, mountPath, modulePath } = ui5Module;
|
|
150
171
|
|
|
151
172
|
// mounting the Router for the UI5 application to the CDS server
|
|
152
|
-
|
|
173
|
+
LOG.info(`Mounting ${mountPath} to UI5 app ${modulePath} (id=${moduleId})${config[moduleId] ? ` using config=${JSON.stringify(config[moduleId])}` : ""}`);
|
|
153
174
|
|
|
154
175
|
// create a patched router
|
|
155
176
|
const router = await createPatchedRouter();
|
|
@@ -160,6 +181,7 @@ if (!skip) {
|
|
|
160
181
|
cwd,
|
|
161
182
|
basePath: modulePath,
|
|
162
183
|
...(config[moduleId] || {}),
|
|
184
|
+
LOG,
|
|
163
185
|
});
|
|
164
186
|
|
|
165
187
|
// register the router to the specified mount path
|
|
@@ -228,7 +250,7 @@ if (!skip) {
|
|
|
228
250
|
);
|
|
229
251
|
ul.innerHTML = newLis.join("\n");
|
|
230
252
|
} else {
|
|
231
|
-
|
|
253
|
+
LOG.warn(`Failed to inject application links into CDS index page!`);
|
|
232
254
|
}
|
|
233
255
|
}
|
|
234
256
|
);
|
|
@@ -245,14 +267,14 @@ if (!skip) {
|
|
|
245
267
|
if (idxOfServeStatic !== -1) {
|
|
246
268
|
middlewareStack.splice(idxOfServeStatic, 0, cmw);
|
|
247
269
|
} else {
|
|
248
|
-
|
|
270
|
+
LOG.error(`Failed to determine welcome page middleware! The links of the application pages may not work properly!`);
|
|
249
271
|
}
|
|
250
272
|
} else {
|
|
251
|
-
|
|
273
|
+
LOG.error(`Failed to inject application pages to welcome page! The links of the application pages may not work properly!`);
|
|
252
274
|
}
|
|
253
275
|
}
|
|
254
276
|
} else {
|
|
255
|
-
|
|
277
|
+
LOG.info("Skip execution of plugin! The plugin is only active for 'cds serve'!");
|
|
256
278
|
}
|
|
257
279
|
|
|
258
280
|
// bootstrap completed, unlock the "served" event
|
|
@@ -313,7 +335,7 @@ if (!skip) {
|
|
|
313
335
|
// sanitize the package.json if it exists
|
|
314
336
|
const packageJsonPath = join(this.task.dest, "package.json");
|
|
315
337
|
if (existsSync(packageJsonPath)) {
|
|
316
|
-
|
|
338
|
+
LOG.info(`Sanitizing the package.json for "${namespace}"...`);
|
|
317
339
|
const packageJson = JSON.parse(await readFile(packageJsonPath), "utf-8");
|
|
318
340
|
let modified = false;
|
|
319
341
|
// remove the workspace configuration
|
|
@@ -338,13 +360,13 @@ if (!skip) {
|
|
|
338
360
|
}
|
|
339
361
|
// update the package-lock.json if it exists
|
|
340
362
|
if (existsSync(join(this.task.dest, "package-lock.json"))) {
|
|
341
|
-
|
|
363
|
+
LOG.info(`Updating the package-lock.json for "${namespace}"...`);
|
|
342
364
|
// run the npm install --package-lock-only to only update the package-lock.json
|
|
343
365
|
// without installing the dependencies to node_modules
|
|
344
366
|
try {
|
|
345
367
|
/* const { stdout, stderr } = */ await exec("npm install --package-lock-only", { cwd: this.task.dest });
|
|
346
368
|
} catch (e) {
|
|
347
|
-
|
|
369
|
+
LOG.error(`Failed to update the package-lock.json for "${namespace}"! Error: ${e.code} - ${e.message}`);
|
|
348
370
|
}
|
|
349
371
|
}
|
|
350
372
|
}
|
|
@@ -354,7 +376,7 @@ if (!skip) {
|
|
|
354
376
|
if (!satisfies(cdsdkVersion, ">=7.5.0")) {
|
|
355
377
|
// TODO: add error message to inform the user that the cds build task is not available
|
|
356
378
|
// and that the @sap/cds-dk version is too old to support the cds build task
|
|
357
|
-
|
|
379
|
+
LOG.warn("The cds build task requires @sap/cds-dk version >= 7.5.0! Skipping execution as your @sap/cds-dk version is too old...");
|
|
358
380
|
}
|
|
359
381
|
}
|
|
360
382
|
}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
const path = require("path");
|
|
2
2
|
const fs = require("fs");
|
|
3
3
|
|
|
4
|
-
const log = require("./log");
|
|
5
|
-
|
|
6
4
|
/**
|
|
7
5
|
* @typedef UI5AppInfo
|
|
8
6
|
* @type {object}
|
|
@@ -21,6 +19,7 @@ const log = require("./log");
|
|
|
21
19
|
* @property {string} [workspaceConfigPath] /!\ RESTRICTED /!\ - path to the ui5-workspace.yaml (defaults to "${basePath}/${workspaceConfigFile}")
|
|
22
20
|
* @property {string} [versionOverride] Framework version to use instead of the one defined in the root project
|
|
23
21
|
* @property {string} [cacheMode] /!\ RESTRICTED /!\ - Cache mode to use when consuming SNAPSHOT versions of a framework (one of: Default|False|Off)
|
|
22
|
+
* @property {string} [log] the logger (defaults to console)
|
|
24
23
|
*/
|
|
25
24
|
|
|
26
25
|
// inspired by https://github.com/SAP/karma-ui5/blob/main/lib/framework.js#L466-L522
|
|
@@ -38,6 +37,8 @@ module.exports = async function applyUI5Middleware(router, options) {
|
|
|
38
37
|
options.cwd = options.cwd || process.cwd();
|
|
39
38
|
options.basePath = options.basePath || process.cwd();
|
|
40
39
|
|
|
40
|
+
const log = options.log || console;
|
|
41
|
+
|
|
41
42
|
const configPath = options.configPath || options.basePath;
|
|
42
43
|
const configFile = options.configFile || "ui5.yaml";
|
|
43
44
|
const workspaceConfigPath = options.workspaceConfigPath || options.basePath;
|
package/lib/findUI5Modules.js
CHANGED
|
@@ -2,8 +2,6 @@ const path = require("path");
|
|
|
2
2
|
const fs = require("fs");
|
|
3
3
|
const yaml = require("js-yaml");
|
|
4
4
|
|
|
5
|
-
const log = require("./log");
|
|
6
|
-
|
|
7
5
|
/**
|
|
8
6
|
* @typedef UI5Module
|
|
9
7
|
* @type {object}
|
|
@@ -19,9 +17,10 @@ const log = require("./log");
|
|
|
19
17
|
* @param {string} options.cds reference to cds
|
|
20
18
|
* @param {string} options.skipLocalApps skip local apps
|
|
21
19
|
* @param {string} options.skipDeps skip dependencies
|
|
20
|
+
* @param {string} options.log the logger (defaults to console)
|
|
22
21
|
* @returns {Array<UI5Module>} array of UI5 module
|
|
23
22
|
*/
|
|
24
|
-
module.exports = async function findUI5Modules({ cwd, cds, skipLocalApps, skipDeps }) {
|
|
23
|
+
module.exports = async function findUI5Modules({ cwd, cds, skipLocalApps, skipDeps, log = console }) {
|
|
25
24
|
// extract the modules configuration from the package.json
|
|
26
25
|
const pkgJson = require(path.join(cwd, "package.json"));
|
|
27
26
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cds-plugin-ui5",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "A CDS server plugin to inject the middlewares of all related UI5 tooling based projects.",
|
|
5
5
|
"author": "Peter Muessig",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -11,9 +11,9 @@
|
|
|
11
11
|
"directory": "packages/cds-plugin-ui5"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@ui5/fs": "^
|
|
15
|
-
"@ui5/project": "^
|
|
16
|
-
"@ui5/server": "^
|
|
14
|
+
"@ui5/fs": "^4.0.0",
|
|
15
|
+
"@ui5/project": "^4.0.2",
|
|
16
|
+
"@ui5/server": "^4.0.3",
|
|
17
17
|
"js-yaml": "^4.1.0",
|
|
18
18
|
"node-html-parser": "^6.1.13",
|
|
19
19
|
"semver": "^7.6.3"
|
|
@@ -26,5 +26,5 @@
|
|
|
26
26
|
"@sap/cds": ">=6.8.2",
|
|
27
27
|
"express": ">=4.18.2"
|
|
28
28
|
},
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "8c1f5e3bd4222b9767494776bdb0a686db0f12f9"
|
|
30
30
|
}
|
package/lib/log.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
const colors = {
|
|
2
|
-
log: "\x1b[0m", // default
|
|
3
|
-
debug: "\x1b[34m", // blue
|
|
4
|
-
info: "\x1b[32m", // green
|
|
5
|
-
warn: "\x1b[33m", // yellow
|
|
6
|
-
error: "\x1b[31m", // red
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* helper to log colorful messages
|
|
11
|
-
* @param {string} type the type of the message
|
|
12
|
-
* @param {...string} message the message text
|
|
13
|
-
*/
|
|
14
|
-
function log(type, ...message) {
|
|
15
|
-
if (!console[type]) {
|
|
16
|
-
type = "log";
|
|
17
|
-
}
|
|
18
|
-
const args = [`\x1b[36m[cds-plugin-ui5]\x1b[0m %s[%s]\x1b[0m %s`, colors[type], type];
|
|
19
|
-
message && args.push(...message);
|
|
20
|
-
console[type].apply(console[type], args);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
module.exports = log;
|
|
24
|
-
Object.keys(colors).forEach((level) => {
|
|
25
|
-
module.exports[level] = log.bind(this, level);
|
|
26
|
-
});
|