@sap-ux/ui5-application-writer 0.17.4 → 0.17.5

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.
@@ -8,15 +8,14 @@ import type { App, Package, UI5 } from '../types';
8
8
  */
9
9
  export declare function packageDefaults(version?: string, description?: string): Partial<Package>;
10
10
  /**
11
- * Merges 2 package definitions. All properties from A and from B will be present.
12
- * Overlapping properties will be replaced from B. Arrays will be concatenated.
13
- * `ui5.dependencies` will be de-duped.
11
+ * Merges two objects. All properties from base and from extension will be present.
12
+ * Overlapping properties will be used from extension. Arrays will be concatenated and de-duped.
14
13
  *
15
- * @param packageA - a partial package definition
16
- * @param packageB - a partial package definition
14
+ * @param base - any object definition
15
+ * @param extension - another object definition
17
16
  * @returns - a merged package defintion
18
17
  */
19
- export declare function mergePackages(packageA: Partial<Package>, packageB: Partial<Package>): Package;
18
+ export declare function mergeObjects<B, E>(base: B, extension: E): B & E;
20
19
  export declare const enum UI5_DEFAULT {
21
20
  DEFAULT_UI5_VERSION = "",
22
21
  DEFAULT_LOCAL_UI5_VERSION = "1.95.0",
@@ -3,12 +3,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getSpecTagVersion = exports.getTypesVersion = exports.mergeUi5 = exports.defaultUI5Libs = exports.mergeApp = exports.mergePackages = exports.packageDefaults = void 0;
6
+ exports.getSpecTagVersion = exports.getTypesVersion = exports.mergeUi5 = exports.defaultUI5Libs = exports.mergeApp = exports.mergeObjects = exports.packageDefaults = void 0;
7
7
  const version_to_descriptor_mapping_json_1 = __importDefault(require("./version-to-descriptor-mapping.json")); // from https://github.com/SAP/ui5-manifest/blob/master/mapping.json
8
8
  const ui5Libs_1 = require("./ui5Libs");
9
9
  const semver_1 = __importDefault(require("semver"));
10
10
  const i18n_1 = require("../i18n");
11
- const json_merger_1 = require("json-merger");
11
+ const mergeWith_1 = __importDefault(require("lodash/mergeWith"));
12
12
  /**
13
13
  * Returns a package instance with default properties.
14
14
  *
@@ -36,26 +36,25 @@ function packageDefaults(version, description) {
36
36
  }
37
37
  exports.packageDefaults = packageDefaults;
38
38
  /**
39
- * Merges 2 package definitions. All properties from A and from B will be present.
40
- * Overlapping properties will be replaced from B. Arrays will be concatenated.
41
- * `ui5.dependencies` will be de-duped.
39
+ * Merges two objects. All properties from base and from extension will be present.
40
+ * Overlapping properties will be used from extension. Arrays will be concatenated and de-duped.
42
41
  *
43
- * @param packageA - a partial package definition
44
- * @param packageB - a partial package definition
42
+ * @param base - any object definition
43
+ * @param extension - another object definition
45
44
  * @returns - a merged package defintion
46
45
  */
47
- function mergePackages(packageA, packageB) {
48
- var _a;
49
- const mergedPackage = json_merger_1.mergeObjects([packageA, packageB], {
50
- defaultArrayMergeOperation: 'concat'
46
+ function mergeObjects(base, extension) {
47
+ return mergeWith_1.default({}, base, extension, (objValue, srcValue) => {
48
+ // merge and de-dup arrays
49
+ if (objValue instanceof Array && srcValue instanceof Array) {
50
+ return [...new Set([...objValue, ...srcValue])];
51
+ }
52
+ else {
53
+ return undefined;
54
+ }
51
55
  });
52
- // de-dup package.ui5.dependencies
53
- if ((_a = mergedPackage.ui5) === null || _a === void 0 ? void 0 : _a.dependencies) {
54
- mergedPackage.ui5.dependencies = Array.from(new Set(mergedPackage.ui5.dependencies));
55
- }
56
- return mergedPackage;
57
56
  }
58
- exports.mergePackages = mergePackages;
57
+ exports.mergeObjects = mergeObjects;
59
58
  /**
60
59
  * Returns an app instance merged with default properties.
61
60
  *
@@ -64,20 +63,17 @@ exports.mergePackages = mergePackages;
64
63
  */
65
64
  function mergeApp(app) {
66
65
  var _a, _b, _c, _d, _e;
67
- return json_merger_1.mergeObjects([
68
- {
69
- version: '0.0.1',
70
- title: i18n_1.t('text.defaultAppTitle', { id: app.id }),
71
- description: i18n_1.t('text.defaultAppDescription', { id: app.id }),
72
- baseComponent: "sap/ui/core/UIComponent" /* BASE_COMPONENT */,
73
- sourceTemplate: {
74
- id: (_b = (_a = app.sourceTemplate) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : '',
75
- version: (_d = (_c = app.sourceTemplate) === null || _c === void 0 ? void 0 : _c.version) !== null && _d !== void 0 ? _d : '',
76
- toolsId: (_e = app.sourceTemplate) === null || _e === void 0 ? void 0 : _e.toolsId
77
- }
78
- },
79
- app
80
- ]);
66
+ return mergeWith_1.default({
67
+ version: '0.0.1',
68
+ title: i18n_1.t('text.defaultAppTitle', { id: app.id }),
69
+ description: i18n_1.t('text.defaultAppDescription', { id: app.id }),
70
+ baseComponent: "sap/ui/core/UIComponent" /* BASE_COMPONENT */,
71
+ sourceTemplate: {
72
+ id: (_b = (_a = app.sourceTemplate) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : '',
73
+ version: (_d = (_c = app.sourceTemplate) === null || _c === void 0 ? void 0 : _c.version) !== null && _d !== void 0 ? _d : '',
74
+ toolsId: (_e = app.sourceTemplate) === null || _e === void 0 ? void 0 : _e.toolsId
75
+ }
76
+ }, app);
81
77
  }
82
78
  exports.mergeApp = mergeApp;
83
79
  // Required default libs
@@ -15,7 +15,7 @@ function mergeWithDefaults(ui5App) {
15
15
  ui5App.app = defaults_1.mergeApp(ui5App.app);
16
16
  ui5App.appOptions = ui5App.appOptions || {};
17
17
  ui5App.ui5 = defaults_1.mergeUi5(ui5App.ui5 || {});
18
- ui5App.package = defaults_1.mergePackages(defaults_1.packageDefaults(ui5App.package.version, ui5App.app.description), ui5App.package);
18
+ ui5App.package = defaults_1.mergeObjects(defaults_1.packageDefaults(ui5App.package.version, ui5App.app.description), ui5App.package);
19
19
  if (ui5App.appOptions.sapux) {
20
20
  ui5App.package.devDependencies = ui5App.package.devDependencies || {};
21
21
  ui5App.package.devDependencies['@sap/ux-specification'] = defaults_1.getSpecTagVersion(ui5App.ui5.version);
package/dist/options.js CHANGED
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.applyOptionalFeatures = exports.enableNpmPackageConsumption = exports.enableTypescript = void 0;
4
4
  const path_1 = require("path");
5
5
  const ejs_1 = require("ejs");
6
- const json_merger_1 = require("json-merger");
7
6
  const files_1 = require("./files");
8
7
  const ui5Libs_1 = require("./data/ui5Libs");
8
+ const defaults_1 = require("./data/defaults");
9
9
  /**
10
10
  * Copy all template files into the target project.
11
11
  *
@@ -23,16 +23,16 @@ function copyTemplates(name, { ui5App, fs, basePath, tmplPath }) {
23
23
  const relPath = optTmplFilePath.replace(optTmplDirPath, '');
24
24
  const outPath = path_1.join(basePath, relPath);
25
25
  // Extend or add
26
- if (!(fs === null || fs === void 0 ? void 0 : fs.exists(outPath))) {
27
- fs === null || fs === void 0 ? void 0 : fs.copyTpl(optTmplFilePath, outPath, ui5App, undefined, {
26
+ if (!fs.exists(outPath)) {
27
+ fs.copyTpl(optTmplFilePath, outPath, ui5App, undefined, {
28
28
  globOptions: { dot: true }
29
29
  });
30
30
  }
31
31
  else {
32
- const add = JSON.parse(ejs_1.render(fs === null || fs === void 0 ? void 0 : fs.read(optTmplFilePath), ui5App, {}));
33
- const existingFile = JSON.parse(fs === null || fs === void 0 ? void 0 : fs.read(outPath));
34
- const merged = json_merger_1.mergeObjects([existingFile, add], { defaultArrayMergeOperation: 'concat' });
35
- fs === null || fs === void 0 ? void 0 : fs.writeJSON(outPath, merged);
32
+ const add = JSON.parse(ejs_1.render(fs.read(optTmplFilePath), ui5App, {}));
33
+ const existingFile = JSON.parse(fs.read(outPath));
34
+ const merged = defaults_1.mergeObjects(existingFile, add);
35
+ fs.writeJSON(outPath, merged);
36
36
  }
37
37
  });
38
38
  }
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "bugs": {
10
10
  "url": "https://github.com/SAP/open-ux-tools/issues?q=is%3Aopen+is%3Aissue+label%3Abug+label%3Aui5-application-writer"
11
11
  },
12
- "version": "0.17.4",
12
+ "version": "0.17.5",
13
13
  "license": "Apache-2.0",
14
14
  "main": "dist/index.js",
15
15
  "files": [
@@ -22,16 +22,17 @@
22
22
  "dependencies": {
23
23
  "@sap-ux/ui5-config": "0.15.1",
24
24
  "ejs": "3.1.7",
25
+ "i18next": "21.6.11",
26
+ "lodash": "4.17.21",
25
27
  "mem-fs": "2.1.0",
26
28
  "mem-fs-editor": "9.4.0",
27
- "json-merger": "1.1.7",
28
- "semver": "7.3.5",
29
- "i18next": "21.6.11"
29
+ "semver": "7.3.5"
30
30
  },
31
31
  "devDependencies": {
32
32
  "@types/ejs": "3.1.0",
33
- "@types/mem-fs": "1.1.2",
34
33
  "@types/fs-extra": "9.0.13",
34
+ "@types/lodash": "4.14.176",
35
+ "@types/mem-fs": "1.1.2",
35
36
  "@types/mem-fs-editor": "7.0.1",
36
37
  "@types/semver": "7.3.9",
37
38
  "fs-extra": "10.0.0"