cds-plugin-ui5 0.6.0 → 0.6.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 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.6.2](https://github.com/ui5-community/ui5-ecosystem-showcase/compare/cds-plugin-ui5@0.6.1...cds-plugin-ui5@0.6.2) (2023-09-08)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **cds-plugin-ui5:** allow relative config files in package.json ([#838](https://github.com/ui5-community/ui5-ecosystem-showcase/issues/838)) ([735b24d](https://github.com/ui5-community/ui5-ecosystem-showcase/commit/735b24d34cebee5463c97c3bb5a3d58e07dace24))
12
+
13
+
14
+
15
+
16
+
17
+ ## [0.6.1](https://github.com/ui5-community/ui5-ecosystem-showcase/compare/cds-plugin-ui5@0.6.0...cds-plugin-ui5@0.6.1) (2023-09-08)
18
+
19
+
20
+ ### Bug Fixes
21
+
22
+ * **cds-plugin-ui5:** flexible mount path configuration ([#837](https://github.com/ui5-community/ui5-ecosystem-showcase/issues/837)) ([dc31a9e](https://github.com/ui5-community/ui5-ecosystem-showcase/commit/dc31a9e30f628c7236c93281909fafe19234bafe))
23
+
24
+
25
+
26
+
27
+
6
28
  # [0.6.0](https://github.com/ui5-community/ui5-ecosystem-showcase/compare/cds-plugin-ui5@0.5.2...cds-plugin-ui5@0.6.0) (2023-09-08)
7
29
 
8
30
 
package/README.md CHANGED
@@ -23,7 +23,61 @@ That's it!
23
23
 
24
24
  ### Configuration
25
25
 
26
- The plugin can be configured using the `cds-plugin-ui5` section in the `package.json`. To define a custom configFile for any module you can add a configuration object for each module in the `modules` section:
26
+ The plugin accepts configuration to control the mount path for the embedding into the CAP server and selected configuration options for the UI5 server middlewares which are embedded into the mount path of the CAP server.
27
+
28
+ #### Mount Path
29
+
30
+ The mount path of the UI5 application configures the nested Router for the UI5 server middlewares to run under this predefined path. It is by default derived from the `metadata/name` of the `ui5.yaml`:
31
+
32
+ ```yaml
33
+ specVersion: "3.0"
34
+ metadata:
35
+ name: ui5.bookshop
36
+ type: application
37
+ ```
38
+
39
+ This configuration can be overruled by adding a the `customConfiguration/cds-plugin-ui5/mountPath` option into the `ui5.yaml`:
40
+
41
+ ```yaml
42
+ specVersion: "3.0"
43
+ metadata:
44
+ name: ui5.bookshop
45
+ type: application
46
+ customConfiguration:
47
+ cds-plugin-ui5:
48
+ mountPath: /bookshop
49
+ ```
50
+
51
+ In some cases it is necessary to overrule the UI5 application local configuration in the CAP server. Therefore, you can add custom configuration into the `package.json` of the CAP server into the section: `cds/cds-plugin-ui5/modules/%moduleId%/mountPath`
52
+
53
+ ```json
54
+ {
55
+ "name": "cds-bookshop",
56
+ [...]
57
+ "cds": {
58
+ [...]
59
+ "cds-plugin-ui5": {
60
+ "modules": {
61
+ "ui5-bookshop": {
62
+ "mountPath": "/the-bookshop"
63
+ }
64
+ }
65
+ }
66
+ }
67
+ }
68
+ ```
69
+
70
+ The `moduleId` is either the directory name for local apps in the `app` directory of the CAP server or for dependencies the `name` from the `package.json`.
71
+
72
+ The configuration can also be injected with the environment variable `CDS_PLUGIN_UI5_MODULES`. It contains the JSON string from the configuration above, e.g.:
73
+
74
+ ```sh
75
+ CDS_PLUGIN_UI5_MODULES="{ \"ui5-bookshop\": { \"mountPath\": \"/the-bookshop\" } }" cds-serve
76
+ ```
77
+
78
+ #### UI5 Server Middlewares
79
+
80
+ 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 CAP server in the section: `cds/cds-plugin-ui5/modules/%moduleId%`
27
81
 
28
82
  ```json
29
83
  {
@@ -45,14 +99,25 @@ The plugin can be configured using the `cds-plugin-ui5` section in the `package.
45
99
  }
46
100
  ```
47
101
 
48
- The key is the `moduleId` which is either the directory name for local apps in the `app` directory of the CAP server or for dependencies the `name` from the `package.json`. As value you can specify an alternative `configFile`, `workspaceConfigFile`, `workspaceName`, and/or `versionOverride`. The location of the config files are relative to the modules' base path.
102
+ The `moduleId` is either the directory name for local apps in the `app` directory of the CAP server or for dependencies the `name` from the `package.json`.
49
103
 
50
- A second option to override this configuration is the usage of the environment variable `CDS_PLUGIN_UI5_MODULES`. It contains the JSON string from the configuration above, e.g.:
104
+ The available configuration options are:
105
+
106
+ * `configFile`: *`string`* - name of the config file (defaults to "ui5.yaml")
107
+ * `workspaceConfigFile`: *`string`* - name of the workspace config file (defaults to "ui5-workspace.yaml")
108
+ * `workspaceName`: *`string`* - name of the workspace (defaults to "default" when the file at workspaceConfigPath exists)
109
+ * `versionOverride`: *`string`* - Framework version to use instead of the one defined in the root project
110
+
111
+ If the `configFile` or `workspaceConfigFile` startes with `./` or `../` then the config file is considered to be relative to the `package.json`.
112
+
113
+ The configuration can also be injected with the environment variable `CDS_PLUGIN_UI5_MODULES`. It contains the JSON string from the configuration above, e.g.:
51
114
 
52
115
  ```sh
53
116
  CDS_PLUGIN_UI5_MODULES="{ \"ui5-bookshop\": { \"configFile\": \"ui5-dist.yaml\" } }" cds-serve
54
117
  ```
55
118
 
119
+ The configuration options from the UI5 server middlewares and the mount path can be mixed together as they both are in the same section of the `package.json`.
120
+
56
121
  ## Info for UI5 Tooling Extension Developers
57
122
 
58
123
  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:
package/cds-plugin.js CHANGED
@@ -49,6 +49,7 @@ cds.on("bootstrap", async function bootstrap(app) {
49
49
  // apply the UI5 middlewares to the router and
50
50
  // retrieve the available HTML pages
51
51
  const appInfo = await applyUI5Middleware(router, {
52
+ cwd,
52
53
  basePath: modulePath,
53
54
  ...(config[moduleId] || {}),
54
55
  });
@@ -12,6 +12,7 @@ const log = require("./log");
12
12
  /**
13
13
  * @typedef applyUI5MiddlewareOptions
14
14
  * @type {object}
15
+ * @property {string} [cwd] cwd to resolve relative config files to, e.g. "./ui5.yaml" or "./ui5-workspace.yaml" (defaults to `process.cwd()`)
15
16
  * @property {string} [basePath] base path of the UI5 application (defaults to `process.cwd()`)
16
17
  * @property {string} [configFile] name of the config file (defaults to "ui5.yaml")
17
18
  * @property {string} [configPath] /!\ RESTRICTED /!\ - path to the ui5.yaml (defaults to "${basePath}/${configFile}")
@@ -30,23 +31,37 @@ const log = require("./log");
30
31
  * @param {applyUI5MiddlewareOptions} options configuration options
31
32
  * @returns {UI5AppInfo} UI5 application information object
32
33
  */
33
- module.exports = async function applyUI5Middleware(router, options = { basePath: process.cwd() }) {
34
+ module.exports = async function applyUI5Middleware(router, options) {
34
35
  const { graphFromPackageDependencies } = await import("@ui5/project/graph");
35
36
  const { createReaderCollection } = await import("@ui5/fs/resourceFactory");
36
37
 
38
+ options.cwd = options.cwd || process.cwd();
39
+ options.basePath = options.basePath || process.cwd();
40
+
37
41
  const configPath = options.configPath || options.basePath;
38
42
  const configFile = options.configFile || "ui5.yaml";
39
43
  const workspaceConfigPath = options.workspaceConfigPath || options.basePath;
40
44
  const workpaceConfigFile = options.workpaceConfigFile || "ui5-workspace.yaml";
41
45
 
42
46
  const determineConfigPath = function (configPath, configFile) {
47
+ // ensure that the config path is absolute
48
+ if (!path.isAbsolute(configPath)) {
49
+ configPath = path.resolve(options.basePath, configPath);
50
+ }
51
+ // if the config path is a file, then we assume that this is the
52
+ // configuration which should be used for the UI5 server middlewares
43
53
  if (fs.existsSync(configPath) && fs.statSync(configPath).isFile()) {
44
54
  return configPath;
45
55
  }
46
- configPath = path.resolve(configPath, configFile);
56
+ // if the configuration file is starting with ./ or ../ then we
57
+ // resolve the configuration relative to the current working dir
58
+ // otherwise we are resolving it relative to the config path
59
+ // which is typically the directory of the UI5 application
60
+ configPath = path.resolve(/^\.\.?\//.test(configFile) ? options.cwd : configPath, configFile);
47
61
  if (fs.existsSync(configPath) && fs.statSync(configPath).isFile()) {
48
62
  return configPath;
49
63
  }
64
+ // nothing matched => no config
50
65
  return undefined;
51
66
  };
52
67
 
@@ -116,22 +116,16 @@ module.exports = async function findUI5Modules({ cwd, skipLocalApps, skipDeps })
116
116
  throw err;
117
117
  }
118
118
 
119
- // by default the mount path is derived from the metadata/name
120
- // and can be overridden by customConfiguration/mountPath
119
+ // extract the configuration
121
120
  const ui5Config = ui5Configs?.[0];
122
121
  const isApplication = ui5Config?.type === "application";
123
122
  if (isApplication) {
124
- let mountPath = ui5Config?.customConfiguration?.mountPath || ui5Config?.metadata?.name;
125
- if (!/^\//.test(mountPath)) {
126
- mountPath = `/${mountPath}`; // always start with /
127
- }
128
-
129
123
  // determine the module path based on the location of the ui5.yaml
130
124
  const modulePath = path.dirname(ui5YamlPath);
131
125
 
132
126
  // manually get the module name as defined in package.json
133
- // skipDeps is only true if we are looking for UI5 apps inside a CAP server project
134
- // in all other cases the module name equals the appDir
127
+ // skipDeps is only true if we are looking for UI5 apps inside a CAP
128
+ // server project in all other cases the module name equals the appDir
135
129
  let moduleName;
136
130
  if (skipDeps) {
137
131
  const packageJsonPath = require.resolve(path.join(appDir, "package.json"), {
@@ -142,6 +136,17 @@ module.exports = async function findUI5Modules({ cwd, skipLocalApps, skipDeps })
142
136
  }
143
137
  const moduleId = moduleName || path.basename(appDir);
144
138
 
139
+ // by default the mount path is derived from the "metadata/name"
140
+ // and can be overridden by "customConfiguration/mountPath" or
141
+ // by "customConfiguration/cds-plugin-ui5/mountPath" or by
142
+ // the following configuration entry in the package.json of CAP
143
+ // server: "cds/cds-plugin-ui5/modules/%moduleId%/mountPath"
144
+ let mountPath =
145
+ modulesConfig?.[moduleId]?.mountPath || ui5Config?.customConfiguration?.["cds-plugin-ui5"]?.mountPath || ui5Config?.customConfiguration?.mountPath || ui5Config?.metadata?.name;
146
+ if (!/^\//.test(mountPath)) {
147
+ mountPath = `/${mountPath}`; // always start with /
148
+ }
149
+
145
150
  // store the custom config in the configuration map
146
151
  if (modulesConfig?.[moduleId]) {
147
152
  apps.config[moduleId] = modulesConfig[moduleId];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cds-plugin-ui5",
3
- "version": "0.6.0",
3
+ "version": "0.6.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",
@@ -24,5 +24,5 @@
24
24
  "@sap/cds": ">=6.8.2",
25
25
  "express": ">=4.18.2"
26
26
  },
27
- "gitHead": "de3226373e571bb9bb9d9e71640815b96858b371"
27
+ "gitHead": "1f8272a1e1faa0559fd9e57b03da2ada256d23df"
28
28
  }