@sap-ux/adp-tooling 0.14.34 → 0.14.35

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.
@@ -2,7 +2,7 @@ import type { ReaderCollection } from '@ui5/fs';
2
2
  import type { MiddlewareUtils } from '@ui5/server';
3
3
  import type { NextFunction, Request, Response, Router } from 'express';
4
4
  import type { Logger, ToolsLogger } from '@sap-ux/logger';
5
- import type { UI5FlexLayer } from '@sap-ux/project-access';
5
+ import { type UI5FlexLayer } from '@sap-ux/project-access';
6
6
  import type { MergedAppDescriptor } from '@sap-ux/axios-extension';
7
7
  import type { AdpPreviewConfig, CommonChangeProperties, DescriptorVariant, OperationType, CommonAdditionalChangeInfoProperties } from '../types';
8
8
  import type { Editor } from 'mem-fs-editor';
@@ -8,6 +8,7 @@ const adm_zip_1 = __importDefault(require("adm-zip"));
8
8
  const system_access_1 = require("@sap-ux/system-access");
9
9
  const routes_handler_1 = __importDefault(require("./routes-handler"));
10
10
  const change_handler_1 = require("./change-handler");
11
+ const descriptor_change_handler_1 = require("./descriptor-change-handler");
11
12
  /**
12
13
  * Instance of an adaptation project handling requests and data transformation.
13
14
  */
@@ -218,6 +219,9 @@ class AdpPreview {
218
219
  if ((0, change_handler_1.isAddAnnotationChange)(change)) {
219
220
  await (0, change_handler_1.addAnnotationFile)(this.util.getProject().getSourcePath(), this.util.getProject().getRootPath(), change, fs, logger, this.provider);
220
221
  }
222
+ if ((0, change_handler_1.isV4DescriptorChange)(change)) {
223
+ (0, descriptor_change_handler_1.addCustomSectionFragment)(this.util.getProject().getSourcePath(), change, fs, logger);
224
+ }
221
225
  break;
222
226
  default:
223
227
  // no need to handle delete changes
@@ -1,7 +1,17 @@
1
1
  import type { Editor } from 'mem-fs-editor';
2
- import type { AddXMLChange, CommonChangeProperties, CodeExtChange, AnnotationFileChange, CommonAdditionalChangeInfoProperties } from '../types';
2
+ import type { AddXMLChange, CommonChangeProperties, CodeExtChange, AnnotationFileChange, CommonAdditionalChangeInfoProperties, AppDescriptorV4Change } from '../types';
3
3
  import type { Logger } from '@sap-ux/logger';
4
4
  import type { AbapServiceProvider } from '@sap-ux/axios-extension';
5
+ interface FragmentTemplateConfig<T = {
6
+ [key: string]: any;
7
+ }> {
8
+ /**
9
+ * Relative path to ../../templates/rta, includes template file name
10
+ */
11
+ path: string;
12
+ getData: (change: AddXMLChange) => T;
13
+ }
14
+ export declare const fragmentTemplateDefinitions: Record<string, FragmentTemplateConfig>;
5
15
  /**
6
16
  * A mapping object that defines how to extract change content data from changes based on their type.
7
17
  */
@@ -45,6 +55,14 @@ export declare function isCodeExtChange(change: CommonChangeProperties): change
45
55
  * indicating the change is of type `AnnotationFileChange`.
46
56
  */
47
57
  export declare function isAddAnnotationChange(change: CommonChangeProperties): change is AnnotationFileChange;
58
+ /**
59
+ * Determines whether a given change is of type `V4 Descriptor Change`.
60
+ *
61
+ * @param {CommonChangeProperties} change - The change object to check.
62
+ * @returns {boolean} `true` if the `changeType` is either 'appdescr_fe_changePageConfiguration',
63
+ * indicating the change is of type `V4 Descriptor Change`.
64
+ */
65
+ export declare function isV4DescriptorChange(change: CommonChangeProperties): change is AppDescriptorV4Change;
48
66
  /**
49
67
  * Asynchronously adds an XML fragment to the project if it doesn't already exist.
50
68
  *
@@ -76,4 +94,5 @@ export declare function addControllerExtension(rootPath: string, basePath: strin
76
94
  *@param {AbapServiceProvider} provider - abap provider.
77
95
  */
78
96
  export declare function addAnnotationFile(basePath: string, projectRoot: string, change: AnnotationFileChange, fs: Editor, logger: Logger, provider: AbapServiceProvider): Promise<void>;
97
+ export {};
79
98
  //# sourceMappingURL=change-handler.d.ts.map
@@ -1,10 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.moduleNameContentMap = void 0;
3
+ exports.moduleNameContentMap = exports.fragmentTemplateDefinitions = void 0;
4
4
  exports.tryFixChange = tryFixChange;
5
5
  exports.isAddXMLChange = isAddXMLChange;
6
6
  exports.isCodeExtChange = isCodeExtChange;
7
7
  exports.isAddAnnotationChange = isAddAnnotationChange;
8
+ exports.isV4DescriptorChange = isV4DescriptorChange;
8
9
  exports.addXmlFragment = addXmlFragment;
9
10
  exports.addControllerExtension = addControllerExtension;
10
11
  exports.addAnnotationFile = addAnnotationFile;
@@ -25,7 +26,7 @@ const V4_MDC_TABLE_COLUMN = 'V4_MDC_TABLE_COLUMN';
25
26
  const ANALYTICAL_TABLE_COLUMN = 'ANALYTICAL_TABLE_COLUMN';
26
27
  const GRID_TREE_TABLE_COLUMN = 'GRID_TREE_TABLE_COLUMN';
27
28
  const TABLE_ACTION = 'TABLE_ACTION';
28
- const fragmentTemplateDefinitions = {
29
+ exports.fragmentTemplateDefinitions = {
29
30
  [OBJECT_PAGE_CUSTOM_SECTION]: {
30
31
  path: 'common/op-custom-section.xml',
31
32
  getData: () => {
@@ -203,6 +204,16 @@ function isCodeExtChange(change) {
203
204
  function isAddAnnotationChange(change) {
204
205
  return change.changeType === 'appdescr_app_addAnnotationsToOData';
205
206
  }
207
+ /**
208
+ * Determines whether a given change is of type `V4 Descriptor Change`.
209
+ *
210
+ * @param {CommonChangeProperties} change - The change object to check.
211
+ * @returns {boolean} `true` if the `changeType` is either 'appdescr_fe_changePageConfiguration',
212
+ * indicating the change is of type `V4 Descriptor Change`.
213
+ */
214
+ function isV4DescriptorChange(change) {
215
+ return change.changeType === 'appdescr_fe_changePageConfiguration';
216
+ }
206
217
  /**
207
218
  * Asynchronously adds an XML fragment to the project if it doesn't already exist.
208
219
  *
@@ -215,7 +226,7 @@ function isAddAnnotationChange(change) {
215
226
  function addXmlFragment(basePath, change, fs, logger, additionalChangeInfo) {
216
227
  const { fragmentPath } = change.content;
217
228
  const fullPath = (0, path_1.join)(basePath, project_access_1.DirName.Changes, fragmentPath);
218
- const templateConfig = fragmentTemplateDefinitions[additionalChangeInfo?.templateName ?? ''];
229
+ const templateConfig = exports.fragmentTemplateDefinitions[additionalChangeInfo?.templateName ?? ''];
219
230
  try {
220
231
  if (templateConfig) {
221
232
  const fragmentTemplatePath = (0, path_1.join)(__dirname, '../../templates/rta', templateConfig.path);
@@ -0,0 +1,28 @@
1
+ import type { Editor } from 'mem-fs-editor';
2
+ import { type AppDescriptorV4Change } from '../types';
3
+ import type { Logger } from '@sap-ux/logger';
4
+ export declare const customFragmentConfig: {
5
+ path: string;
6
+ getData: () => {
7
+ ids: Record<string, string>;
8
+ };
9
+ };
10
+ /**
11
+ * Checks if the given object has a 'template' property of type string.
12
+ *
13
+ * @param obj - The object to check.
14
+ * @returns True if the object has a 'template' property of type string, false otherwise.
15
+ */
16
+ export declare function hasTemplate(obj: unknown): obj is {
17
+ template: string;
18
+ };
19
+ /**
20
+ * Adds a custom XML fragment file based on the provided AppDescriptorV4Change and template configuration.
21
+ *
22
+ * @param basePath - The base path where the fragment should be created.
23
+ * @param change - The AppDescriptorV4Change object containing change details.
24
+ * @param fs - The mem-fs-editor instance for file operations.
25
+ * @param logger - The logger instance for logging information and errors.
26
+ */
27
+ export declare function addCustomSectionFragment(basePath: string, change: AppDescriptorV4Change, fs: Editor, logger: Logger): void;
28
+ //# sourceMappingURL=descriptor-change-handler.d.ts.map
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.customFragmentConfig = void 0;
4
+ exports.hasTemplate = hasTemplate;
5
+ exports.addCustomSectionFragment = addCustomSectionFragment;
6
+ const path_1 = require("path");
7
+ const utils_1 = require("./utils");
8
+ const crypto_1 = require("crypto");
9
+ const ejs_1 = require("ejs");
10
+ exports.customFragmentConfig = {
11
+ path: 'v4/custom-section.xml',
12
+ getData: () => {
13
+ const uuid = (0, crypto_1.randomBytes)(4).toString('hex');
14
+ return {
15
+ ids: {
16
+ hBox: `hbox-${uuid}`
17
+ }
18
+ };
19
+ }
20
+ };
21
+ /**
22
+ * Checks if the given object has a 'template' property of type string.
23
+ *
24
+ * @param obj - The object to check.
25
+ * @returns True if the object has a 'template' property of type string, false otherwise.
26
+ */
27
+ function hasTemplate(obj) {
28
+ return typeof obj === 'object' && obj !== null && 'template' in obj && typeof obj.template === 'string';
29
+ }
30
+ /**
31
+ * Adds a custom XML fragment file based on the provided AppDescriptorV4Change and template configuration.
32
+ *
33
+ * @param basePath - The base path where the fragment should be created.
34
+ * @param change - The AppDescriptorV4Change object containing change details.
35
+ * @param fs - The mem-fs-editor instance for file operations.
36
+ * @param logger - The logger instance for logging information and errors.
37
+ */
38
+ function addCustomSectionFragment(basePath, change, fs, logger) {
39
+ const propertyValue = change.content.entityPropertyChange.propertyValue;
40
+ const isCustomSectionPropertyPath = change.content.entityPropertyChange.propertyPath.startsWith('content/body/sections/');
41
+ if (isCustomSectionPropertyPath && hasTemplate(propertyValue)) {
42
+ const { template } = propertyValue;
43
+ const path = (0, utils_1.getFragmentPathFromTemplate)(template, change);
44
+ try {
45
+ if (!path) {
46
+ throw new Error('Fragment Path could not be determined');
47
+ }
48
+ const fragmentPath = `${path}.fragment.xml`;
49
+ const fullPath = (0, path_1.join)(basePath, fragmentPath);
50
+ const fragmentTemplatePath = (0, path_1.join)(__dirname, '../../templates/rta', exports.customFragmentConfig.path);
51
+ const text = fs.read(fragmentTemplatePath);
52
+ const template = (0, ejs_1.render)(text, exports.customFragmentConfig.getData());
53
+ fs.write(fullPath, template);
54
+ logger.info(`XML Fragment "${fragmentPath}" was created`);
55
+ }
56
+ catch (error) {
57
+ logger.error(`Failed to create XML Fragment: ${error}`);
58
+ }
59
+ }
60
+ }
61
+ //# sourceMappingURL=descriptor-change-handler.js.map
@@ -0,0 +1,10 @@
1
+ import type { AppDescriptorV4Change } from '../types';
2
+ /**
3
+ * Generates the fragment path from the given template string and change object.
4
+ *
5
+ * @param template - The template string representing the fragment.
6
+ * @param change - The AppDescriptorV4Change object containing change details.
7
+ * @returns The computed fragment path as a string.
8
+ */
9
+ export declare function getFragmentPathFromTemplate(template: string, change: AppDescriptorV4Change): string | undefined;
10
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getFragmentPathFromTemplate = getFragmentPathFromTemplate;
4
+ const project_access_1 = require("@sap-ux/project-access");
5
+ const path_1 = require("path");
6
+ /**
7
+ * Generates the fragment path from the given template string and change object.
8
+ *
9
+ * @param template - The template string representing the fragment.
10
+ * @param change - The AppDescriptorV4Change object containing change details.
11
+ * @returns The computed fragment path as a string.
12
+ */
13
+ function getFragmentPathFromTemplate(template, change) {
14
+ const segments = template.split(`${change.projectId}.${project_access_1.DirName.Changes}.${project_access_1.DirName.Fragments}.`);
15
+ const [namespace, fileName] = segments;
16
+ if (segments.length === 2 && namespace === '') {
17
+ return (0, path_1.join)(project_access_1.DirName.Changes, project_access_1.DirName.Fragments, fileName);
18
+ }
19
+ return undefined;
20
+ }
21
+ //# sourceMappingURL=utils.js.map
package/dist/types.d.ts CHANGED
@@ -260,6 +260,16 @@ export interface AddXMLChange extends CommonChangeProperties {
260
260
  dependentSelector: Record<string, unknown>;
261
261
  jsOnly: boolean;
262
262
  }
263
+ export interface AppDescriptorV4Change<T = unknown> extends CommonChangeProperties {
264
+ changeType: 'appdescr_fe_changePageConfiguration';
265
+ content: {
266
+ entityPropertyChange: {
267
+ propertyPath: string;
268
+ operation: string;
269
+ propertyValue: string | boolean | number | T;
270
+ };
271
+ };
272
+ }
263
273
  export interface CodeExtChange extends CommonChangeProperties {
264
274
  changeType: 'codeExt';
265
275
  content: {
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "bugs": {
10
10
  "url": "https://github.com/SAP/open-ux-tools/issues?q=is%3Aopen+is%3Aissue+label%3Abug+label%3Aadp-tooling"
11
11
  },
12
- "version": "0.14.34",
12
+ "version": "0.14.35",
13
13
  "license": "Apache-2.0",
14
14
  "author": "@SAP/ux-tools-team",
15
15
  "main": "dist/index.js",
@@ -6,7 +6,7 @@
6
6
  >
7
7
  <uxap:ObjectPageSection
8
8
  id="<%- ids.objectPageSection %>"
9
- title="New custom section"
9
+ title="New Custom Section"
10
10
  >
11
11
  <uxap:ObjectPageSubSection id="<%- ids.objectPageSubSection %>">
12
12
  <HBox id="<%- ids.hBox %>">
@@ -0,0 +1,9 @@
1
+ <!-- Use stable and unique IDs!-->
2
+ <core:FragmentDefinition
3
+ xmlns:core='sap.ui.core'
4
+ xmlns='sap.m'
5
+ >
6
+ <HBox id="<%- ids.hBox %>">
7
+ <!-- add your xml here -->
8
+ </HBox>
9
+ </core:FragmentDefinition>