@sap-ux/preview-middleware 0.15.8 → 0.16.2

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)) {