@sap-ux/fe-fpm-writer 0.18.2 → 0.18.3

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.
@@ -62,7 +62,7 @@ export interface ViewVariant {
62
62
  /**
63
63
  * The annotationPath of a specific variant.
64
64
  */
65
- annotationPath: string;
65
+ annotationPath?: string;
66
66
  /**
67
67
  * View title, is shown in the tab item.
68
68
  */
@@ -9,6 +9,38 @@ const validate_1 = require("../common/validate");
9
9
  const defaults_1 = require("../common/defaults");
10
10
  const event_handler_1 = require("../common/event-handler");
11
11
  const templates_1 = require("../templates");
12
+ /**
13
+ * Merge the new view into the list of existing views (if any).
14
+ *
15
+ * @param {CustomView & Partial<InternalCustomView>} config - config for the template, views property gets updated
16
+ * @param {Manifest} manifest - the application manifest
17
+ */
18
+ function mergeViews(config, manifest) {
19
+ var _a, _b, _c, _d, _e;
20
+ const newViews = {
21
+ paths: [
22
+ {
23
+ 'key': config.key,
24
+ 'label': config.label,
25
+ 'template': `${config.ns}.${config.name}`
26
+ }
27
+ ]
28
+ };
29
+ const existingViews = (_e = (_d = ((_c = (_b = (_a = manifest['sap.ui5']) === null || _a === void 0 ? void 0 : _a.routing) === null || _b === void 0 ? void 0 : _b.targets) === null || _c === void 0 ? void 0 : _c[config.target]).options) === null || _d === void 0 ? void 0 : _d.settings) === null || _e === void 0 ? void 0 : _e.views;
30
+ if (existingViews === null || existingViews === void 0 ? void 0 : existingViews.paths) {
31
+ const index = existingViews.paths.findIndex((entry) => entry.key === newViews.paths[0].key);
32
+ if (index > -1) {
33
+ existingViews.paths[index] = newViews.paths[0];
34
+ }
35
+ else {
36
+ existingViews.paths.push(newViews.paths[0]);
37
+ }
38
+ config.views = existingViews;
39
+ }
40
+ else {
41
+ config.views = newViews;
42
+ }
43
+ }
12
44
  /**
13
45
  * Enhances the provided custom view configuration with default data.
14
46
  *
@@ -19,19 +51,14 @@ const templates_1 = require("../templates");
19
51
  * @returns enhanced configuration
20
52
  */
21
53
  function enhanceConfig(fs, data, manifestPath, manifest) {
22
- var _a, _b, _c, _d, _e;
23
54
  const config = Object.assign({}, data);
24
55
  defaults_1.setCommonDefaults(config, manifestPath, manifest);
25
- // Apply event handler
56
+ // apply event handler
26
57
  if (config.eventHandler) {
27
58
  config.eventHandler = event_handler_1.applyEventHandlerConfiguration(fs, config, config.eventHandler, true, config.typescript);
28
59
  }
29
- // existing views
30
- const existingViews = (_e = (_d = ((_c = (_b = (_a = manifest['sap.ui5']) === null || _a === void 0 ? void 0 : _a.routing) === null || _b === void 0 ? void 0 : _b.targets) === null || _c === void 0 ? void 0 : _c[data.target])
31
- .options) === null || _d === void 0 ? void 0 : _d.settings) === null || _e === void 0 ? void 0 : _e.views;
32
- if (existingViews) {
33
- config.views = existingViews;
34
- }
60
+ // fill config.views, merge new data into existing views
61
+ mergeViews(config, manifest);
35
62
  // generate view content
36
63
  if (typeof config.control === 'string') {
37
64
  config.content = config.control;
@@ -63,12 +90,14 @@ function generateCustomView(basePath, customView, fs) {
63
90
  const filledTemplate = ejs_1.render(fs.read(templates_1.getTemplatePath('view/manifest.json')), completeView, {});
64
91
  fs.extendJSON(manifestPath, JSON.parse(filledTemplate));
65
92
  // add fragment
66
- const viewPath = path_1.join(completeView.path, `${completeView.name}.fragment.xml`);
67
- if (completeView.control === true) {
68
- fs.copyTpl(templates_1.getTemplatePath('view/ext/CustomViewWithTable.xml'), viewPath, completeView);
69
- }
70
- else if (!fs.exists(viewPath)) {
71
- fs.copyTpl(templates_1.getTemplatePath('common/Fragment.xml'), viewPath, completeView);
93
+ if (customView.viewUpdate !== false) {
94
+ const viewPath = path_1.join(completeView.path, `${completeView.name}.fragment.xml`);
95
+ if (completeView.control === true) {
96
+ fs.copyTpl(templates_1.getTemplatePath('view/ext/CustomViewWithTable.xml'), viewPath, completeView);
97
+ }
98
+ else if (!fs.exists(viewPath)) {
99
+ fs.copyTpl(templates_1.getTemplatePath('common/Fragment.xml'), viewPath, completeView);
100
+ }
72
101
  }
73
102
  return fs;
74
103
  }
@@ -17,6 +17,10 @@ export interface CustomView extends CustomElement, EventHandler {
17
17
  * If set to true, a table macro control will be generated.
18
18
  */
19
19
  control?: string | true;
20
+ /**
21
+ * Indicates that the view shall be created or updated
22
+ */
23
+ viewUpdate?: boolean;
20
24
  }
21
25
  export interface InternalCustomView extends CustomView, InternalCustomElement {
22
26
  content: string;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sap-ux/fe-fpm-writer",
3
3
  "description": "SAP Fiori elements flexible programming model writer",
4
- "version": "0.18.2",
4
+ "version": "0.18.3",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/SAP/open-ux-tools.git",
@@ -20,17 +20,16 @@
20
20
  "views": {
21
21
  "paths": [
22
22
  <% if (locals.views?.paths) { %>
23
- <% locals.views.paths.forEach ( (path) => { %>
24
- <%- JSON.stringify(path) %>,
23
+ <% for (var i =0; i < locals.views.paths.length; i++) { %>
24
+ <%- JSON.stringify(locals.views.paths[i]) %>
25
+ <% if (i < locals.views.paths.length - 1) { %>
26
+ ,
27
+ <%
28
+ } %>
25
29
  <%
26
- } ) %>
30
+ } %>
27
31
  <%
28
32
  } %>
29
- {
30
- "key": "<%- key %>",
31
- "label": "<%- label %>",
32
- "template": "<%- ns %>.<%- name %>"
33
- }
34
33
  ]
35
34
  }
36
35
  }