@sap-ux/fe-fpm-writer 0.31.0 → 0.31.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.
@@ -10,6 +10,13 @@ import { type CodeSnippet } from '../prompts/types';
10
10
  * @returns {Editor} the updated memfs editor instance
11
11
  */
12
12
  export declare function generateBuildingBlock<T extends BuildingBlock>(basePath: string, config: BuildingBlockConfig<T>, fs?: Editor): Promise<Editor>;
13
+ /**
14
+ * Method returns the manifest content for the required dependency library.
15
+ *
16
+ * @param {Editor} fs - the memfs editor instance
17
+ * @returns {Promise<string>} Manifest content for the required dependency library.
18
+ */
19
+ export declare function getManifestContent(fs: Editor): Promise<string>;
13
20
  /**
14
21
  * Gets the serialized content of the updated view file.
15
22
  *
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.getSerializedFileContent = exports.generateBuildingBlock = void 0;
29
+ exports.getSerializedFileContent = exports.getManifestContent = exports.generateBuildingBlock = void 0;
30
30
  const mem_fs_1 = require("mem-fs");
31
31
  const mem_fs_editor_1 = require("mem-fs-editor");
32
32
  const ejs_1 = require("ejs");
@@ -56,28 +56,29 @@ const PLACEHOLDERS = {
56
56
  * @returns {Editor} the updated memfs editor instance
57
57
  */
58
58
  async function generateBuildingBlock(basePath, config, fs) {
59
+ const { viewOrFragmentPath, aggregationPath, buildingBlockData, allowAutoAddDependencyLib = true } = config;
59
60
  // Validate the base and view paths
60
61
  if (!fs) {
61
62
  fs = (0, mem_fs_editor_1.create)((0, mem_fs_1.create)());
62
63
  }
63
64
  (0, validate_1.validateBasePath)(basePath, fs, []);
64
- if (!fs.exists((0, path_1.join)(basePath, config.viewOrFragmentPath))) {
65
- throw new Error(`Invalid view path ${config.viewOrFragmentPath}.`);
65
+ if (!fs.exists((0, path_1.join)(basePath, viewOrFragmentPath))) {
66
+ throw new Error(`Invalid view path ${viewOrFragmentPath}.`);
66
67
  }
67
68
  // Read the view xml and template files and update contents of the view xml file
68
- const xmlDocument = getUI5XmlDocument(basePath, config.viewOrFragmentPath, fs);
69
+ const xmlDocument = getUI5XmlDocument(basePath, viewOrFragmentPath, fs);
69
70
  const { content: manifest } = await (0, utils_1.getManifest)(basePath, fs);
70
- const templateDocument = getTemplateDocument(config.buildingBlockData, xmlDocument, fs, manifest);
71
- fs = updateViewFile(basePath, config.viewOrFragmentPath, config.aggregationPath, xmlDocument, templateDocument, fs);
72
- if (manifest && !(0, validate_1.validateDependenciesLibs)(manifest, ['sap.fe.macros'])) {
71
+ const templateDocument = getTemplateDocument(buildingBlockData, xmlDocument, fs, manifest);
72
+ fs = updateViewFile(basePath, viewOrFragmentPath, aggregationPath, xmlDocument, templateDocument, fs);
73
+ if (allowAutoAddDependencyLib && manifest && !(0, validate_1.validateDependenciesLibs)(manifest, ['sap.fe.macros'])) {
73
74
  // "sap.fe.macros" is missing - enhance manifest.json for missing "sap.fe.macros"
74
75
  const manifestPath = await (0, utils_1.getManifestPath)(basePath, fs);
75
- const templatePath = (0, templates_1.getTemplatePath)('/building-block/common/manifest.json');
76
+ const manifestContent = await getManifestContent(fs);
76
77
  const content = fs.read(manifestPath);
77
78
  const tabInfo = (0, file_1.detectTabSpacing)(content);
78
79
  (0, file_1.extendJSON)(fs, {
79
80
  filepath: manifestPath,
80
- content: (0, ejs_1.render)(fs.read(templatePath), { libraries: { 'sap.fe.macros': {} } }),
81
+ content: manifestContent,
81
82
  tabInfo: tabInfo
82
83
  });
83
84
  }
@@ -211,6 +212,18 @@ function getTemplateContent(buildingBlockData, viewDocument, manifest, fs, usePl
211
212
  data: buildingBlockData
212
213
  }, {});
213
214
  }
215
+ /**
216
+ * Method returns the manifest content for the required dependency library.
217
+ *
218
+ * @param {Editor} fs - the memfs editor instance
219
+ * @returns {Promise<string>} Manifest content for the required dependency library.
220
+ */
221
+ async function getManifestContent(fs) {
222
+ // "sap.fe.macros" is missing - enhance manifest.json for missing "sap.fe.macros"
223
+ const templatePath = (0, templates_1.getTemplatePath)('/building-block/common/manifest.json');
224
+ return (0, ejs_1.render)(fs.read(templatePath), { libraries: { 'sap.fe.macros': {} } });
225
+ }
226
+ exports.getManifestContent = getManifestContent;
214
227
  /**
215
228
  * Returns the template xml file document.
216
229
  *
@@ -289,7 +302,9 @@ function getFilePathProps(basePath, relativePath) {
289
302
  * @returns {{ [questionName: string]: CodeSnippet }} An object with serialized code snippet content and file props
290
303
  */
291
304
  async function getSerializedFileContent(basePath, config, fs) {
292
- if (!config.buildingBlockData?.buildingBlockType) {
305
+ const snippets = {};
306
+ const { buildingBlockData, viewOrFragmentPath, allowAutoAddDependencyLib = true } = config;
307
+ if (!buildingBlockData?.buildingBlockType) {
293
308
  return {};
294
309
  }
295
310
  // Validate the base and view paths
@@ -297,19 +312,30 @@ async function getSerializedFileContent(basePath, config, fs) {
297
312
  fs = (0, mem_fs_editor_1.create)((0, mem_fs_1.create)());
298
313
  }
299
314
  // Read the view xml and template files and get content of the view xml file
300
- const xmlDocument = config.viewOrFragmentPath
301
- ? getUI5XmlDocument(basePath, config.viewOrFragmentPath, fs)
302
- : undefined;
303
- const { content: manifest } = await (0, utils_1.getManifest)(basePath, fs, false);
304
- const content = getTemplateContent(config.buildingBlockData, xmlDocument, manifest, fs, true);
305
- const filePathProps = getFilePathProps(basePath, config.viewOrFragmentPath);
306
- return {
307
- viewOrFragmentPath: {
308
- content,
309
- language: types_2.CodeSnippetLanguage.XML,
310
- filePathProps
311
- }
315
+ const xmlDocument = viewOrFragmentPath ? getUI5XmlDocument(basePath, viewOrFragmentPath, fs) : undefined;
316
+ const { content: manifest, path: manifestPath } = await (0, utils_1.getManifest)(basePath, fs, false);
317
+ const content = getTemplateContent(buildingBlockData, xmlDocument, manifest, fs, true);
318
+ const filePathProps = getFilePathProps(basePath, viewOrFragmentPath);
319
+ // Snippet for fragment xml
320
+ snippets['viewOrFragmentPath'] = {
321
+ content,
322
+ language: types_2.CodeSnippetLanguage.XML,
323
+ filePathProps
312
324
  };
325
+ // Snippet for manifest.json
326
+ if (allowAutoAddDependencyLib) {
327
+ const manifestContent = await getManifestContent(fs);
328
+ snippets['manifest'] = {
329
+ content: manifestContent,
330
+ language: types_2.CodeSnippetLanguage.JSON,
331
+ filePathProps: {
332
+ fileName: (0, path_1.parse)(manifestPath).base,
333
+ relativePath: (0, path_1.relative)(basePath, manifestPath),
334
+ fullPath: manifestPath
335
+ }
336
+ };
337
+ }
338
+ return snippets;
313
339
  }
314
340
  exports.getSerializedFileContent = getSerializedFileContent;
315
341
  //# sourceMappingURL=index.js.map
@@ -365,5 +365,12 @@ export interface BuildingBlockConfig<T extends BuildingBlock> {
365
365
  * The building block parameters.
366
366
  */
367
367
  buildingBlockData: T;
368
+ /**
369
+ * Allows updating the 'manifest.json' file with missing dependency libraries.
370
+ * Dependency libraries are listed under '"sap.ui5"/"dependencies"/"libs"', and 'sap.fe.macros' is required for Building Blocks.
371
+ *
372
+ * @default true
373
+ */
374
+ allowAutoAddDependencyLib?: boolean;
368
375
  }
369
376
  //# sourceMappingURL=types.d.ts.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.31.0",
4
+ "version": "0.31.2",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/SAP/open-ux-tools.git",
@@ -31,8 +31,8 @@
31
31
  "semver": "7.5.4",
32
32
  "xml-formatter": "2.6.1",
33
33
  "xpath": "0.0.33",
34
- "@sap-ux/fiori-annotation-api": "0.2.2",
35
- "@sap-ux/project-access": "1.27.2"
34
+ "@sap-ux/fiori-annotation-api": "0.2.3",
35
+ "@sap-ux/project-access": "1.27.3"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@types/inquirer": "8.2.6",
@@ -42,7 +42,7 @@
42
42
  "@types/mem-fs-editor": "7.0.1",
43
43
  "@types/semver": "7.5.2",
44
44
  "@types/vinyl": "2.0.7",
45
- "@sap-ux/ui-prompting": "0.1.9"
45
+ "@sap-ux/ui-prompting": "0.1.12"
46
46
  },
47
47
  "engines": {
48
48
  "node": ">=18.x"