@sap-ux/fe-fpm-writer 0.25.0 → 0.25.2

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/dist/app/index.js CHANGED
@@ -5,10 +5,51 @@ const mem_fs_1 = require("mem-fs");
5
5
  const mem_fs_editor_1 = require("mem-fs-editor");
6
6
  const path_1 = require("path");
7
7
  const semver_1 = require("semver");
8
+ const project_access_1 = require("@sap-ux/project-access");
8
9
  const defaults_1 = require("../common/defaults");
9
10
  const templates_1 = require("../templates");
10
11
  const utils_1 = require("../common/utils");
11
12
  exports.MIN_VERSION = '1.94.0';
13
+ /**
14
+ * If a minUI5Version is set and it is smaller than the minimum required, increase it.
15
+ *
16
+ * @param {Manifest} manifest - content of the mnaifest.json
17
+ * @param {Editor} fs - the mem-fs editor instance
18
+ * @param {string} manifestPath - path to the manifest.json file
19
+ */
20
+ function adaptMinUI5Version(manifest, fs, manifestPath) {
21
+ const minUI5VersionArray = (0, project_access_1.getMinUI5VersionAsArray)(manifest, true);
22
+ if (minUI5VersionArray?.length > 0) {
23
+ let update = false;
24
+ for (let index = 0; index < minUI5VersionArray.length; index++) {
25
+ const minUI5Version = minUI5VersionArray[index];
26
+ if (minUI5Version && (0, semver_1.valid)(minUI5Version) && (0, semver_1.lt)(minUI5Version, exports.MIN_VERSION)) {
27
+ minUI5VersionArray[index] = exports.MIN_VERSION;
28
+ update = true;
29
+ }
30
+ }
31
+ if (update) {
32
+ if (minUI5VersionArray.length === 1) {
33
+ fs.extendJSON(manifestPath, {
34
+ 'sap.ui5': {
35
+ dependencies: {
36
+ minUI5Version: minUI5VersionArray[0]
37
+ }
38
+ }
39
+ });
40
+ }
41
+ else if (minUI5VersionArray.length > 1) {
42
+ fs.extendJSON(manifestPath, {
43
+ 'sap.ui5': {
44
+ dependencies: {
45
+ minUI5Version: minUI5VersionArray
46
+ }
47
+ }
48
+ });
49
+ }
50
+ }
51
+ }
52
+ }
12
53
  /**
13
54
  * Enable the flexible programming model for an application.
14
55
  *
@@ -39,19 +80,10 @@ function enableFPM(basePath, config = {}, fs) {
39
80
  });
40
81
  }
41
82
  // if a minUI5Version is set and it is smaller than the minimum required, increase it
42
- const minUI5Version = manifest['sap.ui5']?.dependencies?.minUI5Version;
43
- if (minUI5Version && (0, semver_1.valid)(minUI5Version) && (0, semver_1.lt)(minUI5Version, exports.MIN_VERSION)) {
44
- fs.extendJSON(manifestPath, {
45
- 'sap.ui5': {
46
- dependencies: {
47
- minUI5Version: exports.MIN_VERSION
48
- }
49
- }
50
- });
51
- }
83
+ adaptMinUI5Version(manifest, fs, manifestPath);
52
84
  // add type extensions if required
53
85
  if (config.typescript) {
54
- (0, utils_1.addExtensionTypes)(basePath, manifest['sap.ui5']?.dependencies.minUI5Version, fs);
86
+ (0, utils_1.addExtensionTypes)(basePath, (0, project_access_1.getMinimumUI5Version)(manifest), fs);
55
87
  }
56
88
  // enable FCL if requested
57
89
  if (config.fcl) {
@@ -11,9 +11,10 @@ export declare function validateVersion(ui5Version?: string): boolean;
11
11
  *
12
12
  * @param {string} basePath - the base path
13
13
  * @param {Editor} fs - the memfs editor instance
14
+ * @param {string[]} dependencies - expected dependencies
14
15
  * @returns true if the path is valid, otherwise, throws and error
15
16
  */
16
- export declare function validateBasePath(basePath: string, fs?: Editor): boolean;
17
+ export declare function validateBasePath(basePath: string, fs?: Editor, dependencies?: string[]): boolean;
17
18
  /**
18
19
  * Returns the message property if the error is an instance of `Error` else a string representation of the error.
19
20
  *
@@ -24,9 +24,10 @@ exports.validateVersion = validateVersion;
24
24
  *
25
25
  * @param {string} basePath - the base path
26
26
  * @param {Editor} fs - the memfs editor instance
27
+ * @param {string[]} dependencies - expected dependencies
27
28
  * @returns true if the path is valid, otherwise, throws and error
28
29
  */
29
- function validateBasePath(basePath, fs) {
30
+ function validateBasePath(basePath, fs, dependencies = ['sap.fe.templates']) {
30
31
  if (!fs) {
31
32
  fs = (0, mem_fs_editor_1.create)((0, mem_fs_1.create)());
32
33
  }
@@ -36,9 +37,12 @@ function validateBasePath(basePath, fs) {
36
37
  }
37
38
  else {
38
39
  const manifest = fs.readJSON(manifestPath);
39
- if ((manifest['sap.ui5']?.dependencies?.libs?.['sap.fe.templates'] !== undefined) === false) {
40
- throw new Error('Dependency sap.fe.templates is missing in the manifest.json. Fiori elements FPM requires the SAP FE libraries.');
41
- }
40
+ const libs = manifest['sap.ui5']?.dependencies?.libs;
41
+ dependencies.forEach((dependency) => {
42
+ if (libs?.[dependency] === undefined) {
43
+ throw new Error(`Dependency ${dependency} is missing in the manifest.json. Fiori elements FPM requires the SAP FE libraries.`);
44
+ }
45
+ });
42
46
  }
43
47
  return true;
44
48
  }
@@ -1,6 +1,7 @@
1
1
  import type { Editor } from 'mem-fs-editor';
2
2
  import type { ManifestNamespace } from '@sap-ux/project-access';
3
- import type { CustomPage, FCL, FpmPage, InternalCustomPage, InternalObjectPage, ObjectPage, ListReport, Navigation, InternalListReport } from './types';
3
+ import type { CustomPage, FCL, FpmPage, InternalCustomPage, InternalObjectPage, ObjectPage, ListReport, Navigation, InternalListReport, Libraries } from './types';
4
+ import { PageType } from './types';
4
5
  import type { Manifest } from '../common/types';
5
6
  type EnhancePageConfigFunction = (data: ObjectPage | ListReport, manifest: Manifest) => InternalObjectPage | InternalListReport;
6
7
  /**
@@ -41,6 +42,13 @@ export declare function getManifestJsonExtensionHelper(config: InternalCustomPag
41
42
  * @returns fcl configuration
42
43
  */
43
44
  export declare function getFclConfig(manifest: Manifest, navigation?: Navigation): FCL;
45
+ /**
46
+ * Get the library dependencies for a given page type.
47
+ *
48
+ * @param pageType - Page type for which the dependencies are to be added
49
+ * @returns Library dependencies
50
+ */
51
+ export declare function getLibraryDependencies(pageType: PageType): Libraries;
44
52
  /**
45
53
  * Create target settings for a Fiori elements page.
46
54
  *
@@ -55,9 +63,10 @@ export declare function initializeTargetSettings(data: FpmPage, addSettings?: Re
55
63
  * @param basePath - the base path
56
64
  * @param config - the custom page configuration
57
65
  * @param fs - the memfs editor instance
66
+ * @param dependencies - expected dependencies
58
67
  * @returns the updated memfs editor instance
59
68
  */
60
- export declare function validatePageConfig(basePath: string, config: CustomPage | ObjectPage, fs: Editor): Editor;
69
+ export declare function validatePageConfig(basePath: string, config: CustomPage | ObjectPage, fs: Editor, dependencies?: never[]): Editor;
61
70
  /**
62
71
  * Add an generic page to an existing UI5 application.
63
72
  * Supported pages - ListReport or ObjectPage.
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.extendPageJSON = exports.validatePageConfig = exports.initializeTargetSettings = exports.getFclConfig = exports.getManifestJsonExtensionHelper = exports.generateRouteTarget = exports.generateRoutePattern = exports.PATTERN_SUFFIX = void 0;
3
+ exports.extendPageJSON = exports.validatePageConfig = exports.initializeTargetSettings = exports.getLibraryDependencies = exports.getFclConfig = exports.getManifestJsonExtensionHelper = exports.generateRouteTarget = exports.generateRoutePattern = exports.PATTERN_SUFFIX = void 0;
4
4
  const mem_fs_1 = require("mem-fs");
5
5
  const mem_fs_editor_1 = require("mem-fs-editor");
6
6
  const path_1 = require("path");
7
7
  const ejs_1 = require("ejs");
8
8
  const validate_1 = require("../common/validate");
9
+ const types_1 = require("./types");
9
10
  const defaults_1 = require("../common/defaults");
10
11
  const file_1 = require("../common/file");
11
12
  const templates_1 = require("../templates");
@@ -121,6 +122,28 @@ function getFclConfig(manifest, navigation) {
121
122
  return config;
122
123
  }
123
124
  exports.getFclConfig = getFclConfig;
125
+ /**
126
+ * Get the library dependencies for a given page type.
127
+ *
128
+ * @param pageType - Page type for which the dependencies are to be added
129
+ * @returns Library dependencies
130
+ */
131
+ function getLibraryDependencies(pageType) {
132
+ const libraries = {};
133
+ switch (pageType) {
134
+ case types_1.PageType.CustomPage: {
135
+ libraries['sap.fe.core'] = {};
136
+ break;
137
+ }
138
+ case types_1.PageType.ListReport:
139
+ case types_1.PageType.ObjectPage: {
140
+ libraries['sap.fe.templates'] = {};
141
+ break;
142
+ }
143
+ }
144
+ return libraries;
145
+ }
146
+ exports.getLibraryDependencies = getLibraryDependencies;
124
147
  /**
125
148
  * Create target settings for a Fiori elements page.
126
149
  *
@@ -148,11 +171,12 @@ exports.initializeTargetSettings = initializeTargetSettings;
148
171
  * @param basePath - the base path
149
172
  * @param config - the custom page configuration
150
173
  * @param fs - the memfs editor instance
174
+ * @param dependencies - expected dependencies
151
175
  * @returns the updated memfs editor instance
152
176
  */
153
- function validatePageConfig(basePath, config, fs) {
177
+ function validatePageConfig(basePath, config, fs, dependencies = []) {
154
178
  // common validators
155
- (0, validate_1.validateBasePath)(basePath, fs);
179
+ (0, validate_1.validateBasePath)(basePath, fs, dependencies);
156
180
  // validate config against the manifest
157
181
  if (config.navigation?.sourcePage) {
158
182
  const manifest = fs.readJSON((0, path_1.join)(basePath, 'webapp/manifest.json'));
@@ -5,6 +5,7 @@ const path_1 = require("path");
5
5
  const mem_fs_1 = require("mem-fs");
6
6
  const mem_fs_editor_1 = require("mem-fs-editor");
7
7
  const ejs_1 = require("ejs");
8
+ const types_1 = require("./types");
8
9
  const common_1 = require("./common");
9
10
  const defaults_1 = require("../common/defaults");
10
11
  const validate_1 = require("../common/validate");
@@ -25,6 +26,8 @@ function enhanceData(data, manifestPath, fs) {
25
26
  // set common defaults
26
27
  const config = (0, defaults_1.setCommonDefaults)(data, manifestPath, manifest);
27
28
  config.settings = (0, common_1.initializeTargetSettings)(data);
29
+ // set library dependencies
30
+ config.libraries = (0, common_1.getLibraryDependencies)(types_1.PageType.CustomPage);
28
31
  // set FCL configuration
29
32
  const fclConfig = (0, common_1.getFclConfig)(manifest, config.navigation);
30
33
  config.fcl = fclConfig.fcl;
@@ -66,7 +69,7 @@ function generate(basePath, data, fs) {
66
69
  fs = (0, mem_fs_editor_1.create)((0, mem_fs_1.create)());
67
70
  }
68
71
  (0, validate_1.validateVersion)(data.minUI5Version);
69
- (0, common_1.validatePageConfig)(basePath, data, fs);
72
+ (0, common_1.validatePageConfig)(basePath, data, fs, []);
70
73
  const manifestPath = (0, path_1.join)(basePath, 'webapp/manifest.json');
71
74
  const config = enhanceData(data, manifestPath, fs);
72
75
  // merge content into existing files
package/dist/page/list.js CHANGED
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generate = void 0;
4
4
  const common_1 = require("./common");
5
+ const types_1 = require("./types");
5
6
  /**
6
7
  * Enhances the provided list report configuration with default data.
7
8
  *
@@ -13,9 +14,11 @@ function enhanceData(data, manifest) {
13
14
  const config = {
14
15
  ...data,
15
16
  settings: (0, common_1.initializeTargetSettings)(data, data.settings),
16
- name: 'ListReport',
17
+ name: types_1.PageType.ListReport,
17
18
  ...(0, common_1.getFclConfig)(manifest)
18
19
  };
20
+ // set library dependencies
21
+ config.libraries = (0, common_1.getLibraryDependencies)(types_1.PageType.ListReport);
19
22
  // use standard file name if i18n enhancement required
20
23
  if (config.settings.enhanceI18n === true) {
21
24
  config.settings.enhanceI18n = `i18n/custom${config.entity}${config.name}.properties`;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generate = void 0;
4
4
  const common_1 = require("./common");
5
+ const types_1 = require("./types");
5
6
  /**
6
7
  * Enhances the provided list report configuration with default data.
7
8
  *
@@ -13,9 +14,11 @@ function enhanceData(data, manifest) {
13
14
  const config = {
14
15
  ...data,
15
16
  settings: (0, common_1.initializeTargetSettings)(data, data.settings),
16
- name: 'ObjectPage',
17
+ name: types_1.PageType.ObjectPage,
17
18
  ...(0, common_1.getFclConfig)(manifest)
18
19
  };
20
+ // set library dependencies
21
+ config.libraries = (0, common_1.getLibraryDependencies)(types_1.PageType.ObjectPage);
19
22
  // use standard file name if i18n enhancement required
20
23
  if (config.settings.enhanceI18n === true) {
21
24
  config.settings.enhanceI18n = `i18n/custom${config.entity}${config.name}.properties`;
@@ -16,6 +16,12 @@ export interface Navigation {
16
16
  */
17
17
  navKey?: boolean;
18
18
  }
19
+ /**
20
+ * Libraries to be added to the application
21
+ */
22
+ export type Libraries = {
23
+ [key: string]: {};
24
+ };
19
25
  export type StandardPageSettings = {
20
26
  enhanceI18n?: string | true;
21
27
  variantManagement?: 'Page' | 'None';
@@ -52,6 +58,10 @@ export interface FpmPage {
52
58
  * If nothing can be generated for the given version then an exception is thrown.
53
59
  */
54
60
  minUI5Version?: string;
61
+ /**
62
+ * UI5 Libraries that should be added to the application.
63
+ */
64
+ libraries?: Libraries;
55
65
  }
56
66
  /**
57
67
  * Configuration options for adding a list report page.
@@ -115,15 +125,20 @@ export interface FCL {
115
125
  export type InternalFpmPage = FCL & {
116
126
  settings: Record<string, unknown | undefined>;
117
127
  };
128
+ export declare enum PageType {
129
+ ListReport = "ListReport",
130
+ ObjectPage = "ObjectPage",
131
+ CustomPage = "CustomPage"
132
+ }
118
133
  /**
119
134
  * Additional internal configuration options that will be calculated based on the provided input as well as the target application.
120
135
  */
121
136
  export type InternalCustomPage = CustomPage & InternalFpmPage & InternalCustomElement;
122
137
  export type InternalListReport = ListReport & InternalFpmPage & {
123
- name: 'ListReport';
138
+ name: PageType.ListReport;
124
139
  navigation?: Navigation;
125
140
  };
126
141
  export type InternalObjectPage = ObjectPage & InternalFpmPage & {
127
- name: 'ObjectPage';
142
+ name: PageType.ObjectPage;
128
143
  };
129
144
  //# sourceMappingURL=types.d.ts.map
@@ -1,3 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PageType = void 0;
4
+ var PageType;
5
+ (function (PageType) {
6
+ PageType["ListReport"] = "ListReport";
7
+ PageType["ObjectPage"] = "ObjectPage";
8
+ PageType["CustomPage"] = "CustomPage";
9
+ })(PageType || (exports.PageType = PageType = {}));
3
10
  //# sourceMappingURL=types.js.map
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.25.0",
4
+ "version": "0.25.2",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/SAP/open-ux-tools.git",
@@ -33,7 +33,7 @@
33
33
  "@types/mem-fs": "1.1.2",
34
34
  "@types/mem-fs-editor": "7.0.1",
35
35
  "@types/semver": "7.5.2",
36
- "@sap-ux/project-access": "1.23.0"
36
+ "@sap-ux/project-access": "1.25.7"
37
37
  },
38
38
  "engines": {
39
39
  "node": ">=18.x"
@@ -1,5 +1,8 @@
1
1
  {
2
2
  "sap.ui5": {
3
+ "dependencies": {
4
+ "libs": <%- JSON.stringify(libraries) %>
5
+ },
3
6
  "routing": {
4
7
  "targets": {
5
8
  "<% if (typeof id !== 'undefined') { %><%- id %><% } else { %><%- entity %><%- name %><% } %>": {
@@ -1,5 +1,8 @@
1
1
  {
2
2
  "sap.ui5": {
3
+ "dependencies": {
4
+ "libs": <%- JSON.stringify(libraries) %>
5
+ },
3
6
  "routing": {
4
7
  "targets": {
5
8
  "<% if (typeof id !== 'undefined') { %><%- id %><% } else { %><%- entity %><%- name %><% } %>": {
@@ -1,5 +1,8 @@
1
1
  {
2
2
  "sap.ui5": {
3
+ "dependencies": {
4
+ "libs": <%- JSON.stringify(libraries) %>
5
+ },
3
6
  "routing": {
4
7
  "targets": {
5
8
  "<% if (typeof id !== 'undefined') { %><%- id %><% } else { %><%- entity %>ListReport<% } %>": {
@@ -1,5 +1,8 @@
1
1
  {
2
2
  "sap.ui5": {
3
+ "dependencies": {
4
+ "libs": <%- JSON.stringify(libraries) %>
5
+ },
3
6
  "routing": {
4
7
  "targets": {
5
8
  "<% if (typeof id !== 'undefined') { %><%- id %><% } else { %><%- entity %>ObjectPage<% } %>": {