@sap-ux/preview-middleware 0.3.9 → 0.4.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,8 +1,15 @@
1
1
  import type { ReaderCollection } from '@ui5/fs';
2
+ import type { Router } from 'express';
2
3
  import type { App, FlpConfig } from '../types';
3
4
  import type { Logger } from '@sap-ux/logger';
4
5
  import type { MiddlewareUtils } from '@ui5/server';
5
6
  import type { Manifest, UI5FlexLayer } from '@sap-ux/project-access';
7
+ /**
8
+ * Enhanced request handler that exposes a list of endpoints for the cds-plugin-ui5.
9
+ */
10
+ export type EnhancedRouter = Router & {
11
+ getAppPages?: () => string[];
12
+ };
6
13
  /**
7
14
  * Internal structure used to fill the sandbox.html template
8
15
  */
@@ -40,7 +47,7 @@ export declare class FlpSandbox {
40
47
  private readonly logger;
41
48
  protected templateConfig: TemplateConfig;
42
49
  readonly config: FlpConfig;
43
- readonly router: any;
50
+ readonly router: EnhancedRouter;
44
51
  /**
45
52
  * Constructor setting defaults and keeping reference to workspace resources.
46
53
  *
package/dist/base/flp.js CHANGED
@@ -106,7 +106,7 @@ class FlpSandbox {
106
106
  */
107
107
  addStandardRoutes() {
108
108
  // add route for the sandbox.html
109
- this.router.get(this.config.path, (req, res) => {
109
+ this.router.get(this.config.path, ((req, res) => __awaiter(this, void 0, void 0, function* () {
110
110
  var _a, _b;
111
111
  const config = Object.assign({}, this.templateConfig);
112
112
  const fioriToolsRtaMode = req.query['fiori-tools-rta-mode'];
@@ -121,6 +121,11 @@ class FlpSandbox {
121
121
  this.logger.error('Fiori tools RTA mode could not be started because the RTA layer is missing.');
122
122
  }
123
123
  }
124
+ // warn the user if a file with the same name exists in the filesystem
125
+ const file = yield this.project.byPath(this.config.path);
126
+ if (file) {
127
+ this.logger.warn(`HTML file returned at ${this.config.path} is NOT loaded from the file system.`);
128
+ }
124
129
  const template = (0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../../templates/flp/sandbox.html'), 'utf-8');
125
130
  const html = (0, ejs_1.render)(template, config);
126
131
  // if livereload is enabled, don't send it but let other middleware modify the content
@@ -131,7 +136,7 @@ class FlpSandbox {
131
136
  else {
132
137
  res.status(200).contentType('html').send(html);
133
138
  }
134
- });
139
+ })));
135
140
  // add route for locate-reuse-libs if requested
136
141
  if (this.config.libs && this.templateConfig.locateReuseLibsScript) {
137
142
  const pathParts = this.config.path.split('/');
@@ -186,12 +191,12 @@ class FlpSandbox {
186
191
  });
187
192
  const api = '/preview/api/changes';
188
193
  this.router.use(api, (0, express_1.json)());
189
- this.router.get(api, (_req, res) => __awaiter(this, void 0, void 0, function* () {
194
+ this.router.get(api, ((_req, res) => __awaiter(this, void 0, void 0, function* () {
190
195
  res.status(200)
191
196
  .contentType('application/json')
192
197
  .send(yield (0, flex_1.readChanges)(this.project, this.logger));
193
- }));
194
- this.router.post(api, (req, res) => __awaiter(this, void 0, void 0, function* () {
198
+ })));
199
+ this.router.post(api, ((req, res) => __awaiter(this, void 0, void 0, function* () {
195
200
  try {
196
201
  const { success, message } = (0, flex_1.writeChange)(req.body, this.utils.getProject().getSourcePath(), this.logger);
197
202
  if (success) {
@@ -204,8 +209,8 @@ class FlpSandbox {
204
209
  catch (error) {
205
210
  res.status(500).send(error.message);
206
211
  }
207
- }));
208
- this.router.delete(api, (req, res) => __awaiter(this, void 0, void 0, function* () {
212
+ })));
213
+ this.router.delete(api, ((req, res) => __awaiter(this, void 0, void 0, function* () {
209
214
  try {
210
215
  const { success, message } = (0, flex_1.deleteChange)(req.body, this.utils.getProject().getSourcePath(), this.logger);
211
216
  if (success) {
@@ -218,7 +223,7 @@ class FlpSandbox {
218
223
  catch (error) {
219
224
  res.status(500).send(error.message);
220
225
  }
221
- }));
226
+ })));
222
227
  return [
223
228
  {
224
229
  applyConnector: workspaceConnectorPath,
@@ -24,7 +24,7 @@ export interface App {
24
24
  */
25
25
  export interface FlpConfig {
26
26
  path: string;
27
- intent?: Intent;
27
+ intent: Intent;
28
28
  rta?: {
29
29
  layer?: UI5FlexLayer;
30
30
  };
@@ -22,10 +22,10 @@ const adp_tooling_1 = require("@sap-ux/adp-tooling");
22
22
  */
23
23
  function initAdp(rootProject, config, flp, logger) {
24
24
  return __awaiter(this, void 0, void 0, function* () {
25
- const files = yield rootProject.byGlob('/manifest.appdescr_variant');
26
- if (files.length === 1) {
25
+ const appVariant = yield rootProject.byPath('/manifest.appdescr_variant');
26
+ if (appVariant) {
27
27
  const adp = new adp_tooling_1.AdpPreview(config, rootProject, logger);
28
- const layer = yield adp.init(JSON.parse(yield files[0].getString()));
28
+ const layer = yield adp.init(JSON.parse(yield appVariant.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));
@@ -57,14 +57,16 @@ function createRouter({ resources, options, middlewareUtil }, logger) {
57
57
  yield initAdp(resources.rootProject, config.adp, flp, logger);
58
58
  }
59
59
  else {
60
- const files = yield resources.rootProject.byGlob('/manifest.json');
61
- if (files.length === 1) {
62
- yield flp.init(JSON.parse(yield files[0].getString()));
60
+ const manifest = yield resources.rootProject.byPath('/manifest.json');
61
+ if (manifest) {
62
+ yield flp.init(JSON.parse(yield manifest.getString()));
63
63
  }
64
64
  else {
65
65
  throw new Error('No manifest.json found.');
66
66
  }
67
67
  }
68
+ // add exposed endpoints for cds-plugin-ui5
69
+ flp.router.getAppPages = () => [`${flp.config.path}#${flp.config.intent.object}-${flp.config.intent.action}`];
68
70
  return flp.router;
69
71
  });
70
72
  }
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.9",
12
+ "version": "0.4.1",
13
13
  "license": "Apache-2.0",
14
14
  "author": "@SAP/ux-tools-team",
15
15
  "main": "dist/index.js",
@@ -34,7 +34,7 @@
34
34
  "express": "4.18.2",
35
35
  "nock": "13.2.1",
36
36
  "supertest": "6.3.2",
37
- "@sap-ux/project-access": "1.13.0",
37
+ "@sap-ux/project-access": "1.13.1",
38
38
  "@sap-ux/store": "0.3.12"
39
39
  },
40
40
  "peerDependencies": {