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

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.
@@ -10,6 +10,7 @@ const validate_1 = require("../common/validate");
10
10
  const defaults_1 = require("../common/defaults");
11
11
  const event_handler_1 = require("../common/event-handler");
12
12
  const templates_1 = require("../templates");
13
+ const file_1 = require("../common/file");
13
14
  /**
14
15
  * Enhances the provided custom action configuration with default data.
15
16
  *
@@ -82,7 +83,7 @@ function generateCustomAction(basePath, actionConfig, fs) {
82
83
  // enhance manifest with action definition and controller reference
83
84
  const actions = enhanceManifestAndGetActionsElementReference(manifest, config.target);
84
85
  Object.assign(actions, JSON.parse(ejs_1.render(fs.read(templates_1.getTemplatePath(`action/manifest.action.json`)), config, {})));
85
- fs.writeJSON(manifestPath, manifest);
86
+ fs.writeJSON(manifestPath, manifest, undefined, file_1.getJsonSpace(fs, manifestPath, actionConfig.tabInfo));
86
87
  return fs;
87
88
  }
88
89
  exports.generateCustomAction = generateCustomAction;
@@ -8,6 +8,7 @@ const path_1 = require("path");
8
8
  const defaults_1 = require("../common/defaults");
9
9
  const validate_1 = require("../common/validate");
10
10
  const event_handler_1 = require("../common/event-handler");
11
+ const file_1 = require("../common/file");
11
12
  const templates_1 = require("../templates");
12
13
  const semver_1 = require("semver");
13
14
  /**
@@ -74,7 +75,11 @@ function generateCustomColumn(basePath, customColumn, fs) {
74
75
  // enhance manifest with column definition
75
76
  const manifestRoot = getManifestRoot(customColumn.minUI5Version);
76
77
  const filledTemplate = ejs_1.render(fs.read(path_1.join(manifestRoot, `manifest.json`)), completeColumn, {});
77
- fs.extendJSON(manifestPath, JSON.parse(filledTemplate));
78
+ file_1.extendJSON(fs, {
79
+ filepath: manifestPath,
80
+ content: filledTemplate,
81
+ tabInfo: customColumn.tabInfo
82
+ });
78
83
  // add fragment
79
84
  const viewPath = path_1.join(completeColumn.path, `${completeColumn.name}.fragment.xml`);
80
85
  if (completeColumn.control || !fs.exists(viewPath)) {
@@ -0,0 +1,36 @@
1
+ import type { Editor } from 'mem-fs-editor';
2
+ import type { TabInfo } from '../common/types';
3
+ declare type WriteJsonReplacer = ((key: string, value: any) => any) | Array<string | number>;
4
+ declare type WriteJsonSpace = number | string;
5
+ interface ExtendJsonParams {
6
+ filepath: string;
7
+ content: string;
8
+ replacer?: WriteJsonReplacer;
9
+ tabInfo?: TabInfo;
10
+ }
11
+ /**
12
+ * Method calculates tab space info for passed file content.
13
+ *
14
+ * @param content - file content.
15
+ * @returns tab size information.
16
+ */
17
+ export declare function detectTabSpacing(content: string): TabInfo | undefined;
18
+ /**
19
+ * Method calculates tab spacing parameter for 'JSON.stringify' method.
20
+ *
21
+ * @param fs - the mem-fs editor instance.
22
+ * @param filePath - path to file to read.
23
+ * @param tabInfo - External tab configuration.
24
+ * @returns tab size information.
25
+ */
26
+ export declare function getJsonSpace(fs: Editor, filePath: string, tabInfo?: TabInfo | undefined): WriteJsonSpace | undefined;
27
+ /**
28
+ * Method extends target JSON file with passed JSOn content.
29
+ * Method uses 'fs.extendJSON', but applies additional calculation to reuse existing content tab sizing information.
30
+ *
31
+ * @param fs - the mem-fs editor instance.
32
+ * @param params - options for JSON extend.
33
+ */
34
+ export declare function extendJSON(fs: Editor, params: ExtendJsonParams): void;
35
+ export {};
36
+ //# sourceMappingURL=file.d.ts.map
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.extendJSON = exports.getJsonSpace = exports.detectTabSpacing = void 0;
4
+ const CHAR_SPACE = ' ';
5
+ const CHAR_TAB = '\t';
6
+ /**
7
+ * Method returns tab info for passed line.
8
+ *
9
+ * @param line - line with tab spacing
10
+ * @returns tab size information
11
+ */
12
+ function getLineTabInfo(line) {
13
+ let tabSize;
14
+ const symbol = line[0] === CHAR_TAB ? CHAR_TAB : CHAR_SPACE;
15
+ // get count of tabs
16
+ for (let i = 0; i < line.length; i++) {
17
+ const char = line[i];
18
+ if (char !== symbol) {
19
+ tabSize = {
20
+ size: i,
21
+ useTabSymbol: symbol === CHAR_TAB
22
+ };
23
+ break;
24
+ }
25
+ }
26
+ return tabSize;
27
+ }
28
+ /**
29
+ * Method calculates tab space info for passed file content.
30
+ *
31
+ * @param content - file content.
32
+ * @returns tab size information.
33
+ */
34
+ function detectTabSpacing(content) {
35
+ let tabSize;
36
+ const tabSymbols = [CHAR_SPACE, CHAR_TAB];
37
+ const lines = content.split(/\r\n|\n/);
38
+ const lineWithSpacing = lines.find((line) => {
39
+ return tabSymbols.includes(line[0]);
40
+ });
41
+ if (lineWithSpacing) {
42
+ tabSize = getLineTabInfo(lineWithSpacing);
43
+ }
44
+ return tabSize;
45
+ }
46
+ exports.detectTabSpacing = detectTabSpacing;
47
+ /**
48
+ * Method calculates tab spacing parameter for 'JSON.stringify' method.
49
+ *
50
+ * @param fs - the mem-fs editor instance.
51
+ * @param filePath - path to file to read.
52
+ * @param tabInfo - External tab configuration.
53
+ * @returns tab size information.
54
+ */
55
+ function getJsonSpace(fs, filePath, tabInfo) {
56
+ if (!tabInfo) {
57
+ // 'tabInfo' was not passed - calculate 'tabInfo' by checking existing content of target file
58
+ const content = fs.read(filePath);
59
+ tabInfo = detectTabSpacing(content);
60
+ }
61
+ let space;
62
+ if (tabInfo) {
63
+ // 'tabInfo' exists - it was passed as custom configuration or calculated from target file
64
+ if (tabInfo.useTabSymbol) {
65
+ // Tab symbol should be used as tab
66
+ space = CHAR_TAB.repeat(tabInfo.size || 1);
67
+ }
68
+ else {
69
+ // Spaces should be used as tab
70
+ space = tabInfo.size;
71
+ }
72
+ }
73
+ return space;
74
+ }
75
+ exports.getJsonSpace = getJsonSpace;
76
+ /**
77
+ * Method extends target JSON file with passed JSOn content.
78
+ * Method uses 'fs.extendJSON', but applies additional calculation to reuse existing content tab sizing information.
79
+ *
80
+ * @param fs - the mem-fs editor instance.
81
+ * @param params - options for JSON extend.
82
+ */
83
+ function extendJSON(fs, params) {
84
+ const { filepath, content, replacer } = params;
85
+ const space = getJsonSpace(fs, filepath, params.tabInfo);
86
+ // Write json
87
+ fs.extendJSON(filepath, JSON.parse(content), replacer, space);
88
+ }
89
+ exports.extendJSON = extendJSON;
90
+ //# sourceMappingURL=file.js.map
@@ -2,10 +2,14 @@ import type { ManifestNamespace } from '@sap-ux/project-access';
2
2
  export declare type Manifest = ManifestNamespace.SAPJSONSchemaForWebApplicationManifestFile & {
3
3
  [key: string]: unknown;
4
4
  };
5
+ export interface TabInfo {
6
+ size?: number;
7
+ useTabSymbol?: boolean;
8
+ }
5
9
  /**
6
10
  * Common properties for any custom element of the flexible programming model.
7
11
  */
8
- export interface CustomElement {
12
+ export interface CustomElement extends WriterConfig {
9
13
  /**
10
14
  * Name of the custom element that is to be added to the application.
11
15
  */
@@ -62,7 +66,7 @@ export interface ViewVariant {
62
66
  /**
63
67
  * The annotationPath of a specific variant.
64
68
  */
65
- annotationPath: string;
69
+ annotationPath?: string;
66
70
  /**
67
71
  * View title, is shown in the tab item.
68
72
  */
@@ -149,4 +153,11 @@ export interface EventHandler {
149
153
  */
150
154
  eventHandler?: true | string | EventHandlerConfiguration;
151
155
  }
156
+ export interface WriterConfig {
157
+ /**
158
+ * Tab size info.
159
+ * Currently is used only for 'manifest.json' update.
160
+ */
161
+ tabInfo?: TabInfo;
162
+ }
152
163
  //# sourceMappingURL=types.d.ts.map
@@ -10,6 +10,7 @@ const validate_1 = require("../common/validate");
10
10
  const defaults_1 = require("../common/defaults");
11
11
  const templates_1 = require("../templates");
12
12
  const utils_1 = require("../common/utils");
13
+ const file_1 = require("../common/file");
13
14
  exports.UI5_CONTROLLER_EXTENSION_LIST_REPORT = 'sap.fe.templates.ListReport.ListReportController';
14
15
  exports.UI5_CONTROLLER_EXTENSION_OBJECT_PAGE = 'sap.fe.templates.ObjectPage.ObjectPageController';
15
16
  const UI5_CONTROLLER_EXTENSIONS = 'sap.ui.controllerExtensions';
@@ -183,7 +184,12 @@ function generateControllerExtension(basePath, controllerConfig, fs) {
183
184
  const internalConfig = enhanceConfig(controllerConfig, manifestPath, manifest);
184
185
  // enhance manifest with view definition
185
186
  const filledTemplate = ejs_1.render(fs.read(templates_1.getTemplatePath('controller-extension/manifest.json')), internalConfig, {});
186
- fs.extendJSON(manifestPath, JSON.parse(filledTemplate), getManifestReplacer(internalConfig));
187
+ file_1.extendJSON(fs, {
188
+ filepath: manifestPath,
189
+ content: filledTemplate,
190
+ replacer: getManifestReplacer(internalConfig),
191
+ tabInfo: controllerConfig.tabInfo
192
+ });
187
193
  // add controller js file
188
194
  const ext = controllerConfig.typescript ? 'ts' : 'js';
189
195
  const viewPath = path_1.join(internalConfig.path, `${internalConfig.name}.controller.${ext}`);
@@ -1,7 +1,8 @@
1
1
  import type { Editor } from 'mem-fs-editor';
2
2
  import type { ManifestNamespace } from '@sap-ux/project-access';
3
- import type { CustomPage, FCL, InternalCustomPage, InternalObjectPage, ObjectPage, Navigation, InternalListReport } from './types';
3
+ import type { CustomPage, FCL, InternalCustomPage, InternalObjectPage, ObjectPage, ListReport, Navigation, InternalListReport } from './types';
4
4
  import type { Manifest } from '../common/types';
5
+ declare type EnhancePageConfigFunction = (data: ObjectPage | ListReport, manifest: Manifest) => InternalObjectPage | InternalListReport;
5
6
  /**
6
7
  * Suffix for patterns to support arbitrary paramters
7
8
  */
@@ -49,4 +50,17 @@ export declare function getFclConfig(manifest: Manifest, navigation?: Navigation
49
50
  * @returns the updated memfs editor instance
50
51
  */
51
52
  export declare function validatePageConfig(basePath: string, config: CustomPage | ObjectPage, fs: Editor): Editor;
53
+ /**
54
+ * Add an generic page to an existing UI5 application.
55
+ * Supported pages - ListReport or ObjectPage.
56
+ *
57
+ * @param basePath - the base path
58
+ * @param data - the page configuration
59
+ * @param enhanceDataFn - Callback function for data enhancement
60
+ * @param templatePath - path to 'manifest.json' template
61
+ * @param fs - the memfs editor instance
62
+ * @returns the updated memfs editor instance
63
+ */
64
+ export declare function extendPageJSON(basePath: string, data: ObjectPage, enhanceDataFn: EnhancePageConfigFunction, templatePath: string, fs?: Editor): Editor;
65
+ export {};
52
66
  //# sourceMappingURL=common.d.ts.map
@@ -1,9 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validatePageConfig = exports.getFclConfig = exports.getManifestJsonExtensionHelper = exports.generateRouteTarget = exports.generateRoutePattern = exports.PATTERN_SUFFIX = void 0;
3
+ exports.extendPageJSON = exports.validatePageConfig = exports.getFclConfig = exports.getManifestJsonExtensionHelper = exports.generateRouteTarget = exports.generateRoutePattern = exports.PATTERN_SUFFIX = void 0;
4
+ const mem_fs_1 = require("mem-fs");
5
+ const mem_fs_editor_1 = require("mem-fs-editor");
4
6
  const path_1 = require("path");
7
+ const ejs_1 = require("ejs");
5
8
  const validate_1 = require("../common/validate");
6
9
  const defaults_1 = require("../common/defaults");
10
+ const file_1 = require("../common/file");
11
+ const templates_1 = require("../templates");
7
12
  /**
8
13
  * Suffix for patterns to support arbitrary paramters
9
14
  */
@@ -154,4 +159,33 @@ function validatePageConfig(basePath, config, fs) {
154
159
  return fs;
155
160
  }
156
161
  exports.validatePageConfig = validatePageConfig;
162
+ /**
163
+ * Add an generic page to an existing UI5 application.
164
+ * Supported pages - ListReport or ObjectPage.
165
+ *
166
+ * @param basePath - the base path
167
+ * @param data - the page configuration
168
+ * @param enhanceDataFn - Callback function for data enhancement
169
+ * @param templatePath - path to 'manifest.json' template
170
+ * @param fs - the memfs editor instance
171
+ * @returns the updated memfs editor instance
172
+ */
173
+ function extendPageJSON(basePath, data, enhanceDataFn, templatePath, fs) {
174
+ if (!fs) {
175
+ fs = mem_fs_editor_1.create(mem_fs_1.create());
176
+ }
177
+ validatePageConfig(basePath, data, fs);
178
+ const manifestPath = path_1.join(basePath, 'webapp/manifest.json');
179
+ const manifest = fs.readJSON(manifestPath);
180
+ const config = enhanceDataFn(data, manifest);
181
+ // enhance manifest.json
182
+ file_1.extendJSON(fs, {
183
+ filepath: manifestPath,
184
+ content: ejs_1.render(fs.read(templates_1.getTemplatePath(templatePath)), config, {}),
185
+ replacer: getManifestJsonExtensionHelper(config),
186
+ tabInfo: data.tabInfo
187
+ });
188
+ return fs;
189
+ }
190
+ exports.extendPageJSON = extendPageJSON;
157
191
  //# sourceMappingURL=common.js.map
@@ -11,6 +11,7 @@ const validate_1 = require("../common/validate");
11
11
  const templates_1 = require("../templates");
12
12
  const semver_1 = require("semver");
13
13
  const utils_1 = require("../common/utils");
14
+ const file_1 = require("../common/file");
14
15
  /**
15
16
  * Enhances the provided custom page configuration with default data.
16
17
  *
@@ -70,7 +71,12 @@ function generate(basePath, data, fs) {
70
71
  // merge content into existing files
71
72
  const root = getTemplateRoot(data.minUI5Version);
72
73
  // enhance manifest.json
73
- fs.extendJSON(manifestPath, JSON.parse(ejs_1.render(fs.read(path_1.join(root, `manifest.json`)), config, {})), common_1.getManifestJsonExtensionHelper(config));
74
+ file_1.extendJSON(fs, {
75
+ filepath: manifestPath,
76
+ content: ejs_1.render(fs.read(path_1.join(root, `manifest.json`)), config, {}),
77
+ replacer: common_1.getManifestJsonExtensionHelper(config),
78
+ tabInfo: data.tabInfo
79
+ });
74
80
  // add extension content
75
81
  const viewPath = path_1.join(config.path, `${config.name}.view.xml`);
76
82
  if (!fs.exists(viewPath)) {
package/dist/page/list.js CHANGED
@@ -1,12 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generate = void 0;
4
- const path_1 = require("path");
5
- const mem_fs_1 = require("mem-fs");
6
- const mem_fs_editor_1 = require("mem-fs-editor");
7
- const ejs_1 = require("ejs");
8
4
  const common_1 = require("./common");
9
- const templates_1 = require("../templates");
10
5
  /**
11
6
  * Enhances the provided list report configuration with default data.
12
7
  *
@@ -44,16 +39,7 @@ function enhanceData(data, manifest) {
44
39
  * @returns the updated memfs editor instance
45
40
  */
46
41
  function generate(basePath, data, fs) {
47
- if (!fs) {
48
- fs = mem_fs_editor_1.create(mem_fs_1.create());
49
- }
50
- common_1.validatePageConfig(basePath, data, fs);
51
- const manifestPath = path_1.join(basePath, 'webapp/manifest.json');
52
- const manifest = fs.readJSON(manifestPath);
53
- const config = enhanceData(data, manifest);
54
- // enhance manifest.json
55
- fs.extendJSON(manifestPath, JSON.parse(ejs_1.render(fs.read(templates_1.getTemplatePath('page/list/manifest.json')), config, {})), common_1.getManifestJsonExtensionHelper(config));
56
- return fs;
42
+ return common_1.extendPageJSON(basePath, data, enhanceData, 'page/list/manifest.json', fs);
57
43
  }
58
44
  exports.generate = generate;
59
45
  //# sourceMappingURL=list.js.map
@@ -1,12 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generate = void 0;
4
- const path_1 = require("path");
5
- const mem_fs_1 = require("mem-fs");
6
- const mem_fs_editor_1 = require("mem-fs-editor");
7
- const ejs_1 = require("ejs");
8
4
  const common_1 = require("./common");
9
- const templates_1 = require("../templates");
10
5
  /**
11
6
  * Enhances the provided list report configuration with default data.
12
7
  *
@@ -34,16 +29,7 @@ function enhanceData(data, manifest) {
34
29
  * @returns the updated memfs editor instance
35
30
  */
36
31
  function generate(basePath, data, fs) {
37
- if (!fs) {
38
- fs = mem_fs_editor_1.create(mem_fs_1.create());
39
- }
40
- common_1.validatePageConfig(basePath, data, fs);
41
- const manifestPath = path_1.join(basePath, 'webapp/manifest.json');
42
- const manifest = fs.readJSON(manifestPath);
43
- const config = enhanceData(data, manifest);
44
- // enhance manifest.json
45
- fs.extendJSON(manifestPath, JSON.parse(ejs_1.render(fs.read(templates_1.getTemplatePath('/page/object/manifest.json')), config, {})), common_1.getManifestJsonExtensionHelper(config));
46
- return fs;
32
+ return common_1.extendPageJSON(basePath, data, enhanceData, '/page/object/manifest.json', fs);
47
33
  }
48
34
  exports.generate = generate;
49
35
  //# sourceMappingURL=object.js.map
@@ -1,4 +1,4 @@
1
- import type { CustomElement, InternalCustomElement } from '../common/types';
1
+ import type { CustomElement, InternalCustomElement, WriterConfig } from '../common/types';
2
2
  /**
3
3
  * Incoming navigation configuration.
4
4
  */
@@ -33,7 +33,7 @@ export interface ListReportSettings extends StandardPageSettings {
33
33
  /**
34
34
  * Configuration options for adding a list report page.
35
35
  */
36
- export interface ListReport {
36
+ export interface ListReport extends WriterConfig {
37
37
  /**
38
38
  * Name of the entity used for the custom page.
39
39
  */
@@ -46,7 +46,7 @@ export interface ListReport {
46
46
  /**
47
47
  * Configuration options for adding an object page.
48
48
  */
49
- export interface ObjectPage {
49
+ export interface ObjectPage extends WriterConfig {
50
50
  /**
51
51
  * Name of the entity used for the custom page.
52
52
  */
@@ -8,6 +8,7 @@ const ejs_1 = require("ejs");
8
8
  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
+ const file_1 = require("../common/file");
11
12
  const templates_1 = require("../templates");
12
13
  const semver_1 = require("semver");
13
14
  /**
@@ -79,7 +80,11 @@ function generateCustomSection(basePath, customSection, fs) {
79
80
  // enhance manifest with section definition
80
81
  const manifestRoot = getManifestRoot(customSection.minUI5Version);
81
82
  const filledTemplate = ejs_1.render(fs.read(path_1.join(manifestRoot, `manifest.json`)), completeSection, {});
82
- fs.extendJSON(manifestPath, JSON.parse(filledTemplate));
83
+ file_1.extendJSON(fs, {
84
+ filepath: manifestPath,
85
+ content: filledTemplate,
86
+ tabInfo: customSection.tabInfo
87
+ });
83
88
  // add fragment
84
89
  const viewPath = path_1.join(completeSection.path, `${completeSection.name}.fragment.xml`);
85
90
  if (!fs.exists(viewPath)) {
@@ -8,7 +8,40 @@ const ejs_1 = require("ejs");
8
8
  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
+ const file_1 = require("../common/file");
11
12
  const templates_1 = require("../templates");
13
+ /**
14
+ * Merge the new view into the list of existing views (if any).
15
+ *
16
+ * @param {CustomView & Partial<InternalCustomView>} config - config for the template, views property gets updated
17
+ * @param {Manifest} manifest - the application manifest
18
+ */
19
+ function mergeViews(config, manifest) {
20
+ var _a, _b, _c, _d, _e;
21
+ const newViews = {
22
+ paths: [
23
+ {
24
+ 'key': config.key,
25
+ 'label': config.label,
26
+ 'template': `${config.ns}.${config.name}`
27
+ }
28
+ ]
29
+ };
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[config.target]).options) === null || _d === void 0 ? void 0 : _d.settings) === null || _e === void 0 ? void 0 : _e.views;
31
+ if (existingViews === null || existingViews === void 0 ? void 0 : existingViews.paths) {
32
+ const index = existingViews.paths.findIndex((entry) => entry.key === newViews.paths[0].key);
33
+ if (index > -1) {
34
+ existingViews.paths[index] = newViews.paths[0];
35
+ }
36
+ else {
37
+ existingViews.paths.push(newViews.paths[0]);
38
+ }
39
+ config.views = existingViews;
40
+ }
41
+ else {
42
+ config.views = newViews;
43
+ }
44
+ }
12
45
  /**
13
46
  * Enhances the provided custom view configuration with default data.
14
47
  *
@@ -19,19 +52,14 @@ const templates_1 = require("../templates");
19
52
  * @returns enhanced configuration
20
53
  */
21
54
  function enhanceConfig(fs, data, manifestPath, manifest) {
22
- var _a, _b, _c, _d, _e;
23
55
  const config = Object.assign({}, data);
24
56
  defaults_1.setCommonDefaults(config, manifestPath, manifest);
25
- // Apply event handler
57
+ // apply event handler
26
58
  if (config.eventHandler) {
27
59
  config.eventHandler = event_handler_1.applyEventHandlerConfiguration(fs, config, config.eventHandler, true, config.typescript);
28
60
  }
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
- }
61
+ // fill config.views, merge new data into existing views
62
+ mergeViews(config, manifest);
35
63
  // generate view content
36
64
  if (typeof config.control === 'string') {
37
65
  config.content = config.control;
@@ -61,14 +89,20 @@ function generateCustomView(basePath, customView, fs) {
61
89
  const completeView = enhanceConfig(fs, customView, manifestPath, manifest);
62
90
  // enhance manifest with view definition
63
91
  const filledTemplate = ejs_1.render(fs.read(templates_1.getTemplatePath('view/manifest.json')), completeView, {});
64
- fs.extendJSON(manifestPath, JSON.parse(filledTemplate));
92
+ file_1.extendJSON(fs, {
93
+ filepath: manifestPath,
94
+ content: filledTemplate,
95
+ tabInfo: customView.tabInfo
96
+ });
65
97
  // 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);
98
+ if (customView.viewUpdate !== false) {
99
+ const viewPath = path_1.join(completeView.path, `${completeView.name}.fragment.xml`);
100
+ if (completeView.control === true) {
101
+ fs.copyTpl(templates_1.getTemplatePath('view/ext/CustomViewWithTable.xml'), viewPath, completeView);
102
+ }
103
+ else if (!fs.exists(viewPath)) {
104
+ fs.copyTpl(templates_1.getTemplatePath('common/Fragment.xml'), viewPath, completeView);
105
+ }
72
106
  }
73
107
  return fs;
74
108
  }
@@ -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.4",
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
  }