@sap-ux/preview-middleware 0.15.8 → 0.16.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,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.generatePreviewFiles = exports.getPreviewPaths = exports.createTestTemplateConfig = exports.createFlpTemplateConfig = exports.addApp = exports.sanitizeConfig = exports.getFlpConfigWithDefaults = exports.DEFAULT_INTENT = exports.DEFAULT_PATH = exports.DEFAULT_THEME = exports.PREVIEW_URL = void 0;
13
4
  const logger_1 = require("@sap-ux/logger");
@@ -78,8 +69,7 @@ const UI5_LIBS = [
78
69
  * @returns UI5 libs that should preloaded
79
70
  */
80
71
  function getUI5Libs(manifest) {
81
- var _a, _b, _c;
82
- const libs = (_c = (_b = (_a = manifest['sap.ui5']) === null || _a === void 0 ? void 0 : _a.dependencies) === null || _b === void 0 ? void 0 : _b.libs) !== null && _c !== void 0 ? _c : {};
72
+ const libs = manifest['sap.ui5']?.dependencies?.libs ?? {};
83
73
  // add libs that should always be preloaded
84
74
  libs['sap.m'] = {};
85
75
  libs['sap.ui.core'] = {};
@@ -99,11 +89,10 @@ function getUI5Libs(manifest) {
99
89
  * @returns a full configuration with default values
100
90
  */
101
91
  function getFlpConfigWithDefaults(config = {}) {
102
- var _a, _b, _c;
103
92
  const flpConfig = {
104
- path: (_a = config.path) !== null && _a !== void 0 ? _a : exports.DEFAULT_PATH,
105
- intent: (_b = config.intent) !== null && _b !== void 0 ? _b : exports.DEFAULT_INTENT,
106
- apps: (_c = config.apps) !== null && _c !== void 0 ? _c : [],
93
+ path: config.path ?? exports.DEFAULT_PATH,
94
+ intent: config.intent ?? exports.DEFAULT_INTENT,
95
+ apps: config.apps ?? [],
107
96
  libs: config.libs,
108
97
  theme: config.theme,
109
98
  init: config.init
@@ -161,24 +150,21 @@ function getFlexSettings() {
161
150
  * @param app configuration for the preview
162
151
  * @param logger logger instance
163
152
  */
164
- function addApp(templateConfig, manifest, app, logger) {
165
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
166
- return __awaiter(this, void 0, void 0, function* () {
167
- const id = (_b = (_a = manifest['sap.app']) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : '';
168
- (_c = app.intent) !== null && _c !== void 0 ? _c : (app.intent = {
169
- object: id.replace(/\./g, ''),
170
- action: 'preview'
171
- });
172
- templateConfig.ui5.resources[id] = app.target;
173
- templateConfig.apps[`${(_d = app.intent) === null || _d === void 0 ? void 0 : _d.object}-${(_e = app.intent) === null || _e === void 0 ? void 0 : _e.action}`] = {
174
- title: (_g = (yield getI18nTextFromProperty(app.local, (_f = manifest['sap.app']) === null || _f === void 0 ? void 0 : _f.title, logger))) !== null && _g !== void 0 ? _g : id,
175
- description: (_j = (yield getI18nTextFromProperty(app.local, (_h = manifest['sap.app']) === null || _h === void 0 ? void 0 : _h.description, logger))) !== null && _j !== void 0 ? _j : '',
176
- additionalInformation: `SAPUI5.Component=${(_k = app.componentId) !== null && _k !== void 0 ? _k : id}`,
177
- applicationType: 'URL',
178
- url: app.target,
179
- applicationDependencies: { manifest: true }
180
- };
181
- });
153
+ async function addApp(templateConfig, manifest, app, logger) {
154
+ const id = manifest['sap.app']?.id ?? '';
155
+ app.intent ??= {
156
+ object: id.replace(/\./g, ''),
157
+ action: 'preview'
158
+ };
159
+ templateConfig.ui5.resources[id] = app.target;
160
+ templateConfig.apps[`${app.intent?.object}-${app.intent?.action}`] = {
161
+ title: (await getI18nTextFromProperty(app.local, manifest['sap.app']?.title, logger)) ?? id,
162
+ description: (await getI18nTextFromProperty(app.local, manifest['sap.app']?.description, logger)) ?? '',
163
+ additionalInformation: `SAPUI5.Component=${app.componentId ?? id}`,
164
+ applicationType: 'URL',
165
+ url: app.target,
166
+ applicationDependencies: { manifest: true }
167
+ };
182
168
  }
183
169
  exports.addApp = addApp;
184
170
  /**
@@ -189,24 +175,21 @@ exports.addApp = addApp;
189
175
  * @param logger logger instance
190
176
  * @returns i18n text of the property
191
177
  */
192
- function getI18nTextFromProperty(projectRoot, propertyValue, logger) {
193
- var _a, _b, _c, _d;
194
- return __awaiter(this, void 0, void 0, function* () {
195
- //i18n model format could be {{key}} or {i18n>key}
196
- if (!projectRoot || !propertyValue || propertyValue.search(/{{\w+}}|{i18n>\w+}/g) === -1) {
197
- return propertyValue;
198
- }
199
- const propertyI18nKey = propertyValue.replace(/i18n>|[{}]/g, '');
200
- const projectAccess = yield (0, project_access_1.createProjectAccess)(projectRoot);
201
- try {
202
- const bundle = (yield projectAccess.getApplication('').getI18nBundles())['sap.app'];
203
- return (_d = (_c = (_b = (_a = bundle[propertyI18nKey]) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.value) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : propertyI18nKey;
204
- }
205
- catch (e) {
206
- logger.warn('Failed to load i18n properties bundle');
207
- }
208
- return propertyI18nKey;
209
- });
178
+ async function getI18nTextFromProperty(projectRoot, propertyValue, logger) {
179
+ //i18n model format could be {{key}} or {i18n>key}
180
+ if (!projectRoot || !propertyValue || propertyValue.search(/{{\w+}}|{i18n>\w+}/g) === -1) {
181
+ return propertyValue;
182
+ }
183
+ const propertyI18nKey = propertyValue.replace(/i18n>|[{}]/g, '');
184
+ const projectAccess = await (0, project_access_1.createProjectAccess)(projectRoot);
185
+ try {
186
+ const bundle = (await projectAccess.getApplication('').getI18nBundles())['sap.app'];
187
+ return bundle[propertyI18nKey]?.[0]?.value?.value ?? propertyI18nKey;
188
+ }
189
+ catch (e) {
190
+ logger.warn('Failed to load i18n properties bundle');
191
+ }
192
+ return propertyI18nKey;
210
193
  }
211
194
  /**
212
195
  * Creates the configuration object for the sandbox.html template.
@@ -216,14 +199,13 @@ function getI18nTextFromProperty(projectRoot, propertyValue, logger) {
216
199
  * @returns configuration object for the sandbox.html template
217
200
  */
218
201
  function createFlpTemplateConfig(config, manifest) {
219
- var _a, _b, _c, _d, _e, _f;
220
202
  const flex = getFlexSettings();
221
- const supportedThemes = (_b = (_a = manifest['sap.ui5']) === null || _a === void 0 ? void 0 : _a.supportedThemes) !== null && _b !== void 0 ? _b : [exports.DEFAULT_THEME];
222
- const ui5Theme = (_c = config.theme) !== null && _c !== void 0 ? _c : (supportedThemes.includes(exports.DEFAULT_THEME) ? exports.DEFAULT_THEME : supportedThemes[0]);
223
- const id = (_e = (_d = manifest['sap.app']) === null || _d === void 0 ? void 0 : _d.id) !== null && _e !== void 0 ? _e : '';
203
+ const supportedThemes = manifest['sap.ui5']?.supportedThemes ?? [exports.DEFAULT_THEME];
204
+ const ui5Theme = config.theme ?? (supportedThemes.includes(exports.DEFAULT_THEME) ? exports.DEFAULT_THEME : supportedThemes[0]);
205
+ const id = manifest['sap.app']?.id ?? '';
224
206
  const ns = id.replace(/\./g, '/');
225
207
  return {
226
- basePath: (_f = path_1.posix.relative(path_1.posix.dirname(config.path), '/')) !== null && _f !== void 0 ? _f : '.',
208
+ basePath: path_1.posix.relative(path_1.posix.dirname(config.path), '/') ?? '.',
227
209
  apps: {},
228
210
  init: config.init ? ns + config.init : undefined,
229
211
  ui5: {
@@ -247,11 +229,10 @@ exports.createFlpTemplateConfig = createFlpTemplateConfig;
247
229
  * @returns configuration object for the test template
248
230
  */
249
231
  function createTestTemplateConfig(config, id) {
250
- var _a;
251
232
  return {
252
233
  id,
253
234
  framework: config.framework,
254
- basePath: (_a = path_1.posix.relative(path_1.posix.dirname(config.path), '/')) !== null && _a !== void 0 ? _a : '.',
235
+ basePath: path_1.posix.relative(path_1.posix.dirname(config.path), '/') ?? '.',
255
236
  initPath: path_1.posix.relative(path_1.posix.dirname(config.path), config.init)
256
237
  };
257
238
  }
@@ -264,7 +245,6 @@ exports.createTestTemplateConfig = createTestTemplateConfig;
264
245
  * @returns an array of preview paths
265
246
  */
266
247
  function getPreviewPaths(config, logger = new logger_1.ToolsLogger()) {
267
- var _a;
268
248
  const urls = [];
269
249
  // remove incorrect configurations
270
250
  sanitizeConfig(config, logger);
@@ -272,7 +252,7 @@ function getPreviewPaths(config, logger = new logger_1.ToolsLogger()) {
272
252
  const flpConfig = getFlpConfigWithDefaults(config.flp);
273
253
  urls.push({ path: `${flpConfig.path}#${flpConfig.intent.object}-${flpConfig.intent.action}`, type: 'preview' });
274
254
  // add editor urls
275
- if ((_a = config.rta) === null || _a === void 0 ? void 0 : _a.editors) {
255
+ if (config.rta?.editors) {
276
256
  config.rta.editors.forEach((editor) => {
277
257
  urls.push({ path: editor.path, type: 'editor' });
278
258
  });
@@ -298,7 +278,7 @@ const TEMPLATE_PATH = (0, path_1.join)(__dirname, '../../templates');
298
278
  * @param flpTemplConfig FLP configuration
299
279
  */
300
280
  function generateTestRunners(configs, manifest, fs, webappPath, flpTemplConfig) {
301
- for (const test of configs !== null && configs !== void 0 ? configs : []) {
281
+ for (const test of configs ?? []) {
302
282
  const testConfig = (0, test_1.mergeTestConfigDefaults)(test);
303
283
  if (['QUnit', 'OPA5'].includes(test.framework)) {
304
284
  const testTemlpate = (0, fs_1.readFileSync)((0, path_1.join)(TEMPLATE_PATH, 'test/qunit.html'), 'utf-8');
@@ -324,55 +304,53 @@ function generateTestRunners(configs, manifest, fs, webappPath, flpTemplConfig)
324
304
  * @param logger logger instance
325
305
  * @returns a mem-fs editor with the preview files
326
306
  */
327
- function generatePreviewFiles(basePath, config, fs, logger = new logger_1.ToolsLogger()) {
328
- return __awaiter(this, void 0, void 0, function* () {
329
- // remove incorrect configurations
330
- sanitizeConfig(config, logger);
331
- // create file system if not provided
332
- if (!fs) {
333
- fs = (0, mem_fs_editor_1.create)((0, mem_fs_1.create)());
334
- }
335
- // generate FLP configuration
336
- const flpTemplate = (0, fs_1.readFileSync)((0, path_1.join)(TEMPLATE_PATH, 'flp/sandbox.html'), 'utf-8');
337
- const flpConfig = getFlpConfigWithDefaults(config.flp);
338
- const webappPath = yield (0, project_access_1.getWebappPath)(basePath, fs);
339
- let manifest;
340
- if (fs.exists((0, path_1.join)(webappPath, 'manifest.json'))) {
341
- manifest = (yield fs.readJSON((0, path_1.join)(webappPath, 'manifest.json')));
342
- }
343
- let flpTemplConfig;
344
- let flpPath;
345
- if (manifest) {
346
- flpTemplConfig = createFlpTemplateConfig(flpConfig, manifest);
347
- flpPath = (0, path_1.join)(webappPath, flpConfig.path);
348
- yield addApp(flpTemplConfig, manifest, {
349
- target: flpTemplConfig.basePath,
350
- local: '.',
351
- intent: flpConfig.intent
352
- }, logger);
353
- generateTestRunners(config.test, manifest, fs, webappPath, flpTemplConfig);
354
- }
355
- else {
356
- flpTemplConfig = createFlpTemplateConfig(flpConfig, {});
357
- flpPath = (0, path_1.join)(basePath, flpConfig.path);
358
- }
359
- if (flpConfig.apps.length > 0) {
360
- for (const app of flpConfig.apps) {
361
- if (app.local) {
362
- const appPath = yield (0, project_access_1.getWebappPath)((0, path_1.join)(basePath, app.local), fs);
363
- if (fs.exists((0, path_1.join)(appPath, 'manifest.json'))) {
364
- const appManifest = (yield fs.readJSON((0, path_1.join)(appPath, 'manifest.json')));
365
- yield addApp(flpTemplConfig, appManifest, app, logger);
366
- }
367
- else {
368
- logger.warn(`Could not add route for ${app}`);
369
- }
307
+ async function generatePreviewFiles(basePath, config, fs, logger = new logger_1.ToolsLogger()) {
308
+ // remove incorrect configurations
309
+ sanitizeConfig(config, logger);
310
+ // create file system if not provided
311
+ if (!fs) {
312
+ fs = (0, mem_fs_editor_1.create)((0, mem_fs_1.create)());
313
+ }
314
+ // generate FLP configuration
315
+ const flpTemplate = (0, fs_1.readFileSync)((0, path_1.join)(TEMPLATE_PATH, 'flp/sandbox.html'), 'utf-8');
316
+ const flpConfig = getFlpConfigWithDefaults(config.flp);
317
+ const webappPath = await (0, project_access_1.getWebappPath)(basePath, fs);
318
+ let manifest;
319
+ if (fs.exists((0, path_1.join)(webappPath, 'manifest.json'))) {
320
+ manifest = (await fs.readJSON((0, path_1.join)(webappPath, 'manifest.json')));
321
+ }
322
+ let flpTemplConfig;
323
+ let flpPath;
324
+ if (manifest) {
325
+ flpTemplConfig = createFlpTemplateConfig(flpConfig, manifest);
326
+ flpPath = (0, path_1.join)(webappPath, flpConfig.path);
327
+ await addApp(flpTemplConfig, manifest, {
328
+ target: flpTemplConfig.basePath,
329
+ local: '.',
330
+ intent: flpConfig.intent
331
+ }, logger);
332
+ generateTestRunners(config.test, manifest, fs, webappPath, flpTemplConfig);
333
+ }
334
+ else {
335
+ flpTemplConfig = createFlpTemplateConfig(flpConfig, {});
336
+ flpPath = (0, path_1.join)(basePath, flpConfig.path);
337
+ }
338
+ if (flpConfig.apps.length > 0) {
339
+ for (const app of flpConfig.apps) {
340
+ if (app.local) {
341
+ const appPath = await (0, project_access_1.getWebappPath)((0, path_1.join)(basePath, app.local), fs);
342
+ if (fs.exists((0, path_1.join)(appPath, 'manifest.json'))) {
343
+ const appManifest = (await fs.readJSON((0, path_1.join)(appPath, 'manifest.json')));
344
+ await addApp(flpTemplConfig, appManifest, app, logger);
345
+ }
346
+ else {
347
+ logger.warn(`Could not add route for ${app}`);
370
348
  }
371
349
  }
372
350
  }
373
- fs.write(flpPath, (0, ejs_1.render)(flpTemplate, flpTemplConfig));
374
- return fs;
375
- });
351
+ }
352
+ fs.write(flpPath, (0, ejs_1.render)(flpTemplate, flpTemplConfig));
353
+ return fs;
376
354
  }
377
355
  exports.generatePreviewFiles = generatePreviewFiles;
378
356
  //# sourceMappingURL=config.js.map
package/dist/base/flex.js CHANGED
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.deleteChange = exports.writeChange = exports.readChanges = void 0;
13
4
  const fs_1 = require("fs");
@@ -19,22 +10,20 @@ const path_1 = require("path");
19
10
  * @param logger logger instance
20
11
  * @returns object with the file name as key and the file content as value
21
12
  */
22
- function readChanges(project, logger) {
23
- return __awaiter(this, void 0, void 0, function* () {
24
- const changes = {};
25
- const files = yield project.byGlob('/**/changes/*.*');
26
- for (const file of files) {
27
- try {
28
- const change = JSON.parse(yield file.getString());
29
- changes[`sap.ui.fl.${(0, path_1.parse)(file.getName()).name}`] = change;
30
- logger.debug(`Read change from ${file.getPath()}`);
31
- }
32
- catch (error) {
33
- logger.warn(error.message);
34
- }
13
+ async function readChanges(project, logger) {
14
+ const changes = {};
15
+ const files = await project.byGlob('/**/changes/*.*');
16
+ for (const file of files) {
17
+ try {
18
+ const change = JSON.parse(await file.getString());
19
+ changes[`sap.ui.fl.${(0, path_1.parse)(file.getName()).name}`] = change;
20
+ logger.debug(`Read change from ${file.getPath()}`);
35
21
  }
36
- return changes;
37
- });
22
+ catch (error) {
23
+ logger.warn(error.message);
24
+ }
25
+ }
26
+ return changes;
38
27
  }
39
28
  exports.readChanges = readChanges;
40
29
  /**
@@ -73,8 +62,7 @@ exports.writeChange = writeChange;
73
62
  * @returns object with success flag and optional message
74
63
  */
75
64
  function deleteChange(data, webappPath, logger) {
76
- var _a;
77
- const fileName = (_a = data.fileName) === null || _a === void 0 ? void 0 : _a.replace('sap.ui.fl.', '');
65
+ const fileName = data.fileName?.replace('sap.ui.fl.', '');
78
66
  if (fileName) {
79
67
  const path = (0, path_1.join)(webappPath, 'changes');
80
68
  if ((0, fs_1.existsSync)(path)) {
package/dist/base/flp.js CHANGED
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.initAdp = exports.FlpSandbox = void 0;
13
4
  const mem_fs_1 = require("mem-fs");
@@ -35,6 +26,15 @@ const DEFAULT_LIVERELOAD_PORT = 35729;
35
26
  * Class handling preview of a sandbox FLP.
36
27
  */
37
28
  class FlpSandbox {
29
+ project;
30
+ utils;
31
+ logger;
32
+ onChangeRequest;
33
+ templateConfig;
34
+ config;
35
+ rta;
36
+ test;
37
+ router;
38
38
  /**
39
39
  * Constructor setting defaults and keeping reference to workspace resources.
40
40
  *
@@ -68,35 +68,31 @@ class FlpSandbox {
68
68
  * @param componentId optional componentId e.g. for adaptation projects
69
69
  * @param resources optional additional resource mappings
70
70
  */
71
- init(manifest, componentId, resources = {}) {
72
- var _a, _b, _c;
73
- var _d, _e;
74
- return __awaiter(this, void 0, void 0, function* () {
75
- this.createFlexHandler();
76
- (_a = (_d = this.config).libs) !== null && _a !== void 0 ? _a : (_d.libs = yield this.hasLocateReuseLibsScript());
77
- const id = manifest['sap.app'].id;
78
- this.templateConfig = (0, config_1.createFlpTemplateConfig)(this.config, manifest);
79
- yield (0, config_1.addApp)(this.templateConfig, manifest, {
80
- componentId,
81
- target: (_b = resources[componentId !== null && componentId !== void 0 ? componentId : id]) !== null && _b !== void 0 ? _b : this.templateConfig.basePath,
82
- local: '.',
83
- intent: this.config.intent
84
- }, this.logger);
85
- this.addStandardRoutes();
86
- if (this.rta) {
87
- (_c = (_e = this.rta).options) !== null && _c !== void 0 ? _c : (_e.options = {});
88
- this.rta.options.baseId = componentId !== null && componentId !== void 0 ? componentId : id;
89
- this.rta.options.appName = id;
90
- this.addEditorRoutes(this.rta);
91
- }
92
- if (this.test) {
93
- this.addTestRoutes(this.test.filter((config) => config.framework !== 'Testsuite'), id);
94
- this.createTestSuite(this.test);
95
- }
96
- yield this.addRoutesForAdditionalApps();
97
- this.logger.info(`Initialized for app ${id}`);
98
- this.logger.debug(`Configured apps: ${JSON.stringify(this.templateConfig.apps)}`);
99
- });
71
+ async init(manifest, componentId, resources = {}) {
72
+ this.createFlexHandler();
73
+ this.config.libs ??= await this.hasLocateReuseLibsScript();
74
+ const id = manifest['sap.app'].id;
75
+ this.templateConfig = (0, config_1.createFlpTemplateConfig)(this.config, manifest);
76
+ await (0, config_1.addApp)(this.templateConfig, manifest, {
77
+ componentId,
78
+ target: resources[componentId ?? id] ?? this.templateConfig.basePath,
79
+ local: '.',
80
+ intent: this.config.intent
81
+ }, this.logger);
82
+ this.addStandardRoutes();
83
+ if (this.rta) {
84
+ this.rta.options ??= {};
85
+ this.rta.options.baseId = componentId ?? id;
86
+ this.rta.options.appName = id;
87
+ this.addEditorRoutes(this.rta);
88
+ }
89
+ if (this.test) {
90
+ this.addTestRoutes(this.test.filter((config) => config.framework !== 'Testsuite'), id);
91
+ this.createTestSuite(this.test);
92
+ }
93
+ await this.addRoutesForAdditionalApps();
94
+ this.logger.info(`Initialized for app ${id}`);
95
+ this.logger.debug(`Configured apps: ${JSON.stringify(this.templateConfig.apps)}`);
100
96
  }
101
97
  /**
102
98
  * Generates the FLP sandbox for an editor.
@@ -106,18 +102,23 @@ class FlpSandbox {
106
102
  * @returns FLP sandbox html
107
103
  */
108
104
  generateSandboxForEditor(rta, editor) {
109
- var _a;
110
105
  const defaultGenerator = editor.developerMode
111
106
  ? '@sap-ux/control-property-editor'
112
107
  : '@sap-ux/preview-middleware';
113
- const config = Object.assign({}, this.templateConfig);
108
+ const config = { ...this.templateConfig };
114
109
  /* sap.ui.rta needs to be added to the list of preload libs for variants management and adaptation projects */
115
110
  if (!config.ui5.libs.includes('sap.ui.rta')) {
116
111
  const libs = config.ui5.libs.split(',');
117
112
  libs.push('sap.ui.rta');
118
113
  config.ui5.libs = libs.join(',');
119
114
  }
120
- config.flex = Object.assign(Object.assign({ layer: rta.layer }, rta.options), { generator: (_a = editor.generator) !== null && _a !== void 0 ? _a : defaultGenerator, developerMode: editor.developerMode === true, pluginScript: editor.pluginScript });
115
+ config.flex = {
116
+ layer: rta.layer,
117
+ ...rta.options,
118
+ generator: editor.generator ?? defaultGenerator,
119
+ developerMode: editor.developerMode === true,
120
+ pluginScript: editor.pluginScript
121
+ };
121
122
  if (editor.developerMode === true) {
122
123
  config.ui5.bootstrapOptions = serializeUi5Configuration(DEVELOPER_MODE_CONFIG);
123
124
  }
@@ -130,16 +131,14 @@ class FlpSandbox {
130
131
  * @param rta runtime authoring configuration
131
132
  */
132
133
  addEditorRoutes(rta) {
133
- var _a;
134
134
  const cpe = (0, path_1.dirname)(require.resolve('@sap-ux/control-property-editor-sources'));
135
135
  for (const editor of rta.editors) {
136
136
  let previewUrl = editor.path;
137
137
  if (editor.developerMode) {
138
138
  previewUrl = `${previewUrl}.inner.html`;
139
- (_a = editor.pluginScript) !== null && _a !== void 0 ? _a : (editor.pluginScript = 'open/ux/preview/client/cpe/init');
140
- this.router.get(editor.path, (_req, res) => __awaiter(this, void 0, void 0, function* () {
141
- var _b, _c, _d, _e;
142
- const scenario = (_b = rta.options) === null || _b === void 0 ? void 0 : _b.scenario;
139
+ editor.pluginScript ??= 'open/ux/preview/client/cpe/init';
140
+ this.router.get(editor.path, async (_req, res) => {
141
+ const scenario = rta.options?.scenario;
143
142
  let templatePreviewUrl = `${previewUrl}?sap-ui-xx-viewCache=false&fiori-tools-rta-mode=forAdaptation&sap-ui-rta-skip-flex-validation=true&sap-ui-xx-condense-changes=true#${this.config.intent.object}-${this.config.intent.action}`;
144
143
  if (scenario === 'ADAPTATION_PROJECT') {
145
144
  templatePreviewUrl = templatePreviewUrl.replace('?', `?sap-ui-layer=${rta.layer}&`);
@@ -148,17 +147,17 @@ class FlpSandbox {
148
147
  const envPort = process.env.FIORI_TOOLS_LIVERELOAD_PORT;
149
148
  let livereloadPort = envPort ? parseInt(envPort, 10) : DEFAULT_LIVERELOAD_PORT;
150
149
  livereloadPort = isNaN(livereloadPort) ? DEFAULT_LIVERELOAD_PORT : livereloadPort;
151
- const envLivereloadUrl = (0, btp_utils_1.isAppStudio)() ? yield (0, btp_utils_1.exposePort)(livereloadPort) : undefined;
150
+ const envLivereloadUrl = (0, btp_utils_1.isAppStudio)() ? await (0, btp_utils_1.exposePort)(livereloadPort) : undefined;
152
151
  const html = (0, ejs_1.render)(template, {
153
152
  previewUrl: templatePreviewUrl,
154
- telemetry: (_d = (_c = rta.options) === null || _c === void 0 ? void 0 : _c.telemetry) !== null && _d !== void 0 ? _d : false,
155
- appName: (_e = rta.options) === null || _e === void 0 ? void 0 : _e.appName,
153
+ telemetry: rta.options?.telemetry ?? false,
154
+ appName: rta.options?.appName,
156
155
  scenario,
157
156
  livereloadPort,
158
157
  livereloadUrl: envLivereloadUrl
159
158
  });
160
159
  this.sendResponse(res, 'text/html', 200, html);
161
- }));
160
+ });
162
161
  let path = (0, path_1.dirname)(editor.path);
163
162
  if (!path.endsWith('/')) {
164
163
  path = `${path}/`;
@@ -178,9 +177,9 @@ class FlpSandbox {
178
177
  // register static client sources
179
178
  this.router.use(config_1.PREVIEW_URL.client.url, (0, express_1.static)(config_1.PREVIEW_URL.client.local));
180
179
  // add route for the sandbox.html
181
- this.router.get(this.config.path, ((_req, res, next) => __awaiter(this, void 0, void 0, function* () {
180
+ this.router.get(this.config.path, (async (_req, res, next) => {
182
181
  // inform the user if a html file exists on the filesystem
183
- const file = yield this.project.byPath(this.config.path);
182
+ const file = await this.project.byPath(this.config.path);
184
183
  if (file) {
185
184
  this.logger.info(`HTML file returned at ${this.config.path} is loaded from the file system.`);
186
185
  next();
@@ -190,49 +189,44 @@ class FlpSandbox {
190
189
  const html = (0, ejs_1.render)(template, this.templateConfig);
191
190
  this.sendResponse(res, 'text/html', 200, html);
192
191
  }
193
- })));
192
+ }));
194
193
  }
195
194
  /**
196
195
  * Try finding a locate-reuse-libs script in the project.
197
196
  *
198
197
  * @returns the location of the locate-reuse-libs script or undefined.
199
198
  */
200
- hasLocateReuseLibsScript() {
201
- return __awaiter(this, void 0, void 0, function* () {
202
- const files = yield this.project.byGlob('**/locate-reuse-libs.js');
203
- return files.length > 0;
204
- });
199
+ async hasLocateReuseLibsScript() {
200
+ const files = await this.project.byGlob('**/locate-reuse-libs.js');
201
+ return files.length > 0;
205
202
  }
206
203
  /**
207
204
  * Add additional routes for apps also to be shown in the local FLP.
208
205
  */
209
- addRoutesForAdditionalApps() {
210
- var _a, _b;
211
- return __awaiter(this, void 0, void 0, function* () {
212
- for (const app of this.config.apps) {
213
- let manifest;
214
- if (app.local) {
215
- manifest = JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(app.local, 'webapp/manifest.json'), 'utf-8'));
216
- this.router.use(app.target, (0, express_1.static)((0, path_1.join)(app.local, 'webapp')));
217
- this.logger.info(`Serving additional application at ${app.target} from ${app.local}`);
218
- }
219
- else if (app.componentId) {
220
- manifest = {
221
- 'sap.app': {
222
- id: app.componentId,
223
- title: app.intent ? `${app.intent.object}-${app.intent.action}` : app.componentId
224
- }
225
- };
226
- }
227
- if (manifest) {
228
- yield (0, config_1.addApp)(this.templateConfig, manifest, app, this.logger);
229
- this.logger.info(`Adding additional intent: ${(_a = app.intent) === null || _a === void 0 ? void 0 : _a.object}-${(_b = app.intent) === null || _b === void 0 ? void 0 : _b.action}`);
230
- }
231
- else {
232
- this.logger.info(`Invalid application config for route ${app.target} because neither componentId nor local folder provided.`);
233
- }
206
+ async addRoutesForAdditionalApps() {
207
+ for (const app of this.config.apps) {
208
+ let manifest;
209
+ if (app.local) {
210
+ manifest = JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(app.local, 'webapp/manifest.json'), 'utf-8'));
211
+ this.router.use(app.target, (0, express_1.static)((0, path_1.join)(app.local, 'webapp')));
212
+ this.logger.info(`Serving additional application at ${app.target} from ${app.local}`);
234
213
  }
235
- });
214
+ else if (app.componentId) {
215
+ manifest = {
216
+ 'sap.app': {
217
+ id: app.componentId,
218
+ title: app.intent ? `${app.intent.object}-${app.intent.action}` : app.componentId
219
+ }
220
+ };
221
+ }
222
+ if (manifest) {
223
+ await (0, config_1.addApp)(this.templateConfig, manifest, app, this.logger);
224
+ this.logger.info(`Adding additional intent: ${app.intent?.object}-${app.intent?.action}`);
225
+ }
226
+ else {
227
+ this.logger.info(`Invalid application config for route ${app.target} because neither componentId nor local folder provided.`);
228
+ }
229
+ }
236
230
  }
237
231
  /**
238
232
  * Create required routes for flex.
@@ -241,24 +235,24 @@ class FlpSandbox {
241
235
  const fs = (0, mem_fs_editor_1.create)((0, mem_fs_1.create)());
242
236
  const api = `${config_1.PREVIEW_URL.api}/changes`;
243
237
  this.router.use(api, (0, express_1.json)());
244
- this.router.get(api, ((_req, res) => __awaiter(this, void 0, void 0, function* () {
245
- const changes = yield (0, flex_1.readChanges)(this.project, this.logger);
238
+ this.router.get(api, (async (_req, res) => {
239
+ const changes = await (0, flex_1.readChanges)(this.project, this.logger);
246
240
  if (this.onChangeRequest) {
247
241
  for (const change of Object.values(changes)) {
248
- yield this.onChangeRequest('read', change, fs, this.logger);
242
+ await this.onChangeRequest('read', change, fs, this.logger);
249
243
  }
250
244
  }
251
245
  this.sendResponse(res, 'application/json', 200, JSON.stringify(changes));
252
- })));
253
- this.router.post(api, ((req, res) => __awaiter(this, void 0, void 0, function* () {
246
+ }));
247
+ this.router.post(api, (async (req, res) => {
254
248
  try {
255
249
  const change = req.body;
256
250
  if (this.onChangeRequest) {
257
- yield this.onChangeRequest('write', change, fs, this.logger);
251
+ await this.onChangeRequest('write', change, fs, this.logger);
258
252
  }
259
253
  const { success, message } = (0, flex_1.writeChange)(change, this.utils.getProject().getSourcePath(), fs, this.logger);
260
254
  if (success) {
261
- fs.commit(() => this.sendResponse(res, 'text/plain', 200, message !== null && message !== void 0 ? message : ''));
255
+ fs.commit(() => this.sendResponse(res, 'text/plain', 200, message ?? ''));
262
256
  }
263
257
  else {
264
258
  this.sendResponse(res, 'text/plain', 400, 'INVALID_DATA');
@@ -267,12 +261,12 @@ class FlpSandbox {
267
261
  catch (error) {
268
262
  this.sendResponse(res, 'text/plain', 500, error.message);
269
263
  }
270
- })));
271
- this.router.delete(api, ((req, res) => __awaiter(this, void 0, void 0, function* () {
264
+ }));
265
+ this.router.delete(api, (async (req, res) => {
272
266
  try {
273
267
  const { success, message } = (0, flex_1.deleteChange)(req.body, this.utils.getProject().getSourcePath(), this.logger);
274
268
  if (success) {
275
- this.sendResponse(res, 'text/plain', 200, message !== null && message !== void 0 ? message : '');
269
+ this.sendResponse(res, 'text/plain', 200, message ?? '');
276
270
  }
277
271
  else {
278
272
  this.sendResponse(res, 'text/plain', 400, 'INVALID_DATA');
@@ -281,7 +275,7 @@ class FlpSandbox {
281
275
  catch (error) {
282
276
  this.sendResponse(res, 'text/plain', 500, error.message);
283
277
  }
284
- })));
278
+ }));
285
279
  }
286
280
  /**
287
281
  * If it is part of TestConfig, create a test suite for the test configurations.
@@ -303,7 +297,7 @@ class FlpSandbox {
303
297
  const initTemplate = (0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../../templates/test/testsuite.qunit.js'), 'utf-8');
304
298
  const config = (0, test_1.mergeTestConfigDefaults)(testsuiteConfig);
305
299
  this.logger.debug(`Add route for ${config.path}`);
306
- this.router.get(config.path, ((_req, res) => __awaiter(this, void 0, void 0, function* () {
300
+ this.router.get(config.path, (async (_req, res) => {
307
301
  this.logger.debug(`Serving test route: ${config.path}`);
308
302
  const templateConfig = {
309
303
  basePath: this.templateConfig.basePath,
@@ -311,7 +305,7 @@ class FlpSandbox {
311
305
  };
312
306
  const html = (0, ejs_1.render)(testsuite, templateConfig);
313
307
  this.sendResponse(res, 'text/html', 200, html);
314
- })));
308
+ }));
315
309
  if (testsuiteConfig.init !== undefined) {
316
310
  this.logger.debug(`Skip serving testsuite init script in favor of provided script: ${testsuiteConfig.init}`);
317
311
  return;
@@ -325,9 +319,9 @@ class FlpSandbox {
325
319
  testPaths.push(path_1.posix.relative(path_1.posix.dirname(config.path), mergedConfig.path));
326
320
  }
327
321
  this.logger.debug(`Add route for ${config.init}`);
328
- this.router.get(config.init, ((_req, res, next) => __awaiter(this, void 0, void 0, function* () {
329
- const files = yield this.project.byGlob(config.init.replace('.js', '.[jt]s'));
330
- if ((files === null || files === void 0 ? void 0 : files.length) > 0) {
322
+ this.router.get(config.init, (async (_req, res, next) => {
323
+ const files = await this.project.byGlob(config.init.replace('.js', '.[jt]s'));
324
+ if (files?.length > 0) {
331
325
  this.logger.warn(`Script returned at ${config.path} is loaded from the file system.`);
332
326
  next();
333
327
  }
@@ -339,7 +333,7 @@ class FlpSandbox {
339
333
  const js = (0, ejs_1.render)(initTemplate, templateConfig);
340
334
  this.sendResponse(res, 'application/javascript', 200, js);
341
335
  }
342
- })));
336
+ }));
343
337
  }
344
338
  /**
345
339
  * Send a response with the given content type, status and body.
@@ -372,9 +366,9 @@ class FlpSandbox {
372
366
  const config = (0, test_1.mergeTestConfigDefaults)(testConfig);
373
367
  this.logger.debug(`Add route for ${config.path}`);
374
368
  // add route for the *.qunit.html
375
- this.router.get(config.path, ((_req, res, next) => __awaiter(this, void 0, void 0, function* () {
369
+ this.router.get(config.path, (async (_req, res, next) => {
376
370
  this.logger.debug(`Serving test route: ${config.path}`);
377
- const file = yield this.project.byPath(config.path);
371
+ const file = await this.project.byPath(config.path);
378
372
  if (file) {
379
373
  this.logger.warn(`HTML file returned at ${config.path} is loaded from the file system.`);
380
374
  next();
@@ -384,27 +378,27 @@ class FlpSandbox {
384
378
  const html = (0, ejs_1.render)(htmlTemplate, templateConfig);
385
379
  this.sendResponse(res, 'text/html', 200, html);
386
380
  }
387
- })));
381
+ }));
388
382
  if (testConfig.init !== undefined) {
389
383
  this.logger.debug(`Skip serving test init script in favor of provided script: ${testConfig.init}`);
390
384
  continue;
391
385
  }
392
386
  // add route for the init file
393
387
  this.logger.debug(`Add route for ${config.init}`);
394
- this.router.get(config.init, ((_req, res, next) => __awaiter(this, void 0, void 0, function* () {
388
+ this.router.get(config.init, (async (_req, res, next) => {
395
389
  this.logger.debug(`Serving test init script: ${config.init}`);
396
- const files = yield this.project.byGlob(config.init.replace('.js', '.[jt]s'));
397
- if ((files === null || files === void 0 ? void 0 : files.length) > 0) {
390
+ const files = await this.project.byGlob(config.init.replace('.js', '.[jt]s'));
391
+ if (files?.length > 0) {
398
392
  this.logger.warn(`Script returned at ${config.path} is loaded from the file system.`);
399
393
  next();
400
394
  }
401
395
  else {
402
- const testFiles = yield this.project.byGlob(config.pattern);
396
+ const testFiles = await this.project.byGlob(config.pattern);
403
397
  const templateConfig = { tests: (0, test_1.generateImportList)(ns, testFiles) };
404
398
  const js = (0, ejs_1.render)(initTemplate, templateConfig);
405
399
  this.sendResponse(res, 'application/javascript', 200, js);
406
400
  }
407
- })));
401
+ }));
408
402
  }
409
403
  }
410
404
  }
@@ -442,34 +436,35 @@ function serializeUi5Configuration(config) {
442
436
  * @param util middleware utilities provided by the UI5 CLI
443
437
  * @param logger logger instance
444
438
  */
445
- function initAdp(rootProject, config, flp, util, logger) {
446
- var _a;
447
- return __awaiter(this, void 0, void 0, function* () {
448
- const appVariant = yield rootProject.byPath('/manifest.appdescr_variant');
449
- if (appVariant) {
450
- const adp = new adp_tooling_1.AdpPreview(config, rootProject, util, logger);
451
- const variant = JSON.parse(yield appVariant.getString());
452
- const layer = yield adp.init(variant);
453
- if (flp.rta) {
454
- flp.rta.layer = layer;
455
- flp.rta.options = Object.assign(Object.assign({}, flp.rta.options), { projectId: variant.id, scenario: 'ADAPTATION_PROJECT' });
456
- for (const editor of flp.rta.editors) {
457
- (_a = editor.pluginScript) !== null && _a !== void 0 ? _a : (editor.pluginScript = 'open/ux/preview/client/adp/init');
458
- }
439
+ async function initAdp(rootProject, config, flp, util, logger) {
440
+ const appVariant = await rootProject.byPath('/manifest.appdescr_variant');
441
+ if (appVariant) {
442
+ const adp = new adp_tooling_1.AdpPreview(config, rootProject, util, logger);
443
+ const variant = JSON.parse(await appVariant.getString());
444
+ const layer = await adp.init(variant);
445
+ if (flp.rta) {
446
+ flp.rta.layer = layer;
447
+ flp.rta.options = {
448
+ ...flp.rta.options,
449
+ projectId: variant.id,
450
+ scenario: 'ADAPTATION_PROJECT'
451
+ };
452
+ for (const editor of flp.rta.editors) {
453
+ editor.pluginScript ??= 'open/ux/preview/client/adp/init';
459
454
  }
460
- const descriptor = adp.descriptor;
461
- descriptor.asyncHints.requests = [];
462
- const { name, manifest } = descriptor;
463
- yield flp.init(manifest, name, adp.resources);
464
- flp.router.use(adp.descriptor.url, adp.proxy.bind(adp));
465
- flp.addOnChangeRequestHandler(adp.onChangeRequest.bind(adp));
466
- flp.router.use((0, express_1.json)());
467
- adp.addApis(flp.router);
468
455
  }
469
- else {
470
- throw new Error('ADP configured but no manifest.appdescr_variant found.');
471
- }
472
- });
456
+ const descriptor = adp.descriptor;
457
+ descriptor.asyncHints.requests = [];
458
+ const { name, manifest } = descriptor;
459
+ await flp.init(manifest, name, adp.resources);
460
+ flp.router.use(adp.descriptor.url, adp.proxy.bind(adp));
461
+ flp.addOnChangeRequestHandler(adp.onChangeRequest.bind(adp));
462
+ flp.router.use((0, express_1.json)());
463
+ adp.addApis(flp.router);
464
+ }
465
+ else {
466
+ throw new Error('ADP configured but no manifest.appdescr_variant found.');
467
+ }
473
468
  }
474
469
  exports.initAdp = initAdp;
475
470
  //# sourceMappingURL=flp.js.map
package/dist/base/test.js CHANGED
@@ -28,9 +28,8 @@ const DEFAULTS = {
28
28
  * @returns merged test configuration
29
29
  */
30
30
  function mergeTestConfigDefaults(config) {
31
- var _a;
32
- const defaults = (_a = DEFAULTS[config.framework.toLowerCase()]) !== null && _a !== void 0 ? _a : {};
33
- const merged = Object.assign(Object.assign({}, defaults), config);
31
+ const defaults = DEFAULTS[config.framework.toLowerCase()] ?? {};
32
+ const merged = { ...defaults, ...config };
34
33
  if (!merged.path.startsWith('/')) {
35
34
  merged.path = `/${merged.path}`;
36
35
  }
@@ -31,7 +31,7 @@ sap.ui.define((function () { 'use strict';
31
31
  */
32
32
  function createMatcher(type) {
33
33
  return function match(value) {
34
- return (value === null || value === void 0 ? void 0 : value.type) === type;
34
+ return value?.type === type;
35
35
  };
36
36
  }
37
37
  /**
@@ -119,7 +119,7 @@ sap.ui.define((function () { 'use strict';
119
119
  * @returns data is PostMessageAction<T>
120
120
  */
121
121
  function isPostMessageAction(data) {
122
- return (data === null || data === void 0 ? void 0 : data.type) === POST_MESSAGE_ACTION_TYPE && typeof (data === null || data === void 0 ? void 0 : data.action) === 'object';
122
+ return data?.type === POST_MESSAGE_ACTION_TYPE && typeof data?.action === 'object';
123
123
  }
124
124
  /**
125
125
  * Method to start post message communication.
@@ -188,15 +188,6 @@ sap.ui.define((function () { 'use strict';
188
188
 
189
189
  var telemetry = {};
190
190
 
191
- var __awaiter = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
192
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
193
- return new (P || (P = Promise))(function (resolve, reject) {
194
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
195
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
196
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
197
- step((generator = generator.apply(thisArg, _arguments || [])).next());
198
- });
199
- };
200
191
  Object.defineProperty(telemetry, "__esModule", { value: true });
201
192
  telemetry.reportTelemetry = telemetry.disableTelemetry = telemetry.enableTelemetry = void 0;
202
193
  let enabled = false;
@@ -214,26 +205,24 @@ sap.ui.define((function () { 'use strict';
214
205
  * @param data The TelemetryData object, that needs to be reported
215
206
  * @returns {Promise<void>}
216
207
  */
217
- function reportTelemetry(data) {
218
- return __awaiter(this, void 0, void 0, function* () {
219
- try {
220
- if (enabled) {
221
- const requestOptions = {
222
- method: 'POST',
223
- headers: {
224
- Accept: 'application/json',
225
- 'Content-Type': 'application/json'
226
- },
227
- body: JSON.stringify(data)
228
- };
229
- yield fetch('/preview/api/telemetry', requestOptions);
230
- }
231
- }
232
- catch (_error) {
233
- // something is wrong with the telemetry service
234
- disableTelemetry();
208
+ async function reportTelemetry(data) {
209
+ try {
210
+ if (enabled) {
211
+ const requestOptions = {
212
+ method: 'POST',
213
+ headers: {
214
+ Accept: 'application/json',
215
+ 'Content-Type': 'application/json'
216
+ },
217
+ body: JSON.stringify(data)
218
+ };
219
+ await fetch('/preview/api/telemetry', requestOptions);
235
220
  }
236
- });
221
+ }
222
+ catch (_error) {
223
+ // something is wrong with the telemetry service
224
+ disableTelemetry();
225
+ }
237
226
  }
238
227
  telemetry.reportTelemetry = reportTelemetry;
239
228
 
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  const logger_1 = require("@sap-ux/logger");
13
4
  const flp_1 = require("../base/flp");
@@ -22,31 +13,28 @@ const config_1 = require("../base/config");
22
13
  * @param logger logger instance
23
14
  * @returns a router
24
15
  */
25
- function createRouter({ resources, options, middlewareUtil }, logger) {
26
- var _a, _b;
27
- return __awaiter(this, void 0, void 0, function* () {
28
- // setting defaults
29
- const config = (_a = options.configuration) !== null && _a !== void 0 ? _a : {};
30
- (_b = config.flp) !== null && _b !== void 0 ? _b : (config.flp = {});
31
- (0, config_1.sanitizeConfig)(config, logger);
32
- // configure the FLP sandbox based on information from the manifest
33
- const flp = new flp_1.FlpSandbox(config, resources.rootProject, middlewareUtil, logger);
34
- if (config.adp) {
35
- yield (0, flp_1.initAdp)(resources.rootProject, config.adp, flp, middlewareUtil, logger);
16
+ async function createRouter({ resources, options, middlewareUtil }, logger) {
17
+ // setting defaults
18
+ const config = options.configuration ?? {};
19
+ config.flp ??= {};
20
+ (0, config_1.sanitizeConfig)(config, logger);
21
+ // configure the FLP sandbox based on information from the manifest
22
+ const flp = new flp_1.FlpSandbox(config, resources.rootProject, middlewareUtil, logger);
23
+ if (config.adp) {
24
+ await (0, flp_1.initAdp)(resources.rootProject, config.adp, flp, middlewareUtil, logger);
25
+ }
26
+ else {
27
+ const manifest = await resources.rootProject.byPath('/manifest.json');
28
+ if (manifest) {
29
+ await flp.init(JSON.parse(await manifest.getString()));
36
30
  }
37
31
  else {
38
- const manifest = yield resources.rootProject.byPath('/manifest.json');
39
- if (manifest) {
40
- yield flp.init(JSON.parse(yield manifest.getString()));
41
- }
42
- else {
43
- throw new Error('No manifest.json found.');
44
- }
32
+ throw new Error('No manifest.json found.');
45
33
  }
46
- // add exposed endpoints for cds-plugin-ui5
47
- flp.router.getAppPages = () => (0, config_1.getPreviewPaths)(config).map(({ path }) => path);
48
- return flp.router;
49
- });
34
+ }
35
+ // add exposed endpoints for cds-plugin-ui5
36
+ flp.router.getAppPages = () => (0, config_1.getPreviewPaths)(config).map(({ path }) => path);
37
+ return flp.router;
50
38
  }
51
39
  /**
52
40
  * Exporting the middleware for usage in the UI5 tooling.
@@ -54,19 +42,18 @@ function createRouter({ resources, options, middlewareUtil }, logger) {
54
42
  * @param params middleware configuration
55
43
  * @returns a promise for the request handler
56
44
  */
57
- module.exports = (params) => __awaiter(void 0, void 0, void 0, function* () {
58
- var _a;
45
+ module.exports = async (params) => {
59
46
  const logger = new logger_1.ToolsLogger({
60
47
  transports: [new logger_1.UI5ToolingTransport({ moduleName: 'preview-middleware' })],
61
- logLevel: ((_a = params.options.configuration) === null || _a === void 0 ? void 0 : _a.debug) ? logger_1.LogLevel.Debug : logger_1.LogLevel.Info
48
+ logLevel: params.options.configuration?.debug ? logger_1.LogLevel.Debug : logger_1.LogLevel.Info
62
49
  });
63
50
  try {
64
- return yield createRouter(params, logger);
51
+ return await createRouter(params, logger);
65
52
  }
66
53
  catch (error) {
67
54
  logger.error('Could not start preview-middleware.');
68
55
  logger.error(error.message);
69
56
  throw error;
70
57
  }
71
- });
58
+ };
72
59
  //# sourceMappingURL=middleware.js.map
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.15.8",
12
+ "version": "0.16.1",
13
13
  "license": "Apache-2.0",
14
14
  "author": "@SAP/ux-tools-team",
15
15
  "main": "dist/index.js",
@@ -25,11 +25,11 @@
25
25
  "ejs": "3.1.10",
26
26
  "mem-fs": "2.1.0",
27
27
  "mem-fs-editor": "9.4.0",
28
- "@sap-ux/logger": "0.5.1",
29
- "@sap-ux/btp-utils": "0.14.4",
30
- "@sap-ux/adp-tooling": "0.11.13",
31
- "@sap-ux/project-access": "1.22.4",
32
- "@sap-ux/control-property-editor-sources": "npm:@sap-ux/control-property-editor@0.4.23"
28
+ "@sap-ux/logger": "0.6.0",
29
+ "@sap-ux/btp-utils": "0.15.0",
30
+ "@sap-ux/adp-tooling": "0.12.1",
31
+ "@sap-ux/control-property-editor-sources": "npm:@sap-ux/control-property-editor@0.4.23",
32
+ "@sap-ux/project-access": "1.23.0"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@types/ejs": "3.1.2",
@@ -43,13 +43,13 @@
43
43
  "npm-run-all2": "6.2.0",
44
44
  "nock": "13.4.0",
45
45
  "supertest": "6.3.3",
46
- "@sap-ux-private/playwright": "0.0.3",
46
+ "@sap-ux-private/playwright": "0.1.0",
47
47
  "dotenv": "16.3.1",
48
- "@private/preview-middleware-client": "npm:@sap-ux-private/preview-middleware-client@0.9.18",
49
- "@sap-ux/axios-extension": "1.14.4",
50
- "@sap-ux/i18n": "0.0.7",
51
- "@sap-ux/store": "0.6.0",
52
- "@sap-ux/ui5-info": "0.5.0"
48
+ "@private/preview-middleware-client": "npm:@sap-ux-private/preview-middleware-client@0.10.0",
49
+ "@sap-ux/axios-extension": "1.15.1",
50
+ "@sap-ux/store": "0.7.0",
51
+ "@sap-ux/ui5-info": "0.6.0",
52
+ "@sap-ux/i18n": "0.1.0"
53
53
  },
54
54
  "peerDependencies": {
55
55
  "express": "4"