@sap-ux/preview-middleware 0.3.0 → 0.3.1

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.
@@ -1,5 +1,18 @@
1
1
  import type { Logger } from '@sap-ux/logger';
2
2
  import type { ReaderCollection } from '@ui5/fs';
3
+ /**
4
+ * Structure of a flex change.
5
+ */
6
+ export interface FlexChange {
7
+ [key: string]: string | object | undefined;
8
+ changeType: string;
9
+ reference: string;
10
+ moduleName?: string;
11
+ content?: {
12
+ codeRef?: string;
13
+ fragmentPath?: string;
14
+ };
15
+ }
3
16
  /**
4
17
  * Read changes from the file system and return them.
5
18
  *
@@ -7,7 +20,7 @@ import type { ReaderCollection } from '@ui5/fs';
7
20
  * @param logger logger instance
8
21
  * @returns object with the file name as key and the file content as value
9
22
  */
10
- export declare function readChanges(project: ReaderCollection, logger: Logger): Promise<Record<string, unknown>>;
23
+ export declare function readChanges(project: ReaderCollection, logger: Logger): Promise<Record<string, FlexChange>>;
11
24
  /**
12
25
  * Writes flex changes to the user's workspace.
13
26
  *
package/dist/base/flex.js CHANGED
@@ -12,6 +12,28 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.deleteChange = exports.writeChange = exports.readChanges = void 0;
13
13
  const fs_1 = require("fs");
14
14
  const path_1 = require("path");
15
+ /**
16
+ * Map of change type specific correction functions.
17
+ */
18
+ const moduleNameContentMap = {
19
+ codeExt: (change) => { var _a, _b; return ((_b = (_a = change.content) === null || _a === void 0 ? void 0 : _a.codeRef) !== null && _b !== void 0 ? _b : '').replace('.js', ''); },
20
+ addXML: (change) => { var _a, _b; return (_b = (_a = change.content) === null || _a === void 0 ? void 0 : _a.fragmentPath) !== null && _b !== void 0 ? _b : ''; }
21
+ };
22
+ /**
23
+ * Sets the moduleName property of the provided change to also support old changes with newer UI5 versions.
24
+ *
25
+ * @param change change to be fixed
26
+ * @param logger logger instance
27
+ */
28
+ function tryFixChange(change, logger) {
29
+ try {
30
+ const prefix = change.reference.replace(/\./g, '/');
31
+ change.moduleName = `${prefix}/changes/${moduleNameContentMap[change.changeType](change)}`;
32
+ }
33
+ catch (error) {
34
+ logger.warn('Could not fix missing module name.');
35
+ }
36
+ }
15
37
  /**
16
38
  * Read changes from the file system and return them.
17
39
  *
@@ -25,7 +47,11 @@ function readChanges(project, logger) {
25
47
  const files = yield project.byGlob('/**/changes/*.*');
26
48
  for (const file of files) {
27
49
  try {
28
- changes[`sap.ui.fl.${(0, path_1.parse)(file.getName()).name}`] = JSON.parse(yield file.getString());
50
+ const change = JSON.parse(yield file.getString());
51
+ if (moduleNameContentMap[change.changeType] && !change.moduleName) {
52
+ tryFixChange(change, logger);
53
+ }
54
+ changes[`sap.ui.fl.${(0, path_1.parse)(file.getName()).name}`] = change;
29
55
  logger.debug(`Read change from ${file.getPath()}`);
30
56
  }
31
57
  catch (error) {
@@ -1,5 +1,8 @@
1
1
  import type { AdpPreviewConfig } from '@sap-ux/adp-tooling';
2
2
  import type { UI5FlexLayer } from '@sap-ux/project-access';
3
+ /**
4
+ * Intent object consisting of an object and an action.
5
+ */
3
6
  interface Intent {
4
7
  object: string;
5
8
  action: string;
@@ -24,8 +24,8 @@ function initAdp(rootProject, config, flp, logger) {
24
24
  return __awaiter(this, void 0, void 0, function* () {
25
25
  const files = yield rootProject.byGlob('/manifest.appdescr_variant');
26
26
  if (files.length === 1) {
27
- const adp = new adp_tooling_1.AdpPreview(config, logger);
28
- const layer = yield adp.init(JSON.parse(yield files[0].getString()), yield rootProject.byGlob('**/*.*'));
27
+ const adp = new adp_tooling_1.AdpPreview(config, rootProject, logger);
28
+ const layer = yield adp.init(JSON.parse(yield files[0].getString()));
29
29
  flp.config.rta = { layer };
30
30
  yield flp.init(adp.descriptor.manifest, adp.descriptor.name, adp.resources);
31
31
  flp.router.use(adp.descriptor.url, adp.proxy.bind(adp));
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%3Apreview-middleware"
11
11
  },
12
- "version": "0.3.0",
12
+ "version": "0.3.1",
13
13
  "license": "Apache-2.0",
14
14
  "author": "@SAP/ux-tools-team",
15
15
  "main": "dist/index.js",
@@ -24,7 +24,7 @@
24
24
  "dependencies": {
25
25
  "ejs": "3.1.7",
26
26
  "@sap-ux/logger": "0.3.7",
27
- "@sap-ux/adp-tooling": "0.1.0"
27
+ "@sap-ux/adp-tooling": "0.1.1"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@types/ejs": "3.1.0",