cds-plugin-ui5 0.8.2 → 0.9.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.9.0](https://github.com/ui5-community/ui5-ecosystem-showcase/compare/cds-plugin-ui5@0.8.3...cds-plugin-ui5@0.9.0) (2024-05-13)
7
+
8
+
9
+ ### Features
10
+
11
+ * **cds-plugin-ui5:** sanitizing package.json with cds build task for gen/srv ([#999](https://github.com/ui5-community/ui5-ecosystem-showcase/issues/999)) ([d52386c](https://github.com/ui5-community/ui5-ecosystem-showcase/commit/d52386c168c62ea4c827cfff65be78117e13fd12))
12
+
13
+
14
+
15
+
16
+
17
+ ## [0.8.3](https://github.com/ui5-community/ui5-ecosystem-showcase/compare/cds-plugin-ui5@0.8.2...cds-plugin-ui5@0.8.3) (2024-03-30)
18
+
19
+
20
+ ### Bug Fixes
21
+
22
+ * cleanup of dependencies and improved approuter logic ([#984](https://github.com/ui5-community/ui5-ecosystem-showcase/issues/984)) ([65ffaed](https://github.com/ui5-community/ui5-ecosystem-showcase/commit/65ffaedb7968015e008e2eb6aa66ff1e0a03a73a))
23
+
24
+
25
+
26
+
27
+
6
28
  ## [0.8.2](https://github.com/ui5-community/ui5-ecosystem-showcase/compare/cds-plugin-ui5@0.8.1...cds-plugin-ui5@0.8.2) (2024-03-04)
7
29
 
8
30
 
package/cds-plugin.js CHANGED
@@ -190,4 +190,75 @@ if (!skip) {
190
190
  // bootstrap completed, unlock the "served" event
191
191
  bootstrapped();
192
192
  });
193
+
194
+ // check if the register function for build tasks is available at the cds object
195
+ // and if the Plugin class is available to register the cds build task
196
+ if (typeof cds.build?.register === "function" && typeof cds.build?.Plugin?.constructor === "function") {
197
+ const { readFile, writeFile } = require("fs").promises;
198
+ const { existsSync } = require("fs");
199
+ const { join } = require("path");
200
+ const { minVersion } = require("semver");
201
+ const util = require("util");
202
+ const exec = util.promisify(require("child_process").exec);
203
+
204
+ // helper to check whether a semantic version is valid
205
+ const valid = (version) => {
206
+ try {
207
+ return minVersion(version) !== null;
208
+ } catch (e) {
209
+ return false;
210
+ }
211
+ };
212
+
213
+ // register the cds build task to sanitize the package.json and update the package-lock.json
214
+ cds.build.register(
215
+ "ui5",
216
+ class UI5Plugin extends cds.build.Plugin {
217
+ static taskDefaults = { src: cds.env.folders.srv };
218
+ static hasTask() {
219
+ return true;
220
+ }
221
+ init() {}
222
+ clean() {
223
+ this._priority = -1; // hack to ensure that the clean task is executed last!
224
+ }
225
+ get priority() {
226
+ return this._priority || 1;
227
+ }
228
+ async build() {
229
+ //const model = await this.model();
230
+ //if (!model) return;
231
+ log.info("Sanitizing the package.json...");
232
+ const packageJson = JSON.parse(await readFile(join(this.task.dest, "package.json"), "utf-8"));
233
+ let modified = false;
234
+ if (packageJson.workspaces) {
235
+ delete packageJson.workspaces;
236
+ modified = true;
237
+ }
238
+ if (packageJson.devDependencies) {
239
+ packageJson.devDependencies = Object.entries(packageJson.devDependencies).reduce((acc, [dep, version]) => {
240
+ if (valid(version) && dep !== "cds-plugin-ui5") {
241
+ acc[dep] = version;
242
+ }
243
+ return acc;
244
+ }, {});
245
+ modified = true;
246
+ }
247
+ if (modified) {
248
+ await writeFile(join(this.task.dest, "package.json"), JSON.stringify(packageJson, null, 2), "utf-8");
249
+ }
250
+ if (existsSync(join(this.task.dest, "package-lock.json"))) {
251
+ log.info("Updating the package-lock.json...");
252
+ try {
253
+ /* const { stdout, stderr } = */ await exec("npm install --package-lock-only", { cwd: this.task.dest });
254
+ } catch (e) {
255
+ //console.error(e.code);
256
+ }
257
+ }
258
+ }
259
+ }
260
+ );
261
+ } else {
262
+ log.info("The cds build task requires @sap/cds-dk version >= 7.6.0! Skipping execution as your @sap/cds-dk version is too old...");
263
+ }
193
264
  }
@@ -53,7 +53,7 @@ module.exports = async function findUI5Modules({ cwd, cds, skipLocalApps, skipDe
53
53
  const localApps = new Set();
54
54
  const appDirs = [];
55
55
  if (!skipLocalApps) {
56
- const appDir = path.join(cwd, cds.env?.folders?.app || "app");
56
+ const appDir = path.join(cwd, cds?.env?.folders?.app || "app");
57
57
  if (fs.existsSync(appDir)) {
58
58
  // is the UI5 app directly in the app directory?
59
59
  if (!fs.existsSync(path.join(appDir, determineUI5Yaml(appDir)))) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cds-plugin-ui5",
3
- "version": "0.8.2",
3
+ "version": "0.9.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",
@@ -15,7 +15,8 @@
15
15
  "@ui5/project": "^3.9.0",
16
16
  "@ui5/server": "^3.1.5",
17
17
  "js-yaml": "^4.1.0",
18
- "node-html-parser": "^6.1.12"
18
+ "node-html-parser": "^6.1.12",
19
+ "semver": "^7.3.5"
19
20
  },
20
21
  "devDependencies": {
21
22
  "@sap/cds": "^6.8.4",
@@ -25,5 +26,5 @@
25
26
  "@sap/cds": ">=6.8.2",
26
27
  "express": ">=4.18.2"
27
28
  },
28
- "gitHead": "95156c55194afaf62f32e2caef743a4e3f71702c"
29
+ "gitHead": "7a1592cd7493d75c6e33a015ac8f3ec141383e44"
29
30
  }