@sap-ux/preview-middleware 0.17.48 → 0.18.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.
@@ -139,7 +139,7 @@ export declare class FlpSandbox {
139
139
  /**
140
140
  * Read the sandbox template file based on the given UI5 version.
141
141
  *
142
- * @param ui5MajorVersion - the major version of UI5
142
+ * @param ui5Version - the UI5 version
143
143
  * @returns the template for the sandbox HTML file
144
144
  */
145
145
  private getSandboxTemplate;
package/dist/base/flp.js CHANGED
@@ -160,7 +160,7 @@ class FlpSandbox {
160
160
  if (ui5Version.major === 1 && ui5Version.minor <= 71) {
161
161
  this.removeAsyncHintsRequests();
162
162
  }
163
- return (0, ejs_1.render)(this.getSandboxTemplate(ui5Version.major), config);
163
+ return (0, ejs_1.render)(this.getSandboxTemplate(ui5Version), config);
164
164
  }
165
165
  /**
166
166
  * Sets application dependencies in the template configuration.
@@ -291,7 +291,7 @@ class FlpSandbox {
291
291
  'protocol' in req
292
292
  ? req.protocol
293
293
  : req.headers.referer?.substring(0, req.headers.referer.indexOf(':')) ?? 'http', req.headers.host, 'ui5-patched-router' in req ? req['ui5-patched-router']?.baseUrl : undefined);
294
- const html = (0, ejs_1.render)(this.getSandboxTemplate(ui5Version.major), this.templateConfig);
294
+ const html = (0, ejs_1.render)(this.getSandboxTemplate(ui5Version), this.templateConfig);
295
295
  this.sendResponse(res, 'text/html', 200, html);
296
296
  }
297
297
  }
@@ -335,21 +335,25 @@ class FlpSandbox {
335
335
  this.logger.error('Could not get UI5 version of application. Using 1.121.0 as fallback.');
336
336
  version = '1.121.0';
337
337
  }
338
- const [major, minor] = version.split('.').map((versionPart) => parseInt(versionPart, 10));
338
+ const [major, minor, patch] = version.split('.').map((versionPart) => parseInt(versionPart, 10));
339
+ const label = version.split(/-(.*)/s)?.[1];
339
340
  return {
340
341
  major,
341
- minor
342
+ minor,
343
+ patch,
344
+ label
342
345
  };
343
346
  }
344
347
  /**
345
348
  * Read the sandbox template file based on the given UI5 version.
346
349
  *
347
- * @param ui5MajorVersion - the major version of UI5
350
+ * @param ui5Version - the UI5 version
348
351
  * @returns the template for the sandbox HTML file
349
352
  */
350
- getSandboxTemplate(ui5MajorVersion) {
351
- this.logger.info(`Using sandbox template for UI5 major version ${ui5MajorVersion}.`);
352
- return (0, fs_1.readFileSync)((0, path_1.join)(__dirname, `../../templates/flp/sandbox${ui5MajorVersion === 1 ? '' : ui5MajorVersion}.html`), 'utf-8');
353
+ getSandboxTemplate(ui5Version) {
354
+ this.logger.info(`Using sandbox template for UI5 version ${ui5Version.major}.${ui5Version.minor}.${ui5Version.patch}${ui5Version.label ? `-${ui5Version.label}` : ''}.`);
355
+ const filePrefix = ui5Version.major > 1 || ui5Version.label?.includes('legacy-free') ? '2' : '';
356
+ return (0, fs_1.readFileSync)((0, path_1.join)(__dirname, `../../templates/flp/sandbox${filePrefix}.html`), 'utf-8');
353
357
  }
354
358
  /**
355
359
  * For UI5 version 1.71 and below, the asyncHints.requests need to be removed from the template configuration
@@ -32,6 +32,7 @@ export interface CodeExtResponse {
32
32
  controllerPath: string;
33
33
  controllerPathFromRoot: string;
34
34
  isRunningInBAS: boolean;
35
+ isTsSupported: boolean;
35
36
  }
36
37
 
37
38
  export interface AnnotationFileDetails {
@@ -10,7 +10,6 @@ sap.ui.define(["sap/m/MessageToast", "sap/ui/core/library", "sap/ui/model/json/J
10
10
  const ValueState = sap_ui_core_library["ValueState"];
11
11
  /** sap.ui.base */
12
12
  const getExistingController = ___api_handler["getExistingController"];
13
- const getManifestAppdescr = ___api_handler["getManifestAppdescr"];
14
13
  const readControllers = ___api_handler["readControllers"];
15
14
  const writeChange = ___api_handler["writeChange"];
16
15
  const writeController = ___api_handler["writeController"];
@@ -104,18 +103,12 @@ sap.ui.define(["sap/m/MessageToast", "sap/ui/core/library", "sap/ui/model/json/J
104
103
  controllerName,
105
104
  viewId
106
105
  } = getControllerInfo(overlayControl);
107
- const existingController = await this.getExistingController(controllerName);
108
- if (existingController) {
109
- const {
110
- controllerExists,
111
- controllerPath,
112
- controllerPathFromRoot,
113
- isRunningInBAS
114
- } = existingController;
115
- if (controllerExists) {
116
- this.updateModelForExistingController(controllerExists, controllerPath, controllerPathFromRoot, isRunningInBAS);
106
+ const data = await this.getExistingController(controllerName);
107
+ if (data) {
108
+ if (data?.controllerExists) {
109
+ this.updateModelForExistingController(data);
117
110
  } else {
118
- this.updateModelForNewController(viewId);
111
+ this.updateModelForNewController(viewId, data.isTsSupported);
119
112
  await this.getControllers();
120
113
  }
121
114
  }
@@ -123,12 +116,15 @@ sap.ui.define(["sap/m/MessageToast", "sap/ui/core/library", "sap/ui/model/json/J
123
116
  /**
124
117
  * Updates the model properties for an existing controller.
125
118
  *
126
- * @param {boolean} controllerExists - Whether the controller exists.
127
- * @param {string} controllerPath - The controller path.
128
- * @param {string} controllerPathFromRoot - The controller path from the project root.
129
- * @param {boolean} isRunningInBAS - Whether the environment is BAS or VS Code.
119
+ * @param {CodeExtResponse} data - Existing controller data from the server.
130
120
  */
131
- updateModelForExistingController: function _updateModelForExistingController(controllerExists, controllerPath, controllerPathFromRoot, isRunningInBAS) {
121
+ updateModelForExistingController: function _updateModelForExistingController(data) {
122
+ const {
123
+ controllerExists,
124
+ controllerPath,
125
+ controllerPathFromRoot,
126
+ isRunningInBAS
127
+ } = data;
132
128
  this.model.setProperty('/controllerExists', controllerExists);
133
129
  this.model.setProperty('/controllerPath', controllerPath);
134
130
  this.model.setProperty('/controllerPathFromRoot', controllerPathFromRoot);
@@ -147,16 +143,18 @@ sap.ui.define(["sap/m/MessageToast", "sap/ui/core/library", "sap/ui/model/json/J
147
143
  /**
148
144
  * Updates the model property for a new controller.
149
145
  *
150
- * @param viewId The view ID
146
+ * @param {string} viewId - The view ID.
147
+ * @param {boolean} isTsSupported - Whether TypeScript supported for the current project.
151
148
  */
152
- updateModelForNewController: function _updateModelForNewController(viewId) {
149
+ updateModelForNewController: function _updateModelForNewController(viewId, isTsSupported) {
153
150
  this.model.setProperty('/viewId', viewId);
151
+ this.model.setProperty('/controllerExtension', isTsSupported ? '.ts' : '.js');
154
152
  },
155
153
  /**
156
154
  * Retrieves existing controller data if found in the project's workspace.
157
155
  *
158
- * @param controllerName Controller name that exists in the view
159
- * @returns Returnsexisting controller data
156
+ * @param controllerName Controller name that exists in the view.
157
+ * @returns Returns existing controller data.
160
158
  */
161
159
  getExistingController: async function _getExistingController(controllerName) {
162
160
  let data;
@@ -188,10 +186,8 @@ sap.ui.define(["sap/m/MessageToast", "sap/ui/core/library", "sap/ui/model/json/J
188
186
  */
189
187
  createNewController: async function _createNewController(controllerName, viewId) {
190
188
  try {
191
- const manifest = await getManifestAppdescr();
192
189
  await writeController({
193
- controllerName,
194
- projectId: manifest.id
190
+ controllerName
195
191
  });
196
192
  const controllerRef = {
197
193
  codeRef: `coding/${controllerName}.js`,
@@ -24,13 +24,7 @@ import type SimpleForm from 'sap/ui/layout/form/SimpleForm';
24
24
  import type ElementOverlay from 'sap/ui/dt/ElementOverlay';
25
25
 
26
26
  import type { CodeExtResponse, ControllersResponse } from '../api-handler';
27
- import {
28
- getExistingController,
29
- getManifestAppdescr,
30
- readControllers,
31
- writeChange,
32
- writeController
33
- } from '../api-handler';
27
+ import { getExistingController, readControllers, writeChange, writeController } from '../api-handler';
34
28
  import BaseDialog from './BaseDialog.controller';
35
29
  import { getControllerInfo } from '../utils';
36
30
 
@@ -44,6 +38,7 @@ type ControllerModel = JSONModel & {
44
38
  getProperty(sPath: '/newControllerName'): string;
45
39
  getProperty(sPath: '/viewId'): string;
46
40
  getProperty(sPath: '/controllerPath'): string;
41
+ getProperty(sPath: '/controllerExtension'): string;
47
42
  };
48
43
 
49
44
  /**
@@ -158,20 +153,13 @@ export default class ControllerExtension extends BaseDialog<ControllerModel> {
158
153
  const overlayControl = sap.ui.getCore().byId(selectorId) as unknown as ElementOverlay;
159
154
 
160
155
  const { controllerName, viewId } = getControllerInfo(overlayControl);
161
- const existingController = await this.getExistingController(controllerName);
162
-
163
- if (existingController) {
164
- const { controllerExists, controllerPath, controllerPathFromRoot, isRunningInBAS } = existingController;
165
-
166
- if (controllerExists) {
167
- this.updateModelForExistingController(
168
- controllerExists,
169
- controllerPath,
170
- controllerPathFromRoot,
171
- isRunningInBAS
172
- );
156
+ const data = await this.getExistingController(controllerName);
157
+
158
+ if (data) {
159
+ if (data?.controllerExists) {
160
+ this.updateModelForExistingController(data);
173
161
  } else {
174
- this.updateModelForNewController(viewId);
162
+ this.updateModelForNewController(viewId, data.isTsSupported);
175
163
 
176
164
  await this.getControllers();
177
165
  }
@@ -180,17 +168,11 @@ export default class ControllerExtension extends BaseDialog<ControllerModel> {
180
168
  /**
181
169
  * Updates the model properties for an existing controller.
182
170
  *
183
- * @param {boolean} controllerExists - Whether the controller exists.
184
- * @param {string} controllerPath - The controller path.
185
- * @param {string} controllerPathFromRoot - The controller path from the project root.
186
- * @param {boolean} isRunningInBAS - Whether the environment is BAS or VS Code.
171
+ * @param {CodeExtResponse} data - Existing controller data from the server.
187
172
  */
188
- private updateModelForExistingController(
189
- controllerExists: boolean,
190
- controllerPath: string,
191
- controllerPathFromRoot: string,
192
- isRunningInBAS: boolean
193
- ): void {
173
+ private updateModelForExistingController(data: CodeExtResponse): void {
174
+ const { controllerExists, controllerPath, controllerPathFromRoot, isRunningInBAS } = data;
175
+
194
176
  this.model.setProperty('/controllerExists', controllerExists);
195
177
  this.model.setProperty('/controllerPath', controllerPath);
196
178
  this.model.setProperty('/controllerPathFromRoot', controllerPathFromRoot);
@@ -214,17 +196,19 @@ export default class ControllerExtension extends BaseDialog<ControllerModel> {
214
196
  /**
215
197
  * Updates the model property for a new controller.
216
198
  *
217
- * @param viewId The view ID
199
+ * @param {string} viewId - The view ID.
200
+ * @param {boolean} isTsSupported - Whether TypeScript supported for the current project.
218
201
  */
219
- private updateModelForNewController(viewId: string): void {
202
+ private updateModelForNewController(viewId: string, isTsSupported: boolean): void {
220
203
  this.model.setProperty('/viewId', viewId);
204
+ this.model.setProperty('/controllerExtension', isTsSupported ? '.ts' : '.js');
221
205
  }
222
206
 
223
207
  /**
224
208
  * Retrieves existing controller data if found in the project's workspace.
225
209
  *
226
- * @param controllerName Controller name that exists in the view
227
- * @returns Returnsexisting controller data
210
+ * @param controllerName Controller name that exists in the view.
211
+ * @returns Returns existing controller data.
228
212
  */
229
213
  private async getExistingController(controllerName: string): Promise<CodeExtResponse | undefined> {
230
214
  let data: CodeExtResponse | undefined;
@@ -257,8 +241,7 @@ export default class ControllerExtension extends BaseDialog<ControllerModel> {
257
241
  */
258
242
  private async createNewController(controllerName: string, viewId: string): Promise<void> {
259
243
  try {
260
- const manifest = await getManifestAppdescr();
261
- await writeController({ controllerName, projectId: manifest.id });
244
+ await writeController({ controllerName });
262
245
 
263
246
  const controllerRef = {
264
247
  codeRef: `coding/${controllerName}.js`,
@@ -16,8 +16,8 @@
16
16
  <Label text="Controller Name" />
17
17
  <Input
18
18
  id="controllerName"
19
- description=".js"
20
- value="{/newControllerName}"
19
+ description="{/controllerExtension}"
20
+ value="{/newControllerName}"
21
21
  liveChange="onControllerNameInputChange">
22
22
  </Input>
23
23
  </f:content>
@@ -41,10 +41,12 @@ sap.ui.define(["sap/ui/VersionInfo", "sap/base/Log"], function (VersionInfo, Log
41
41
  version = '1.121.0';
42
42
  }
43
43
  const [major, minor, patch] = version.split('.').map(versionPart => parseInt(versionPart, 10));
44
+ const label = version.split(/-(.*)/s)?.[1];
44
45
  return {
45
- major: major,
46
- minor: minor,
47
- patch: patch
46
+ major,
47
+ minor,
48
+ patch,
49
+ label
48
50
  };
49
51
  }
50
52
 
@@ -12,6 +12,7 @@ export type Ui5VersionInfo = {
12
12
  major: number;
13
13
  minor: number;
14
14
  patch?: number;
15
+ label?: string;
15
16
  };
16
17
 
17
18
  /**
@@ -51,11 +52,13 @@ export async function getUi5Version(library: string = 'sap.ui.core'): Promise<Ui
51
52
  version = '1.121.0';
52
53
  }
53
54
  const [major, minor, patch] = version.split('.').map((versionPart) => parseInt(versionPart, 10));
55
+ const label = version.split(/-(.*)/s)?.[1];
54
56
 
55
57
  return {
56
- major: major,
57
- minor: minor,
58
- patch: patch
58
+ major,
59
+ minor,
60
+ patch,
61
+ label
59
62
  } satisfies Ui5VersionInfo;
60
63
  }
61
64
 
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.17.48",
12
+ "version": "0.18.1",
13
13
  "license": "Apache-2.0",
14
14
  "author": "@SAP/ux-tools-team",
15
15
  "main": "dist/index.js",
@@ -28,9 +28,9 @@
28
28
  "@sap-ux/logger": "0.6.0",
29
29
  "@sap-ux/feature-toggle": "0.2.3",
30
30
  "@sap-ux/btp-utils": "1.0.1",
31
- "@sap-ux/adp-tooling": "0.12.138",
31
+ "@sap-ux/adp-tooling": "0.13.1",
32
32
  "@sap-ux/control-property-editor-sources": "npm:@sap-ux/control-property-editor@0.5.37",
33
- "@sap-ux/project-access": "1.29.8"
33
+ "@sap-ux/project-access": "1.29.9"
34
34
  },
35
35
  "devDependencies": {
36
36
  "connect": "^3.7.0",
@@ -48,7 +48,7 @@
48
48
  "supertest": "6.3.3",
49
49
  "@sap-ux-private/playwright": "0.1.0",
50
50
  "dotenv": "16.3.1",
51
- "@private/preview-middleware-client": "npm:@sap-ux-private/preview-middleware-client@0.11.69",
51
+ "@private/preview-middleware-client": "npm:@sap-ux-private/preview-middleware-client@0.12.1",
52
52
  "@sap-ux/axios-extension": "1.18.6",
53
53
  "@sap-ux/store": "1.0.0",
54
54
  "@sap-ux/ui5-info": "0.8.3",