@ui5/task-adaptation 1.0.21 → 1.1.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.
Files changed (35) hide show
  1. package/CHANGELOG.md +12 -1
  2. package/dist/annotationManager.d.ts +3 -4
  3. package/dist/annotationManager.js +20 -56
  4. package/dist/annotations/oDataModel.d.ts +20 -0
  5. package/dist/annotations/oDataModel.js +46 -0
  6. package/dist/annotations/oDataV2Model.d.ts +4 -0
  7. package/dist/annotations/oDataV2Model.js +13 -0
  8. package/dist/annotations/serviceRequestor.d.ts +17 -0
  9. package/dist/annotations/serviceRequestor.js +36 -0
  10. package/dist/appVariantManager.d.ts +0 -7
  11. package/dist/appVariantManager.js +2 -20
  12. package/dist/baseAppManager.d.ts +1 -0
  13. package/dist/baseAppManager.js +22 -5
  14. package/dist/i18nManager.d.ts +11 -10
  15. package/dist/i18nManager.js +19 -19
  16. package/dist/index.js +2 -0
  17. package/dist/model/language.d.ts +13 -0
  18. package/dist/model/language.js +37 -0
  19. package/dist/model/types.d.ts +1 -1
  20. package/dist/processors/abapProcessor.js +2 -2
  21. package/dist/repositories/abapRepoManager.js +2 -1
  22. package/dist/util/cfUtil.js +1 -1
  23. package/dist/util/commonUtil.d.ts +1 -0
  24. package/dist/util/commonUtil.js +13 -1
  25. package/dist/util/jsonDiffUtil.d.ts +14 -3
  26. package/dist/util/jsonDiffUtil.js +29 -9
  27. package/package.json +4 -3
  28. package/scripts/metadataDownloadHelper.ts +85 -0
  29. package/scripts/rollup.ts +0 -9
  30. package/dist/bundle-resourceBundle.js +0 -692
  31. package/scripts/rollup/bundleDefinition-resourceBundle.js +0 -5
  32. package/scripts/rollup/overrides/sap/base/i18n/Localization.js +0 -1
  33. package/scripts/rollup/overrides/sap/base/string/formatMessage.js +0 -1
  34. package/scripts/rollup/overrides/sap/base/util/Properties.js +0 -1
  35. package/scripts/rollup/overrides/sap/base/util/merge.js +0 -1
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const commonUtil_1 = require("../util/commonUtil");
4
+ const language_1 = require("../model/language");
4
5
  class AbapProcessor {
5
6
  constructor(configuration, cacheManager, abapRepoManager, annotationManager) {
6
7
  this.configuration = configuration;
@@ -15,8 +16,7 @@ class AbapProcessor {
15
16
  (0, commonUtil_1.validateObject)(this.configuration, ["destination", "appName"], "should be specified in ui5.yaml configuration");
16
17
  }
17
18
  async updateLandscapeSpecificContent(renamedBaseAppManifest, baseAppFiles) {
18
- const { languages } = this.configuration;
19
- const files = await this.annotationManager.process(renamedBaseAppManifest, ["", ...(languages ?? ["EN"])]);
19
+ const files = await this.annotationManager.process(renamedBaseAppManifest, (language_1.default.create(this.configuration.languages)));
20
20
  if (baseAppFiles) {
21
21
  files.forEach((value, key) => baseAppFiles.set(key, value));
22
22
  }
@@ -23,7 +23,8 @@ class AbapRepoManager {
23
23
  return { changedOn: header.modified };
24
24
  }
25
25
  async downloadAnnotationFile(uri) {
26
- const annotation = await requestUtil_1.default.retryWithAuth(() => requestUtil_1.default.get(uri, REQUEST_OPTIONS_XML), () => requestUtil_1.default.get(uri, REQUEST_OPTIONS_XML, this.getAuth()));
26
+ const annotationUri = `https://${this.configuration.destination}.dest${uri}`;
27
+ const annotation = await requestUtil_1.default.retryWithAuth(() => requestUtil_1.default.get(annotationUri, REQUEST_OPTIONS_XML), () => requestUtil_1.default.get(annotationUri, REQUEST_OPTIONS_XML, this.getAuth()));
27
28
  return new Map([["annotation.xml", annotation]]);
28
29
  }
29
30
  getMetadata(baseAppId) {
@@ -66,7 +66,7 @@ class CFUtil {
66
66
  key: types_1.eFilters.service_instance_guids
67
67
  }]
68
68
  }).catch((error) => {
69
- throw Error("Failed to get service credentials: " + error.message);
69
+ throw new Error("Failed to get service credentials: " + error.message);
70
70
  });
71
71
  }
72
72
  static async createServiceKey(serviceInstanceName, serviceKeyName) {
@@ -3,3 +3,4 @@ export declare function validateObject<T extends Object>(options: T, properties:
3
3
  export declare function escapeRegex(update: string): string;
4
4
  export declare function renameResources(files: Map<string, string>, search: string, replacement: string): Map<string, string>;
5
5
  export declare function removePropertiesExtension(filePath: string): string;
6
+ export declare function logBuilderVersion(): Promise<void>;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.removePropertiesExtension = exports.renameResources = exports.escapeRegex = exports.validateObject = exports.dotToUnderscore = void 0;
3
+ exports.logBuilderVersion = exports.removePropertiesExtension = exports.renameResources = exports.escapeRegex = exports.validateObject = exports.dotToUnderscore = void 0;
4
+ const log = require("@ui5/logger").getLogger("rollup-plugin-ui5-resolve-task-adaptation");
4
5
  function dotToUnderscore(value) {
5
6
  return value.replace(/\./g, "_");
6
7
  }
@@ -60,4 +61,15 @@ function removePropertiesExtension(filePath) {
60
61
  return filePath.substring(0, lastIndexOf);
61
62
  }
62
63
  exports.removePropertiesExtension = removePropertiesExtension;
64
+ async function logBuilderVersion() {
65
+ try {
66
+ // @ts-ignore
67
+ const packageJSON = await Promise.resolve().then(() => require("../../package.json"));
68
+ log.info(`Running app-variant-bundler-build with version ${packageJSON.version}`);
69
+ }
70
+ catch (e) {
71
+ // do nothing
72
+ }
73
+ }
74
+ exports.logBuilderVersion = logBuilderVersion;
63
75
  //# sourceMappingURL=commonUtil.js.map
@@ -1,17 +1,28 @@
1
+ import Language from "../model/language";
1
2
  export interface IJsonContent {
2
- language: string;
3
+ language: Language;
3
4
  json: any;
4
5
  }
5
6
  export interface IDiffProperty {
6
7
  object: any;
7
- property: string;
8
+ property: string | number;
9
+ type: DiffTypeEnum;
10
+ }
11
+ export declare enum DiffTypeEnum {
12
+ MINUS = 0,
13
+ PLUS = 1,
14
+ DELTA = 2
8
15
  }
9
16
  export interface IDiffJson {
10
17
  json: any;
11
18
  properties: Set<IDiffProperty>;
12
19
  }
20
+ export interface IDiffOptions {
21
+ restoreOriginalValue: boolean;
22
+ throwErrorOnDiffStructure: boolean;
23
+ }
13
24
  export default class JsonDiffUtil {
14
- static diff(jsonA: any, jsonB: any): IDiffJson;
25
+ static diff(jsonA: any, jsonB: any, options?: IDiffOptions): IDiffJson;
15
26
  private static findDiffsAndRestoreStructure;
16
27
  private static traverseDiffRecursive;
17
28
  }
@@ -1,22 +1,32 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DiffTypeEnum = void 0;
3
4
  const jsonDiff = require("json-diff");
4
5
  const annotationDiffStructureError_1 = require("../model/annotationDiffStructureError");
6
+ var DiffTypeEnum;
7
+ (function (DiffTypeEnum) {
8
+ DiffTypeEnum[DiffTypeEnum["MINUS"] = 0] = "MINUS";
9
+ DiffTypeEnum[DiffTypeEnum["PLUS"] = 1] = "PLUS";
10
+ DiffTypeEnum[DiffTypeEnum["DELTA"] = 2] = "DELTA";
11
+ })(DiffTypeEnum = exports.DiffTypeEnum || (exports.DiffTypeEnum = {}));
5
12
  class JsonDiffUtil {
6
- static diff(jsonA, jsonB) {
13
+ static diff(jsonA, jsonB, options = {
14
+ throwErrorOnDiffStructure: true,
15
+ restoreOriginalValue: false
16
+ }) {
7
17
  const json = jsonDiff.diff(jsonA, jsonB, { full: true, sort: false });
8
- const properties = this.findDiffsAndRestoreStructure(json);
18
+ const properties = this.findDiffsAndRestoreStructure(json, options);
9
19
  return {
10
20
  json,
11
21
  properties
12
22
  };
13
23
  }
14
- static findDiffsAndRestoreStructure(object) {
24
+ static findDiffsAndRestoreStructure(object, options) {
15
25
  const properties = new Set();
16
- this.traverseDiffRecursive(properties, { object }, "object");
26
+ this.traverseDiffRecursive(properties, { object }, "object", options);
17
27
  return properties;
18
28
  }
19
- static traverseDiffRecursive(properties, object, property) {
29
+ static traverseDiffRecursive(properties, object, property, options) {
20
30
  const current = object[property];
21
31
  if (typeof current !== "object") {
22
32
  return;
@@ -29,10 +39,17 @@ class JsonDiffUtil {
29
39
  // This is a sign from json-diff plugin, that the property contains differences.
30
40
  // We will remove these signs, to restore the original structure
31
41
  if (item[0] === "~") {
32
- this.traverseDiffRecursive(properties, item, 1);
42
+ this.traverseDiffRecursive(properties, item, 1, options);
33
43
  }
34
44
  else if (item[0] === "+" || item[0] === "-") {
35
- throw new annotationDiffStructureError_1.default(item[1]);
45
+ if (options.throwErrorOnDiffStructure) {
46
+ throw new annotationDiffStructureError_1.default(item[1]);
47
+ }
48
+ properties.add({
49
+ object: object[property],
50
+ property: i,
51
+ type: item[0] === "+" ? DiffTypeEnum.PLUS : DiffTypeEnum.MINUS
52
+ });
36
53
  }
37
54
  }
38
55
  }
@@ -40,11 +57,14 @@ class JsonDiffUtil {
40
57
  else {
41
58
  for (const key of Object.keys(current)) {
42
59
  if (key == "__old" || key == "__new") {
43
- properties.add({ object, property });
60
+ if (options.restoreOriginalValue) {
61
+ object[property] = current["__old"];
62
+ }
63
+ properties.add({ object, property, type: DiffTypeEnum.DELTA });
44
64
  break;
45
65
  }
46
66
  else {
47
- this.traverseDiffRecursive(properties, current, key);
67
+ this.traverseDiffRecursive(properties, current, key, options);
48
68
  }
49
69
  }
50
70
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ui5/task-adaptation",
3
- "version": "1.0.21",
3
+ "version": "1.1.0",
4
4
  "description": "Custom task for ui5-builder which allows building UI5 Flexibility Adaptation Projects for SAP BTP, Cloud Foundry environment",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -14,7 +14,8 @@
14
14
  "prepublishOnly": "git push --follow-tags",
15
15
  "release-note": "git-chglog -c .chglog/release-config.yml v$npm_package_version",
16
16
  "rollup": "npx ts-node scripts/rollup.ts",
17
- "build": "npm run rollup && tsc -p ./"
17
+ "build": "npm run rollup && tsc -p ./",
18
+ "download-metadata": "npx ts-node scripts/metadataDownloadHelper.ts"
18
19
  },
19
20
  "repository": {
20
21
  "type": "git",
@@ -40,7 +41,7 @@
40
41
  "@ui5/project": "^2.6.0",
41
42
  "adm-zip": "^0.5.5",
42
43
  "amdextract": "^3.0.0",
43
- "axios": "^1.6.0",
44
+ "axios": "^1.6.2",
44
45
  "builtin-modules": "^3.2.0",
45
46
  "dotenv": "^16.0.3",
46
47
  "js-yaml": "^4.1.0",
@@ -0,0 +1,85 @@
1
+ import * as dotenv from "dotenv";
2
+ import * as fs from "fs/promises";
3
+ import { Agent } from "https";
4
+ import RequestUtil from "../src/util/requestUtil";
5
+
6
+ dotenv.config();
7
+ const httpsAgent = new Agent({ rejectUnauthorized: false });
8
+
9
+ export default class MetadataDownloadHelper {
10
+
11
+ static async readAllUrls() {
12
+ await fs.readdir("./test/resources/annotations/inline", { encoding: "utf8" });
13
+ const resultsObject = JSON.parse(await fs.readFile("./test/resources/allReleasedODataServices.json", { encoding: "utf8" }));
14
+ return this.exractUrlsFromResponse(resultsObject);
15
+ }
16
+
17
+ static async fetchAllUrls(host: string) {
18
+ const REQUEST_OPTIONS_JSON = {
19
+ headers: {
20
+ "Content-Type": "application/json; charset=utf-8",
21
+ 'Cookie': process.env.cookie,
22
+ },
23
+ httpsAgent
24
+ };
25
+ const url = "/sap/bc/ui2/app_index?sap.fiori/cloudDevAdaptationStatus=released&fields=sap.app/id,sap.app/dataSources/OData/uri";
26
+ const response = await RequestUtil.get(host + url, REQUEST_OPTIONS_JSON);
27
+ const allUris = this.exractUrlsFromResponse(response);
28
+ for (const [index, url] of allUris.entries()) {
29
+ try {
30
+ const metadataFile = await this.fetchMetadataFileByUri(host, url);
31
+ if (typeof metadataFile === "object") {
32
+ console.error(`Received object instead of xml file with content: ${JSON.stringify(metadataFile)}`)
33
+ continue;
34
+ }
35
+ // @ts-ignore
36
+ await fs.writeFile(`test/resources/metadata/download/${index}__${url.replaceAll("/", "_")}.xml`, metadataFile, { encoding: "utf8" });
37
+ } catch (e: any) {
38
+ console.error(`Error fetching metadata file with url ${url} with error \n\n ${e}`);
39
+ continue;
40
+ }
41
+ }
42
+ }
43
+
44
+ private static exractUrlsFromResponse(resultsObject: any) {
45
+ let allUrls: string[] = [];
46
+ resultsObject.results.map((value: any) => {
47
+ allUrls = allUrls.concat(value["sap.app/dataSources/OData/uri"]);
48
+ });
49
+ return allUrls;
50
+ }
51
+
52
+ static readMetadataFileByFilePath(filePath: string) {
53
+ return fs.readFile(filePath, { encoding: "utf8" });
54
+ }
55
+
56
+ static fetchMetadataFileByUri(host: string, uri: string) {
57
+ const REQUEST_OPTIONS_XML = {
58
+ headers: {
59
+ "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
60
+ 'Cookie': process.env.cookie,
61
+ },
62
+ httpsAgent
63
+ };
64
+ uri = uri.endsWith("/") ? `${uri}$metadata` : `${uri}/$metadata`;
65
+ return RequestUtil.get(host + uri, REQUEST_OPTIONS_XML);
66
+ }
67
+ }
68
+
69
+ // Get the command line arguments
70
+ const args = process.argv;
71
+
72
+ // Find the index of the `--host=` argument
73
+ const hostArgIndex = args.findIndex(arg => arg.startsWith('--host='));
74
+
75
+ // If the `--host=` argument is found
76
+ if (hostArgIndex !== -1) {
77
+ // Extract the value of the `--host=` argument
78
+ const hostArg = args[hostArgIndex];
79
+ const host = hostArg.split('=')[1];
80
+
81
+ // Use the `host` variable as needed
82
+ MetadataDownloadHelper.fetchAllUrls(host);
83
+ } else {
84
+ console.info("Please provide missing host parameter");
85
+ }
package/scripts/rollup.ts CHANGED
@@ -73,15 +73,6 @@ export default class Builder {
73
73
  [
74
74
  "sap/ui/thirdparty/URI"
75
75
  ]);
76
- await Bundler.run(
77
- project,
78
- "bundleDefinition-resourceBundle.js",
79
- "./dist/bundle-resourceBundle.js",
80
- "/sap.ui.core",
81
- [
82
- "/resources/sap/base/**"
83
- ]
84
- );
85
76
  }
86
77
  }
87
78