@sap-ux/preview-middleware 0.14.0 → 0.15.0

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,4 @@
1
- import type { Logger } from '@sap-ux/logger';
2
- import { ToolsLogger } from '@sap-ux/logger';
1
+ import { ToolsLogger, type Logger } from '@sap-ux/logger';
3
2
  import type { App, FlpConfig, Intent, InternalTestConfig, MiddlewareConfig } from '../types';
4
3
  import { type Manifest, type UI5FlexLayer } from '@sap-ux/project-access';
5
4
  import { type Editor } from 'mem-fs-editor';
@@ -96,7 +95,7 @@ export declare function sanitizeConfig(config: MiddlewareConfig, logger: ToolsLo
96
95
  * @param app configuration for the preview
97
96
  * @param logger logger instance
98
97
  */
99
- export declare function addApp(templateConfig: TemplateConfig, manifest: Manifest, app: App, logger: Logger): Promise<void>;
98
+ export declare function addApp(templateConfig: TemplateConfig, manifest: Partial<Manifest>, app: App, logger: Logger): Promise<void>;
100
99
  /**
101
100
  * Creates the configuration object for the sandbox.html template.
102
101
  *
@@ -104,7 +103,7 @@ export declare function addApp(templateConfig: TemplateConfig, manifest: Manifes
104
103
  * @param manifest application manifest
105
104
  * @returns configuration object for the sandbox.html template
106
105
  */
107
- export declare function createFlpTemplateConfig(config: FlpConfig, manifest: Manifest): TemplateConfig;
106
+ export declare function createFlpTemplateConfig(config: FlpConfig, manifest: Partial<Manifest>): TemplateConfig;
108
107
  /**
109
108
  * Creates the configuration object for the test template.
110
109
  *
@@ -162,18 +162,18 @@ function getFlexSettings() {
162
162
  * @param logger logger instance
163
163
  */
164
164
  function addApp(templateConfig, manifest, app, logger) {
165
- var _a, _b, _c, _d, _e, _f;
165
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
166
166
  return __awaiter(this, void 0, void 0, function* () {
167
- const id = manifest['sap.app'].id;
168
- (_a = app.intent) !== null && _a !== void 0 ? _a : (app.intent = {
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
169
  object: id.replace(/\./g, ''),
170
170
  action: 'preview'
171
171
  });
172
172
  templateConfig.ui5.resources[id] = app.target;
173
- templateConfig.apps[`${(_b = app.intent) === null || _b === void 0 ? void 0 : _b.object}-${(_c = app.intent) === null || _c === void 0 ? void 0 : _c.action}`] = {
174
- title: (_d = (yield getI18nTextFromProperty(app.local, manifest['sap.app'].title, logger))) !== null && _d !== void 0 ? _d : id,
175
- description: (_e = (yield getI18nTextFromProperty(app.local, manifest['sap.app'].description, logger))) !== null && _e !== void 0 ? _e : '',
176
- additionalInformation: `SAPUI5.Component=${(_f = app.componentId) !== null && _f !== void 0 ? _f : id}`,
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
177
  applicationType: 'URL',
178
178
  url: app.target,
179
179
  applicationDependencies: { manifest: true }
@@ -216,14 +216,14 @@ function getI18nTextFromProperty(projectRoot, propertyValue, logger) {
216
216
  * @returns configuration object for the sandbox.html template
217
217
  */
218
218
  function createFlpTemplateConfig(config, manifest) {
219
- var _a, _b, _c, _d;
219
+ var _a, _b, _c, _d, _e, _f;
220
220
  const flex = getFlexSettings();
221
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
222
  const ui5Theme = (_c = config.theme) !== null && _c !== void 0 ? _c : (supportedThemes.includes(exports.DEFAULT_THEME) ? exports.DEFAULT_THEME : supportedThemes[0]);
223
- const id = manifest['sap.app'].id;
223
+ const id = (_e = (_d = manifest['sap.app']) === null || _d === void 0 ? void 0 : _d.id) !== null && _e !== void 0 ? _e : '';
224
224
  const ns = id.replace(/\./g, '/');
225
225
  return {
226
- basePath: (_d = path_1.posix.relative(path_1.posix.dirname(config.path), '/')) !== null && _d !== void 0 ? _d : '.',
226
+ basePath: (_f = path_1.posix.relative(path_1.posix.dirname(config.path), '/')) !== null && _f !== void 0 ? _f : '.',
227
227
  apps: {},
228
228
  init: config.init ? ns + config.init : undefined,
229
229
  ui5: {
@@ -287,6 +287,34 @@ function getPreviewPaths(config, logger = new logger_1.ToolsLogger()) {
287
287
  return urls;
288
288
  }
289
289
  exports.getPreviewPaths = getPreviewPaths;
290
+ const TEMPLATE_PATH = (0, path_1.join)(__dirname, '../../templates');
291
+ /**
292
+ * Generate test runners.
293
+ *
294
+ * @param configs array of test configurations
295
+ * @param manifest application manifest
296
+ * @param fs mem fs editor instance
297
+ * @param webappPath webapp path
298
+ * @param flpTemplConfig FLP configuration
299
+ */
300
+ function generateTestRunners(configs, manifest, fs, webappPath, flpTemplConfig) {
301
+ for (const test of configs !== null && configs !== void 0 ? configs : []) {
302
+ const testConfig = (0, test_1.mergeTestConfigDefaults)(test);
303
+ if (['QUnit', 'OPA5'].includes(test.framework)) {
304
+ const testTemlpate = (0, fs_1.readFileSync)((0, path_1.join)(TEMPLATE_PATH, 'test/qunit.html'), 'utf-8');
305
+ const testTemplateConfig = createTestTemplateConfig(testConfig, manifest['sap.app'].id);
306
+ fs.write((0, path_1.join)(webappPath, testConfig.path), (0, ejs_1.render)(testTemlpate, testTemplateConfig));
307
+ }
308
+ else if (test.framework === 'Testsuite') {
309
+ const testTemlpate = (0, fs_1.readFileSync)((0, path_1.join)(TEMPLATE_PATH, 'test/testsuite.qunit.html'), 'utf-8');
310
+ const testTemplateConfig = {
311
+ basePath: flpTemplConfig.basePath,
312
+ initPath: testConfig.init
313
+ };
314
+ fs.write((0, path_1.join)(webappPath, testConfig.path), (0, ejs_1.render)(testTemlpate, testTemplateConfig));
315
+ }
316
+ }
317
+ }
290
318
  /**
291
319
  * Generates the preview files.
292
320
  *
@@ -304,38 +332,45 @@ function generatePreviewFiles(basePath, config, fs, logger = new logger_1.ToolsL
304
332
  if (!fs) {
305
333
  fs = (0, mem_fs_editor_1.create)((0, mem_fs_1.create)());
306
334
  }
307
- const templatePath = (0, path_1.join)(__dirname, '../../templates');
308
- const webappPath = yield (0, project_access_1.getWebappPath)(basePath, fs);
309
- const manifest = (yield fs.readJSON((0, path_1.join)(webappPath, 'manifest.json')));
310
335
  // generate FLP configuration
336
+ const flpTemplate = (0, fs_1.readFileSync)((0, path_1.join)(TEMPLATE_PATH, 'flp/sandbox.html'), 'utf-8');
311
337
  const flpConfig = getFlpConfigWithDefaults(config.flp);
312
- const flpTemplate = (0, fs_1.readFileSync)((0, path_1.join)(templatePath, 'flp/sandbox.html'), 'utf-8');
313
- const flpTemplConfig = createFlpTemplateConfig(flpConfig, manifest);
314
- yield addApp(flpTemplConfig, manifest, {
315
- target: flpTemplConfig.basePath,
316
- local: '.',
317
- intent: flpConfig.intent
318
- }, logger);
319
- fs.write((0, path_1.join)(webappPath, flpConfig.path), (0, ejs_1.render)(flpTemplate, flpTemplConfig));
320
- // optional test files
321
- if (config.test) {
322
- for (const test of config.test) {
323
- const testConfig = (0, test_1.mergeTestConfigDefaults)(test);
324
- if (['QUnit', 'OPA5'].includes(test.framework)) {
325
- const testTemlpate = (0, fs_1.readFileSync)((0, path_1.join)(templatePath, 'test/qunit.html'), 'utf-8');
326
- const testTemplateConfig = createTestTemplateConfig(testConfig, manifest['sap.app'].id);
327
- fs.write((0, path_1.join)(webappPath, testConfig.path), (0, ejs_1.render)(testTemlpate, testTemplateConfig));
328
- }
329
- else if (test.framework === 'Testsuite') {
330
- const testTemlpate = (0, fs_1.readFileSync)((0, path_1.join)(templatePath, 'test/testsuite.qunit.html'), 'utf-8');
331
- const testTemplateConfig = {
332
- basePath: flpTemplConfig.basePath,
333
- initPath: testConfig.init
334
- };
335
- fs.write((0, path_1.join)(webappPath, testConfig.path), (0, ejs_1.render)(testTemlpate, testTemplateConfig));
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
+ }
336
370
  }
337
371
  }
338
372
  }
373
+ fs.write(flpPath, (0, ejs_1.render)(flpTemplate, flpTemplConfig));
339
374
  return fs;
340
375
  });
341
376
  }
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.14.0",
12
+ "version": "0.15.0",
13
13
  "license": "Apache-2.0",
14
14
  "author": "@SAP/ux-tools-team",
15
15
  "main": "dist/index.js",
@@ -26,9 +26,9 @@
26
26
  "mem-fs": "2.1.0",
27
27
  "mem-fs-editor": "9.4.0",
28
28
  "@sap-ux/logger": "0.5.1",
29
+ "@sap-ux/btp-utils": "0.14.4",
29
30
  "@sap-ux/adp-tooling": "0.11.7",
30
31
  "@sap-ux/control-property-editor-sources": "npm:@sap-ux/control-property-editor@0.4.23",
31
- "@sap-ux/btp-utils": "0.14.4",
32
32
  "@sap-ux/project-access": "1.22.3"
33
33
  },
34
34
  "devDependencies": {
@@ -45,11 +45,11 @@
45
45
  "supertest": "6.3.3",
46
46
  "@sap-ux-private/playwright": "0.0.3",
47
47
  "dotenv": "16.3.1",
48
- "@sap-ux/axios-extension": "1.14.2",
49
48
  "@private/preview-middleware-client": "npm:@sap-ux-private/preview-middleware-client@0.9.16",
49
+ "@sap-ux/axios-extension": "1.14.2",
50
50
  "@sap-ux/store": "0.6.0",
51
- "@sap-ux/i18n": "0.0.7",
52
- "@sap-ux/ui5-info": "0.5.0"
51
+ "@sap-ux/ui5-info": "0.5.0",
52
+ "@sap-ux/i18n": "0.0.7"
53
53
  },
54
54
  "peerDependencies": {
55
55
  "express": "4"