@sap-ux/fe-fpm-writer 0.29.5 → 0.29.6

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.
@@ -9,7 +9,7 @@ import { type CodeSnippet } from '../prompts/types';
9
9
  * @param {Editor} [fs] - the memfs editor instance
10
10
  * @returns {Editor} the updated memfs editor instance
11
11
  */
12
- export declare function generateBuildingBlock<T extends BuildingBlock>(basePath: string, config: BuildingBlockConfig<T>, fs?: Editor): Editor;
12
+ export declare function generateBuildingBlock<T extends BuildingBlock>(basePath: string, config: BuildingBlockConfig<T>, fs?: Editor): Promise<Editor>;
13
13
  /**
14
14
  * Gets the serialized content of the updated view file.
15
15
  *
@@ -18,7 +18,7 @@ export declare function generateBuildingBlock<T extends BuildingBlock>(basePath:
18
18
  * @param {Editor} [fs] - The memfs editor instance
19
19
  * @returns {{ [questionName: string]: CodeSnippet }} An object with serialized code snippet content and file props
20
20
  */
21
- export declare function getSerializedFileContent<T extends BuildingBlock>(basePath: string, config: BuildingBlockConfig<T>, fs?: Editor): {
21
+ export declare function getSerializedFileContent<T extends BuildingBlock>(basePath: string, config: BuildingBlockConfig<T>, fs?: Editor): Promise<{
22
22
  [questionName: string]: CodeSnippet;
23
- };
23
+ }>;
24
24
  //# sourceMappingURL=index.d.ts.map
@@ -40,11 +40,22 @@ const templates_1 = require("../templates");
40
40
  const types_2 = require("../prompts/types");
41
41
  const semver_1 = require("semver");
42
42
  const project_access_1 = require("@sap-ux/project-access");
43
+ const file_1 = require("../common/file");
43
44
  const PLACEHOLDERS = {
44
45
  'id': 'REPLACE_WITH_BUILDING_BLOCK_ID',
45
46
  'entitySet': 'REPLACE_WITH_ENTITY',
46
47
  'qualifier': 'REPLACE_WITH_A_QUALIFIER'
47
48
  };
49
+ /**
50
+ * Gets manifest path.
51
+ *
52
+ * @param {string} basePath the base path
53
+ * @param {Editor} fs the memfs editor instance
54
+ * @returns {Manifest | undefined} path to manifest file
55
+ */
56
+ async function getManifestPath(basePath, fs) {
57
+ return (0, path_1.join)(await (0, project_access_1.getWebappPath)(basePath, fs), 'manifest.json');
58
+ }
48
59
  /**
49
60
  * Gets manifest content.
50
61
  *
@@ -52,8 +63,8 @@ const PLACEHOLDERS = {
52
63
  * @param {Editor} fs the memfs editor instance
53
64
  * @returns {Manifest | undefined} the manifest content
54
65
  */
55
- function getManifest(basePath, fs) {
56
- const manifestPath = (0, path_1.join)(basePath, 'webapp/manifest.json');
66
+ async function getManifest(basePath, fs) {
67
+ const manifestPath = await getManifestPath(basePath, fs);
57
68
  return fs.readJSON(manifestPath);
58
69
  }
59
70
  /**
@@ -64,20 +75,32 @@ function getManifest(basePath, fs) {
64
75
  * @param {Editor} [fs] - the memfs editor instance
65
76
  * @returns {Editor} the updated memfs editor instance
66
77
  */
67
- function generateBuildingBlock(basePath, config, fs) {
78
+ async function generateBuildingBlock(basePath, config, fs) {
68
79
  // Validate the base and view paths
69
80
  if (!fs) {
70
81
  fs = (0, mem_fs_editor_1.create)((0, mem_fs_1.create)());
71
82
  }
72
- (0, validate_1.validateBasePath)(basePath, fs, ['sap.fe.templates', 'sap.fe.core']);
83
+ (0, validate_1.validateBasePath)(basePath, fs, []);
73
84
  if (!fs.exists((0, path_1.join)(basePath, config.viewOrFragmentPath))) {
74
85
  throw new Error(`Invalid view path ${config.viewOrFragmentPath}.`);
75
86
  }
76
87
  // Read the view xml and template files and update contents of the view xml file
77
88
  const xmlDocument = getUI5XmlDocument(basePath, config.viewOrFragmentPath, fs);
78
- const manifest = getManifest(basePath, fs);
89
+ const manifest = await getManifest(basePath, fs);
79
90
  const templateDocument = getTemplateDocument(config.buildingBlockData, xmlDocument, fs, manifest);
80
91
  fs = updateViewFile(basePath, config.viewOrFragmentPath, config.aggregationPath, xmlDocument, templateDocument, fs);
92
+ if (manifest && !(0, validate_1.validateDependenciesLibs)(manifest, ['sap.fe.macros'])) {
93
+ // "sap.fe.macros" is missing - enhance manifest.json for missing "sap.fe.macros"
94
+ const manifestPath = await getManifestPath(basePath, fs);
95
+ const templatePath = (0, templates_1.getTemplatePath)('/building-block/common/manifest.json');
96
+ const content = fs.read(manifestPath);
97
+ const tabInfo = (0, file_1.detectTabSpacing)(content);
98
+ (0, file_1.extendJSON)(fs, {
99
+ filepath: manifestPath,
100
+ content: (0, ejs_1.render)(fs.read(templatePath), { libraries: { 'sap.fe.macros': {} } }),
101
+ tabInfo: tabInfo
102
+ });
103
+ }
81
104
  return fs;
82
105
  }
83
106
  exports.generateBuildingBlock = generateBuildingBlock;
@@ -285,7 +308,7 @@ function getFilePathProps(basePath, relativePath) {
285
308
  * @param {Editor} [fs] - The memfs editor instance
286
309
  * @returns {{ [questionName: string]: CodeSnippet }} An object with serialized code snippet content and file props
287
310
  */
288
- function getSerializedFileContent(basePath, config, fs) {
311
+ async function getSerializedFileContent(basePath, config, fs) {
289
312
  if (!config.buildingBlockData?.buildingBlockType) {
290
313
  return {};
291
314
  }
@@ -297,7 +320,7 @@ function getSerializedFileContent(basePath, config, fs) {
297
320
  const xmlDocument = config.viewOrFragmentPath
298
321
  ? getUI5XmlDocument(basePath, config.viewOrFragmentPath, fs)
299
322
  : undefined;
300
- const manifest = getManifest(basePath, fs);
323
+ const manifest = await getManifest(basePath, fs);
301
324
  const content = getTemplateContent(config.buildingBlockData, xmlDocument, manifest, fs, true);
302
325
  const filePathProps = getFilePathProps(basePath, config.viewOrFragmentPath);
303
326
  return {
@@ -1,4 +1,5 @@
1
1
  import type { Editor } from 'mem-fs-editor';
2
+ import type { Manifest } from './types';
2
3
  /**
3
4
  * Validate that the UI5 version requirement is valid.
4
5
  *
@@ -6,6 +7,14 @@ import type { Editor } from 'mem-fs-editor';
6
7
  * @returns true if the version is supported otherwise throws an error
7
8
  */
8
9
  export declare function validateVersion(ui5Version?: string): boolean;
10
+ /**
11
+ * Validates the library dependencies - at least one of expected dependencies is present.
12
+ *
13
+ * @param {string} manifest - the manifest content
14
+ * @param {string[]} dependencies - expected dependencies
15
+ * @returns true if at least one of expected dependencies is presented in manifest.
16
+ */
17
+ export declare function validateDependenciesLibs(manifest: Manifest, dependencies: string[]): boolean;
9
18
  /**
10
19
  * Validates the provided base path, checks at least one of expected dependencies is present.
11
20
  *
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getErrorMessage = exports.validateBasePath = exports.validateVersion = void 0;
3
+ exports.getErrorMessage = exports.validateBasePath = exports.validateDependenciesLibs = exports.validateVersion = void 0;
4
4
  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");
@@ -19,6 +19,22 @@ function validateVersion(ui5Version) {
19
19
  return true;
20
20
  }
21
21
  exports.validateVersion = validateVersion;
22
+ /**
23
+ * Validates the library dependencies - at least one of expected dependencies is present.
24
+ *
25
+ * @param {string} manifest - the manifest content
26
+ * @param {string[]} dependencies - expected dependencies
27
+ * @returns true if at least one of expected dependencies is presented in manifest.
28
+ */
29
+ function validateDependenciesLibs(manifest, dependencies) {
30
+ const libs = manifest['sap.ui5']?.dependencies?.libs;
31
+ return dependencies.length
32
+ ? dependencies.some((dependency) => {
33
+ return libs?.[dependency] !== undefined;
34
+ })
35
+ : true;
36
+ }
37
+ exports.validateDependenciesLibs = validateDependenciesLibs;
22
38
  /**
23
39
  * Validates the provided base path, checks at least one of expected dependencies is present.
24
40
  *
@@ -37,13 +53,7 @@ function validateBasePath(basePath, fs, dependencies = ['sap.fe.templates']) {
37
53
  }
38
54
  else {
39
55
  const manifest = fs.readJSON(manifestPath);
40
- const libs = manifest['sap.ui5']?.dependencies?.libs;
41
- const valid = dependencies.length
42
- ? dependencies.some((dependency) => {
43
- return libs?.[dependency] !== undefined;
44
- })
45
- : true;
46
- if (!valid) {
56
+ if (!validateDependenciesLibs(manifest, dependencies)) {
47
57
  if (dependencies.length === 1) {
48
58
  throw new Error(`Dependency ${dependencies[0]} is missing in the manifest.json. Fiori elements FPM requires the SAP FE libraries.`);
49
59
  }
@@ -58,7 +58,7 @@ export declare class PromptsAPI {
58
58
  * @param answers The answers object
59
59
  * @returns The updated memfs editor instance
60
60
  */
61
- submitAnswers<N extends SupportedPrompts['type']>(type: N, answers: NarrowPrompt<typeof type>['answers']): Editor;
61
+ submitAnswers<N extends SupportedPrompts['type']>(type: N, answers: NarrowPrompt<typeof type>['answers']): Promise<Editor>;
62
62
  /**
63
63
  * Method returns code snippet for passed answers and prompt type.
64
64
  *
@@ -66,9 +66,9 @@ export declare class PromptsAPI {
66
66
  * @param answers The answers object
67
67
  * @returns Code snippet content.
68
68
  */
69
- getCodeSnippets<N extends SupportedPrompts['type']>(type: N, answers: NarrowPrompt<typeof type>['answers']): {
69
+ getCodeSnippets<N extends SupportedPrompts['type']>(type: N, answers: NarrowPrompt<typeof type>['answers']): Promise<{
70
70
  [questionName: string]: CodeSnippet;
71
- };
71
+ }>;
72
72
  /**
73
73
  * Method checks if passed type of prompt supports generation and code preview.
74
74
  *
@@ -134,7 +134,7 @@ class PromptsAPI {
134
134
  * @param answers The answers object
135
135
  * @returns The updated memfs editor instance
136
136
  */
137
- submitAnswers(type, answers) {
137
+ async submitAnswers(type, answers) {
138
138
  const config = { type, answers };
139
139
  if (!this.isGenerationSupported(config)) {
140
140
  return this.context.fs;
@@ -151,7 +151,7 @@ class PromptsAPI {
151
151
  * @param answers The answers object
152
152
  * @returns Code snippet content.
153
153
  */
154
- getCodeSnippets(type, answers) {
154
+ async getCodeSnippets(type, answers) {
155
155
  const config = { type, answers };
156
156
  if (!this.isGenerationSupported(config)) {
157
157
  return {};
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.29.5",
4
+ "version": "0.29.6",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/SAP/open-ux-tools.git",
@@ -0,0 +1,7 @@
1
+ {
2
+ "sap.ui5": {
3
+ "dependencies": {
4
+ "libs": <%- JSON.stringify(libraries) %>
5
+ }
6
+ }
7
+ }