@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.
- package/dist/base/config.js +85 -107
- package/dist/base/flex.js +14 -26
- package/dist/base/flp.js +130 -135
- package/dist/base/test.js +2 -3
- package/dist/client/flp/init.js +193 -255
- package/dist/client/flp/init.ts +2 -2
- package/dist/client/thirdparty/@sap-ux-private/control-property-editor-common.js +21 -32
- package/dist/ui5/middleware.js +23 -36
- package/package.json +12 -12
package/dist/base/config.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.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
|
-
|
|
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:
|
|
105
|
-
intent:
|
|
106
|
-
apps:
|
|
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
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
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
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
const
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
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 =
|
|
222
|
-
const ui5Theme =
|
|
223
|
-
const id =
|
|
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:
|
|
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:
|
|
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 (
|
|
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
|
|
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
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
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
|
-
|
|
374
|
-
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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)) {
|