@sap-ux/app-config-writer 0.5.1 → 0.5.4

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/index.d.ts CHANGED
@@ -2,4 +2,5 @@ export { getSmartLinksTargetFromPrompt } from './prompt';
2
2
  export { generateSmartLinksConfig } from './smartlinks-config';
3
3
  export { generateInboundNavigationConfig, readManifest } from './navigation-config';
4
4
  export { generateVariantsConfig } from './variants-config';
5
+ export { convertToVirtualPreview } from './preview-config';
5
6
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateVariantsConfig = exports.readManifest = exports.generateInboundNavigationConfig = exports.generateSmartLinksConfig = exports.getSmartLinksTargetFromPrompt = void 0;
3
+ exports.convertToVirtualPreview = exports.generateVariantsConfig = exports.readManifest = exports.generateInboundNavigationConfig = exports.generateSmartLinksConfig = exports.getSmartLinksTargetFromPrompt = void 0;
4
4
  var prompt_1 = require("./prompt");
5
5
  Object.defineProperty(exports, "getSmartLinksTargetFromPrompt", { enumerable: true, get: function () { return prompt_1.getSmartLinksTargetFromPrompt; } });
6
6
  var smartlinks_config_1 = require("./smartlinks-config");
@@ -10,4 +10,6 @@ Object.defineProperty(exports, "generateInboundNavigationConfig", { enumerable:
10
10
  Object.defineProperty(exports, "readManifest", { enumerable: true, get: function () { return navigation_config_1.readManifest; } });
11
11
  var variants_config_1 = require("./variants-config");
12
12
  Object.defineProperty(exports, "generateVariantsConfig", { enumerable: true, get: function () { return variants_config_1.generateVariantsConfig; } });
13
+ var preview_config_1 = require("./preview-config");
14
+ Object.defineProperty(exports, "convertToVirtualPreview", { enumerable: true, get: function () { return preview_config_1.convertToVirtualPreview; } });
13
15
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,16 @@
1
+ import { type Editor } from 'mem-fs-editor';
2
+ import { type ToolsLogger } from '@sap-ux/logger';
3
+ /**
4
+ * Converts the local preview files of a project to virtual files.
5
+ *
6
+ * It will check the prerequisites and confirm an explicit approval to convert the project.
7
+ * If the prerequisites and approval are met, the corresponding UI5 yaml configuration for the preview middleware will be converted.
8
+ * Corresponding files which are used for the preview are renamed or deleted.
9
+ *
10
+ * @param basePath - base path to be used for the conversion
11
+ * @param logger logger to report info to the user
12
+ * @param fs - file system reference
13
+ * @returns file system reference
14
+ */
15
+ export declare function convertToVirtualPreview(basePath: string, logger?: ToolsLogger, fs?: Editor): Promise<Editor>;
16
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.convertToVirtualPreview = convertToVirtualPreview;
4
+ const prerequisites_1 = require("./prerequisites");
5
+ const mem_fs_1 = require("mem-fs");
6
+ const mem_fs_editor_1 = require("mem-fs-editor");
7
+ const preview_files_1 = require("./preview-files");
8
+ const ui5_yaml_1 = require("./ui5-yaml");
9
+ const package_json_1 = require("./package-json");
10
+ /**
11
+ * Converts the local preview files of a project to virtual files.
12
+ *
13
+ * It will check the prerequisites and confirm an explicit approval to convert the project.
14
+ * If the prerequisites and approval are met, the corresponding UI5 yaml configuration for the preview middleware will be converted.
15
+ * Corresponding files which are used for the preview are renamed or deleted.
16
+ *
17
+ * @param basePath - base path to be used for the conversion
18
+ * @param logger logger to report info to the user
19
+ * @param fs - file system reference
20
+ * @returns file system reference
21
+ */
22
+ async function convertToVirtualPreview(basePath, logger, fs) {
23
+ if (!fs) {
24
+ fs = (0, mem_fs_editor_1.create)((0, mem_fs_1.create)());
25
+ }
26
+ if (!(await (0, prerequisites_1.checkPrerequisites)(basePath, fs, logger))) {
27
+ throw Error('The prerequisites are not met. For more information, see the log messages above.');
28
+ }
29
+ if (!(await (0, prerequisites_1.getExplicitApprovalToAdjustFiles)())) {
30
+ logger?.error('You have not approved the conversion. The conversion has been aborted.');
31
+ return fs;
32
+ }
33
+ await (0, ui5_yaml_1.updatePreviewMiddlewareConfigs)(fs, basePath, logger);
34
+ await (0, preview_files_1.renameDefaultSandboxes)(fs, basePath);
35
+ await (0, preview_files_1.deleteNoLongerUsedFiles)(fs, basePath);
36
+ await (0, package_json_1.updateVariantsCreationScript)(fs, basePath, logger);
37
+ return fs;
38
+ }
39
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,54 @@
1
+ import type { Editor } from 'mem-fs-editor';
2
+ import type { ToolsLogger } from '@sap-ux/logger';
3
+ import type { Package } from '@sap-ux/project-access';
4
+ import type { FlpConfig } from '@sap-ux/preview-middleware';
5
+ /**
6
+ * Ensures that the @sap/ux-ui5-tooling or @sap-ux/preview-middleware dependency exists in the package.json.
7
+ *
8
+ * If none dependency is given, the @sap-ux/preview-middleware will be added as a devDependency.
9
+ *
10
+ * @param packageJson - the package.json file content
11
+ * @param fs - file system reference
12
+ * @param packageJsonPath - the path to the package.json file
13
+ */
14
+ export declare function ensurePreviewMiddlewareDependency(packageJson: Package | undefined, fs: Editor, packageJsonPath: string): void;
15
+ /**
16
+ * Extracts the URL details from a given script.
17
+ *
18
+ * It extracts the used mount point for the preview and the used intent.
19
+ *
20
+ * @param script - the content of the script
21
+ * @returns the URL details
22
+ */
23
+ export declare function extractUrlDetails(script: string): {
24
+ path: string | undefined;
25
+ intent: FlpConfig['intent'] | undefined;
26
+ };
27
+ /**
28
+ * Check if the script/-name is valid for the conversion.
29
+ *
30
+ * The script:
31
+ * - must contain 'ui5 serve' or 'fiori run' command
32
+ * - must not be a test script
33
+ * - must not relate to 'webapp/index.html'.
34
+ *
35
+ * The script name:
36
+ * - must not be 'start-variants-management'
37
+ * - must not be 'start-control-property-editor'.
38
+ *
39
+ * @param scriptName - the name of the script from the package.json file
40
+ * @param script - the content of the script from the package.json file
41
+ * @returns indicator if the script is valid
42
+ */
43
+ export declare function isValidPreviewScript(scriptName: string, script: string | undefined): boolean;
44
+ /**
45
+ * Updates the variants creation script in package.json if needed.
46
+ *
47
+ * If an update is needed, the used intent of the script will be adjusted based on the used UI5 yaml configuration.
48
+ *
49
+ * @param fs - file system reference
50
+ * @param basePath - base path to be used for the conversion
51
+ * @param logger logger to report info to the user
52
+ */
53
+ export declare function updateVariantsCreationScript(fs: Editor, basePath: string, logger?: ToolsLogger): Promise<void>;
54
+ //# sourceMappingURL=package-json.d.ts.map
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ensurePreviewMiddlewareDependency = ensurePreviewMiddlewareDependency;
4
+ exports.extractUrlDetails = extractUrlDetails;
5
+ exports.isValidPreviewScript = isValidPreviewScript;
6
+ exports.updateVariantsCreationScript = updateVariantsCreationScript;
7
+ const path_1 = require("path");
8
+ const ui5_yaml_1 = require("./ui5-yaml");
9
+ const variants_config_1 = require("../variants-config");
10
+ /**
11
+ * Ensures that the @sap/ux-ui5-tooling or @sap-ux/preview-middleware dependency exists in the package.json.
12
+ *
13
+ * If none dependency is given, the @sap-ux/preview-middleware will be added as a devDependency.
14
+ *
15
+ * @param packageJson - the package.json file content
16
+ * @param fs - file system reference
17
+ * @param packageJsonPath - the path to the package.json file
18
+ */
19
+ function ensurePreviewMiddlewareDependency(packageJson, fs, packageJsonPath) {
20
+ if (!packageJson) {
21
+ return;
22
+ }
23
+ const hasDependency = (dependency) => !!packageJson?.devDependencies?.[dependency] || !!packageJson?.dependencies?.[dependency];
24
+ const dependencies = ['@sap-ux/preview-middleware', '@sap/ux-ui5-tooling'];
25
+ if (dependencies.some((dependency) => hasDependency(dependency))) {
26
+ return;
27
+ }
28
+ packageJson.devDependencies = { ...packageJson.devDependencies, '@sap-ux/preview-middleware': 'latest' };
29
+ fs.writeJSON(packageJsonPath, packageJson);
30
+ }
31
+ /**
32
+ * Extracts the URL details from a given script.
33
+ *
34
+ * It extracts the used mount point for the preview and the used intent.
35
+ *
36
+ * @param script - the content of the script
37
+ * @returns the URL details
38
+ */
39
+ function extractUrlDetails(script) {
40
+ //extract the URL from the 'open' command of the script
41
+ let url = / (?:--open|-o|--o) ([^"]?\S*)/.exec(script)?.[1] ?? undefined;
42
+ url = url?.startsWith('"') ? url.slice(1) : url;
43
+ //extract the path from the URL
44
+ const path = /^[^?#]+\.html/.exec(url ?? '')?.[0] ?? undefined;
45
+ //extract the intent from the URL
46
+ const intent = /(?<=#)\w+-\w+/.exec(url ?? '')?.[0] ?? undefined;
47
+ return {
48
+ path,
49
+ intent: intent
50
+ ? {
51
+ object: intent?.split('-')[0],
52
+ action: intent?.split('-')[1]
53
+ }
54
+ : undefined
55
+ };
56
+ }
57
+ /**
58
+ * Check if the script/-name is valid for the conversion.
59
+ *
60
+ * The script:
61
+ * - must contain 'ui5 serve' or 'fiori run' command
62
+ * - must not be a test script
63
+ * - must not relate to 'webapp/index.html'.
64
+ *
65
+ * The script name:
66
+ * - must not be 'start-variants-management'
67
+ * - must not be 'start-control-property-editor'.
68
+ *
69
+ * @param scriptName - the name of the script from the package.json file
70
+ * @param script - the content of the script from the package.json file
71
+ * @returns indicator if the script is valid
72
+ */
73
+ function isValidPreviewScript(scriptName, script) {
74
+ const isValidScriptName = scriptName != 'start-variants-management' && scriptName != 'start-control-property-editor';
75
+ //eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
76
+ const startsWebServer = !!(script?.includes('ui5 serve') || script?.includes('fiori run'));
77
+ const { path } = extractUrlDetails(script ?? '');
78
+ const opensTest = path?.includes('qunit.html');
79
+ const opensIndexHtml = path === 'index.html';
80
+ return isValidScriptName && startsWebServer && !opensTest && !opensIndexHtml;
81
+ }
82
+ /**
83
+ * Updates the variants creation script in package.json if needed.
84
+ *
85
+ * If an update is needed, the used intent of the script will be adjusted based on the used UI5 yaml configuration.
86
+ *
87
+ * @param fs - file system reference
88
+ * @param basePath - base path to be used for the conversion
89
+ * @param logger logger to report info to the user
90
+ */
91
+ async function updateVariantsCreationScript(fs, basePath, logger) {
92
+ const packageJsonPath = (0, path_1.join)(basePath, 'package.json');
93
+ const packageJson = fs.readJSON(packageJsonPath);
94
+ if (packageJson?.scripts?.['start-variants-management']) {
95
+ const ui5Yaml = (0, path_1.basename)((0, ui5_yaml_1.extractYamlConfigFileName)(packageJson?.scripts?.['start-variants-management']));
96
+ const yamlPath = (0, path_1.join)(basePath, ui5Yaml);
97
+ await (0, variants_config_1.generateVariantsConfig)(basePath, yamlPath, logger, fs);
98
+ }
99
+ }
100
+ //# sourceMappingURL=package-json.js.map
@@ -0,0 +1,21 @@
1
+ import type { Editor } from 'mem-fs-editor';
2
+ import type { ToolsLogger } from '@sap-ux/logger';
3
+ /**
4
+ * Check if the prerequisites for the conversion are met.
5
+ * - UI5 CLI version 3.0.0 or higher is being used.
6
+ * - '@sap/grunt-sapui5-bestpractice-build' is not being used.
7
+ * - '@sap-ux/ui5-middleware-fe-mockserver' or 'cds-plugin-ui5' is being used.
8
+ *
9
+ * @param basePath - base path to be used for the conversion
10
+ * @param fs - file system reference
11
+ * @param logger logger to report info to the user
12
+ * @returns indicator if the prerequisites are met
13
+ */
14
+ export declare function checkPrerequisites(basePath: string, fs: Editor, logger?: ToolsLogger): Promise<boolean>;
15
+ /**
16
+ * Get the explicit approval form the user to do the conversion.
17
+ *
18
+ * @returns Explicit user approval to do the conversion.
19
+ */
20
+ export declare function getExplicitApprovalToAdjustFiles(): Promise<boolean>;
21
+ //# sourceMappingURL=prerequisites.d.ts.map
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkPrerequisites = checkPrerequisites;
4
+ exports.getExplicitApprovalToAdjustFiles = getExplicitApprovalToAdjustFiles;
5
+ const path_1 = require("path");
6
+ const prompts_1 = require("prompts");
7
+ /**
8
+ * Check if the prerequisites for the conversion are met.
9
+ * - UI5 CLI version 3.0.0 or higher is being used.
10
+ * - '@sap/grunt-sapui5-bestpractice-build' is not being used.
11
+ * - '@sap-ux/ui5-middleware-fe-mockserver' or 'cds-plugin-ui5' is being used.
12
+ *
13
+ * @param basePath - base path to be used for the conversion
14
+ * @param fs - file system reference
15
+ * @param logger logger to report info to the user
16
+ * @returns indicator if the prerequisites are met
17
+ */
18
+ async function checkPrerequisites(basePath, fs, logger) {
19
+ const packageJsonPath = (0, path_1.join)(basePath, 'package.json');
20
+ const packageJson = fs.readJSON(packageJsonPath);
21
+ let prerequisitesMet = true;
22
+ if (!packageJson) {
23
+ throw Error(`File 'package.json' not found at '${basePath}'`);
24
+ }
25
+ const sapui5BestpracticeBuildExists = !!packageJson?.devDependencies?.['@sap/grunt-sapui5-bestpractice-build'] ||
26
+ !!packageJson?.dependencies?.['@sap/grunt-sapui5-bestpractice-build'];
27
+ if (sapui5BestpracticeBuildExists) {
28
+ logger?.error("Conversion from '@sap/grunt-sapui5-bestpractice-build' is not supported. You must migrate to UI5 CLI version 3.0.0 or higher. For more information, see https://sap.github.io/ui5-tooling/v3/updates/migrate-v3.");
29
+ prerequisitesMet = false;
30
+ }
31
+ const ui5CliVersion = packageJson?.devDependencies?.['@ui5/cli'] ?? packageJson?.dependencies?.['@ui5/cli'] ?? '0';
32
+ if (parseInt(ui5CliVersion.split('.')[0], 10) < 3) {
33
+ logger?.error('UI5 CLI version 3.0.0 or higher is required to convert the preview to virtual files. For more information, see https://sap.github.io/ui5-tooling/v3/updates/migrate-v3.');
34
+ prerequisitesMet = false;
35
+ }
36
+ const ui5MiddlewareMockserverExists = !!packageJson?.devDependencies?.['@sap-ux/ui5-middleware-fe-mockserver'] ||
37
+ !!packageJson?.dependencies?.['@sap-ux/ui5-middleware-fe-mockserver'];
38
+ const cdsPluginUi5Exists = !!packageJson?.devDependencies?.['cds-plugin-ui5'] || !!packageJson?.dependencies?.['cds-plugin-ui5'];
39
+ if (!ui5MiddlewareMockserverExists && !cdsPluginUi5Exists) {
40
+ logger?.error("Conversion from 'sap/ui/core/util/MockServer' is not supported. You must migrate from '@sap-ux/ui5-middleware-fe-mockserver'. For more information, see https://www.npmjs.com/package/@sap-ux/ui5-middleware-fe-mockserver.");
41
+ prerequisitesMet = false;
42
+ }
43
+ return prerequisitesMet;
44
+ }
45
+ /**
46
+ * Get the explicit approval form the user to do the conversion.
47
+ *
48
+ * @returns Explicit user approval to do the conversion.
49
+ */
50
+ async function getExplicitApprovalToAdjustFiles() {
51
+ const question = {
52
+ type: 'confirm',
53
+ name: 'approval',
54
+ initial: false,
55
+ message: 'The converter will rename the HTML files and delete the JS and TS files used for the existing preview functionality and configure virtual files instead. Do you want to proceed with the conversion?'
56
+ };
57
+ return Boolean((await (0, prompts_1.prompt)([question])).approval);
58
+ }
59
+ //# sourceMappingURL=prerequisites.js.map
@@ -0,0 +1,32 @@
1
+ import type { Editor } from 'mem-fs-editor';
2
+ import type { ToolsLogger } from '@sap-ux/logger';
3
+ /**
4
+ * Renames the sandbox file which is used in a given script.
5
+ *
6
+ * The corresponding file will be renamed from *.html to *_old.html.
7
+ *
8
+ * @param fs - file system reference
9
+ * @param path - file path to be used for the renaming
10
+ * @param logger logger to report info to the user
11
+ */
12
+ export declare function renameSandbox(fs: Editor, path: string, logger?: ToolsLogger): Promise<void>;
13
+ /**
14
+ * Renames the default sandbox files.
15
+ *
16
+ * The default files are 'flpSandbox.html' and 'flpSandboxMockserver.html' and located under webapp/test.
17
+ * It adds '_old' to 'test/flpSandbox.html' and 'test/flpSandboxMockserver.html' to indicate that they will no longer be used.
18
+ *
19
+ * @param fs - file system reference
20
+ * @param basePath - base path to be used for the conversion
21
+ * @param logger logger to report info to the user
22
+ */
23
+ export declare function renameDefaultSandboxes(fs: Editor, basePath: string, logger?: ToolsLogger): Promise<void>;
24
+ /**
25
+ * Deletes the *.js and *.ts files which are no longer used for the virtual preview.
26
+ *
27
+ * @param fs - file system reference
28
+ * @param basePath - base path to be used for the conversion
29
+ * @param logger logger to report info to the user
30
+ */
31
+ export declare function deleteNoLongerUsedFiles(fs: Editor, basePath: string, logger?: ToolsLogger): Promise<void>;
32
+ //# sourceMappingURL=preview-files.d.ts.map
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.renameSandbox = renameSandbox;
4
+ exports.renameDefaultSandboxes = renameDefaultSandboxes;
5
+ exports.deleteNoLongerUsedFiles = deleteNoLongerUsedFiles;
6
+ const path_1 = require("path");
7
+ const project_access_1 = require("@sap-ux/project-access");
8
+ const renameMessage = (filename) => `Renamed '${filename}' to '${filename.slice(0, -5)}_old.html'. This file is no longer needed for the preview functionality. If you have not modified this file, you can delete it. If you have modified this file, move the modified content to a custom init script for the preview middleware. For more information, see https://www.npmjs.com/package/preview-middleware#migration.`;
9
+ /**
10
+ * Renames the sandbox file which is used in a given script.
11
+ *
12
+ * The corresponding file will be renamed from *.html to *_old.html.
13
+ *
14
+ * @param fs - file system reference
15
+ * @param path - file path to be used for the renaming
16
+ * @param logger logger to report info to the user
17
+ */
18
+ async function renameSandbox(fs, path, logger) {
19
+ if (fs.exists(path)) {
20
+ fs.move(path, path.replace('.html', '_old.html'));
21
+ logger?.info(renameMessage((0, path_1.basename)(path)));
22
+ }
23
+ else if (
24
+ //checks if there is a file with the same name which has already been deleted/renamed to _old.html
25
+ Object.keys(fs.dump(undefined, (file) => {
26
+ return file.history.includes(path) && file.state !== 'deleted';
27
+ })).length === 0) {
28
+ logger?.debug(`The file '${(0, path_1.basename)(path)}', has already been renamed. Skipping renaming.`);
29
+ }
30
+ else {
31
+ logger?.warn(`The file '${(0, path_1.basename)(path)}', has not been found. Skipping renaming.`);
32
+ }
33
+ }
34
+ /**
35
+ * Renames the default sandbox files.
36
+ *
37
+ * The default files are 'flpSandbox.html' and 'flpSandboxMockserver.html' and located under webapp/test.
38
+ * It adds '_old' to 'test/flpSandbox.html' and 'test/flpSandboxMockserver.html' to indicate that they will no longer be used.
39
+ *
40
+ * @param fs - file system reference
41
+ * @param basePath - base path to be used for the conversion
42
+ * @param logger logger to report info to the user
43
+ */
44
+ async function renameDefaultSandboxes(fs, basePath, logger) {
45
+ const defaultSandboxPaths = [(0, path_1.join)('test', 'flpSandbox.html'), (0, path_1.join)('test', 'flpSandboxMockserver.html')];
46
+ for (const path of defaultSandboxPaths) {
47
+ await renameSandbox(fs, (0, path_1.join)(await (0, project_access_1.getWebappPath)(basePath), path), logger);
48
+ }
49
+ }
50
+ /**
51
+ * Deletes the *.js and *.ts files which are no longer used for the virtual preview.
52
+ *
53
+ * @param fs - file system reference
54
+ * @param basePath - base path to be used for the conversion
55
+ * @param logger logger to report info to the user
56
+ */
57
+ async function deleteNoLongerUsedFiles(fs, basePath, logger) {
58
+ const webappTestPath = (0, path_1.join)(await (0, project_access_1.getWebappPath)(basePath), 'test');
59
+ [
60
+ (0, path_1.join)(webappTestPath, 'locate-reuse-libs.js'),
61
+ (0, path_1.join)(webappTestPath, 'changes_loader.js'),
62
+ (0, path_1.join)(webappTestPath, 'changes_loader.ts'),
63
+ (0, path_1.join)(webappTestPath, 'changes_preview.js'),
64
+ (0, path_1.join)(webappTestPath, 'changes_preview.ts'),
65
+ (0, path_1.join)(webappTestPath, 'flpSandbox.js'),
66
+ (0, path_1.join)(webappTestPath, 'flpSandbox.ts'),
67
+ (0, path_1.join)(webappTestPath, 'initFlpSandbox.js'),
68
+ (0, path_1.join)(webappTestPath, 'initFlpSandbox.ts')
69
+ ].forEach((path) => {
70
+ if (fs.exists(path)) {
71
+ fs.delete(path);
72
+ logger?.info(`Deleted the '${(0, path_1.join)('webapp', 'test', (0, path_1.basename)(path))}' file. This file is no longer needed for the preview functionality.`);
73
+ }
74
+ });
75
+ }
76
+ //# sourceMappingURL=preview-files.js.map
@@ -0,0 +1,49 @@
1
+ import type { CustomMiddleware } from '@sap-ux/ui5-config';
2
+ import type { Editor } from 'mem-fs-editor';
3
+ import type { FlpConfig } from '@sap-ux/preview-middleware';
4
+ import type { PreviewConfigOptions } from '../types';
5
+ import type { ToolsLogger } from '@sap-ux/logger';
6
+ /**
7
+ * Extract the UI5 yaml configuration file name from the script.
8
+ *
9
+ * @param script - the content of the script from the package.json file
10
+ * @returns the UI5 yaml configuration file name or 'ui5.yaml' as default
11
+ */
12
+ export declare function extractYamlConfigFileName(script: string): string;
13
+ /**
14
+ * Processes the passed UI5 yaml configuration file and reads out the preview middleware configuration.
15
+ *
16
+ * If the preview middleware creation is not skipped and none is given, one will be created.
17
+ * The configuration for the preview middleware creation will be based on the parameters of the passed script.
18
+ *
19
+ * @param fs - file system reference
20
+ * @param basePath - base path to be used for the conversion
21
+ * @param ui5Yaml - the name of the UI5 yaml configuration file
22
+ * @param script - the content of the script
23
+ * @param skipPreviewMiddlewareCreation - (default: false) indicator if the preview middleware creation should be skipped if no preview middleware is configured.
24
+ */
25
+ export declare function processUi5YamlConfig(fs: Editor, basePath: string, ui5Yaml: string, script: string, skipPreviewMiddlewareCreation?: boolean): Promise<void>;
26
+ /**
27
+ * Creates a preview middleware configuration.
28
+ *
29
+ * It will sanitize the given preview middleware configuration and construct the flp configuration out of the given intent and path.
30
+ *
31
+ * @param previewMiddleware - the preview middleware configuration
32
+ * @param intent - the intent
33
+ * @param path - the flp path
34
+ * @returns the preview middleware configuration
35
+ */
36
+ export declare function updatePreviewMiddlewareConfig(previewMiddleware: CustomMiddleware<PreviewConfigOptions>, intent: FlpConfig['intent'] | undefined, path: string | undefined): CustomMiddleware<PreviewConfigOptions>;
37
+ /**
38
+ * Updates the preview middleware configurations according to the scripts they are being used in package.json.
39
+ *
40
+ * It will process all given UI5 configuration yaml files and check if the preview middleware configuration must be updated based on a given script.
41
+ * If a script is valid, the preview middleware configuration will be updated and the corresponding file renamed.
42
+ * UI5 configuration yaml files which are not used in any script will be sanitized.
43
+ *
44
+ * @param fs - file system reference
45
+ * @param basePath - base path to be used for the conversion
46
+ * @param logger logger to report info to the user
47
+ */
48
+ export declare function updatePreviewMiddlewareConfigs(fs: Editor, basePath: string, logger?: ToolsLogger): Promise<void>;
49
+ //# sourceMappingURL=ui5-yaml.d.ts.map
@@ -0,0 +1,234 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.extractYamlConfigFileName = extractYamlConfigFileName;
4
+ exports.processUi5YamlConfig = processUi5YamlConfig;
5
+ exports.updatePreviewMiddlewareConfig = updatePreviewMiddlewareConfig;
6
+ exports.updatePreviewMiddlewareConfigs = updatePreviewMiddlewareConfigs;
7
+ const path_1 = require("path");
8
+ const ui5_yaml_1 = require("../variants-config/ui5-yaml");
9
+ const package_json_1 = require("./package-json");
10
+ const project_access_1 = require("@sap-ux/project-access");
11
+ const utils_1 = require("../variants-config/utils");
12
+ const preview_files_1 = require("./preview-files");
13
+ const DEFAULT_FLP_PATH = '/test/flp.html';
14
+ const DEFAULT_INTENT = {
15
+ object: 'app',
16
+ action: 'preview'
17
+ };
18
+ /**
19
+ * Checks if a script can be converted based on the used UI5 yaml configuration file.
20
+ *
21
+ * A script can be converted when the used UI5 yaml configuration file exists and complies with the schema validation.
22
+ *
23
+ * @param ui5Yaml - the name of the UI5 yaml configuration file
24
+ * @param scriptName - the name of the script from the package.json file
25
+ * @param ui5YamlFileNames - the UI5 yaml configuration file names
26
+ * @param logger logger to report info to the user
27
+ * @returns indicator if the script is to be converted
28
+ */
29
+ function isUi5YamlToBeConverted(ui5Yaml, scriptName, ui5YamlFileNames, logger) {
30
+ if (!ui5YamlFileNames.includes(ui5Yaml)) {
31
+ logger?.warn(`Skipping script '${scriptName}', because the UI5 YAML configuration file, '${ui5Yaml}', could not be found.`);
32
+ return false;
33
+ }
34
+ return true;
35
+ }
36
+ /**
37
+ * Check if a UI5 yaml configuration file has already been converted based on another script.
38
+ *
39
+ * This is done to avoid overwriting of already converted UI5 yaml configurations.
40
+ *
41
+ * @param fs - file system reference
42
+ * @param basePath - base path to be used for the conversion
43
+ * @param ui5Yaml - the name of the UI5 yaml configuration file
44
+ * @param scriptName - the name of the script from the package.json file
45
+ * @param script - the content of the script from the package.json file
46
+ * @param logger logger to report info to the user
47
+ * @returns indicator if the UI5 yaml configuration file has already been converted
48
+ */
49
+ async function isUi5YamlAlreadyConverted(fs, basePath, ui5Yaml, scriptName, script, logger) {
50
+ if (Object.keys(fs.dump(basePath, (file) => {
51
+ return file.basename === ui5Yaml && file.state === 'modified';
52
+ })).length === 0) {
53
+ return false;
54
+ }
55
+ const flpPath = (await (0, utils_1.getPreviewMiddleware)(undefined, basePath, ui5Yaml, fs))
56
+ ?.configuration?.flp?.path;
57
+ const { path: scriptPath } = (0, package_json_1.extractUrlDetails)(script);
58
+ if (flpPath != scriptPath) {
59
+ logger?.warn(`Skipping script'${scriptName}', because another script also refers to UI5 YAML configuration file, '${ui5Yaml}'. Adjust the 'flp.path' property in the UI5 YAML configuration file to the correct endpoint or create a separate UI5 YAML configuration file for script '${scriptName}'. ${ui5Yaml} currently uses ${flpPath ?? DEFAULT_FLP_PATH} whereas script '${scriptName}' uses '${scriptPath}'.`);
60
+ }
61
+ else {
62
+ logger?.info(`Skipping script '${scriptName}', because the UI5 YAML configuration file '${ui5Yaml}' has already been adjusted based on another script.`);
63
+ }
64
+ return true;
65
+ }
66
+ /**
67
+ * Checks if the passed path is a FLP path.
68
+ *
69
+ * @param path - the path
70
+ * @param configuration - the preview configuration
71
+ * @returns indicator if the path is an FLP path
72
+ */
73
+ function pathIsFlpPath(path, configuration) {
74
+ if (!path) {
75
+ return false;
76
+ }
77
+ const isNotRtaEditorPath = configuration.rta?.editors?.every((editor) => editor.path !== path) ?? true;
78
+ const isNotTestPath = configuration.test?.every((test) => test.path !== path) ?? true;
79
+ return isNotRtaEditorPath && isNotTestPath;
80
+ }
81
+ /**
82
+ * Sanitizes the preview middleware configuration.
83
+ *
84
+ * In case of an outdated preview configuration, the following changes will be applied:
85
+ * - property 'ui5Theme' will be moved to 'flp.theme'.
86
+ * - no longer used property 'component' will be removed.
87
+ *
88
+ * @param previewMiddleware - the preview middleware
89
+ * @returns the sanitized preview middleware
90
+ */
91
+ function sanitizePreviewMiddleware(previewMiddleware) {
92
+ if (!(0, utils_1.isFioriToolsDeprecatedPreviewConfig)(previewMiddleware.configuration)) {
93
+ return previewMiddleware;
94
+ }
95
+ const ui5Theme = previewMiddleware.configuration.ui5Theme;
96
+ delete previewMiddleware.configuration;
97
+ if (!ui5Theme) {
98
+ return previewMiddleware;
99
+ }
100
+ const configuration = {};
101
+ configuration.flp = {};
102
+ configuration.flp.theme = ui5Theme;
103
+ previewMiddleware.configuration = configuration;
104
+ return previewMiddleware;
105
+ }
106
+ /**
107
+ * Extract the UI5 yaml configuration file name from the script.
108
+ *
109
+ * @param script - the content of the script from the package.json file
110
+ * @returns the UI5 yaml configuration file name or 'ui5.yaml' as default
111
+ */
112
+ function extractYamlConfigFileName(script) {
113
+ return / (?:--config|-c) (\S*)/.exec(script)?.[1] ?? project_access_1.FileName.Ui5Yaml;
114
+ }
115
+ /**
116
+ * Processes the passed UI5 yaml configuration file and reads out the preview middleware configuration.
117
+ *
118
+ * If the preview middleware creation is not skipped and none is given, one will be created.
119
+ * The configuration for the preview middleware creation will be based on the parameters of the passed script.
120
+ *
121
+ * @param fs - file system reference
122
+ * @param basePath - base path to be used for the conversion
123
+ * @param ui5Yaml - the name of the UI5 yaml configuration file
124
+ * @param script - the content of the script
125
+ * @param skipPreviewMiddlewareCreation - (default: false) indicator if the preview middleware creation should be skipped if no preview middleware is configured.
126
+ */
127
+ async function processUi5YamlConfig(fs, basePath, ui5Yaml, script, skipPreviewMiddlewareCreation = false) {
128
+ let ui5YamlConfig;
129
+ try {
130
+ ui5YamlConfig = await (0, project_access_1.readUi5Yaml)(basePath, ui5Yaml, fs, { validateSchema: true });
131
+ }
132
+ catch (error) {
133
+ throw new Error(`An error occurred when reading '${ui5Yaml}': ${error.message}`);
134
+ }
135
+ let previewMiddleware = await (0, utils_1.getPreviewMiddleware)(ui5YamlConfig);
136
+ if (skipPreviewMiddlewareCreation && !previewMiddleware) {
137
+ return;
138
+ }
139
+ if (!previewMiddleware) {
140
+ previewMiddleware = (0, ui5_yaml_1.createPreviewMiddlewareConfig)(fs, basePath);
141
+ }
142
+ const { path, intent } = (0, package_json_1.extractUrlDetails)(script);
143
+ previewMiddleware = updatePreviewMiddlewareConfig(previewMiddleware, intent, path);
144
+ ui5YamlConfig.updateCustomMiddleware(previewMiddleware);
145
+ const yamlPath = (0, path_1.join)(basePath, ui5Yaml);
146
+ fs.write(yamlPath, ui5YamlConfig.toString());
147
+ }
148
+ /**
149
+ * Creates a preview middleware configuration.
150
+ *
151
+ * It will sanitize the given preview middleware configuration and construct the flp configuration out of the given intent and path.
152
+ *
153
+ * @param previewMiddleware - the preview middleware configuration
154
+ * @param intent - the intent
155
+ * @param path - the flp path
156
+ * @returns the preview middleware configuration
157
+ */
158
+ function updatePreviewMiddlewareConfig(previewMiddleware, intent, path) {
159
+ const defaultIntent = `${DEFAULT_INTENT.object}-${DEFAULT_INTENT.action}`;
160
+ const newMiddlewareConfig = sanitizePreviewMiddleware(previewMiddleware);
161
+ //copy of configuration to avoid ending up with an empty configuration object in some cases
162
+ const configuration = { ...newMiddlewareConfig.configuration };
163
+ configuration.flp = configuration.flp ?? {};
164
+ let writeConfig = false;
165
+ //check path and respect defaults
166
+ if (pathIsFlpPath(path, configuration) && !path?.includes(DEFAULT_FLP_PATH)) {
167
+ configuration.flp.path = path;
168
+ writeConfig = true;
169
+ }
170
+ //check intent and respect defaults
171
+ if (intent && `${intent?.object}-${intent?.action}` !== defaultIntent) {
172
+ configuration.flp.intent = {
173
+ object: intent.object,
174
+ action: intent.action
175
+ };
176
+ writeConfig = true;
177
+ }
178
+ if (writeConfig) {
179
+ newMiddlewareConfig.configuration = configuration;
180
+ }
181
+ return newMiddlewareConfig;
182
+ }
183
+ /**
184
+ * Updates the preview middleware configurations according to the scripts they are being used in package.json.
185
+ *
186
+ * It will process all given UI5 configuration yaml files and check if the preview middleware configuration must be updated based on a given script.
187
+ * If a script is valid, the preview middleware configuration will be updated and the corresponding file renamed.
188
+ * UI5 configuration yaml files which are not used in any script will be sanitized.
189
+ *
190
+ * @param fs - file system reference
191
+ * @param basePath - base path to be used for the conversion
192
+ * @param logger logger to report info to the user
193
+ */
194
+ async function updatePreviewMiddlewareConfigs(fs, basePath, logger) {
195
+ const ui5YamlFileNames = await (0, project_access_1.getAllUi5YamlFileNames)(basePath, fs);
196
+ const unprocessedUi5YamlFileNames = [...ui5YamlFileNames];
197
+ const packageJsonPath = (0, path_1.join)(basePath, 'package.json');
198
+ const packageJson = fs.readJSON(packageJsonPath);
199
+ for (const [scriptName, script] of Object.entries(packageJson?.scripts ?? {})) {
200
+ if (!script || !(0, package_json_1.isValidPreviewScript)(scriptName, script)) {
201
+ continue;
202
+ }
203
+ const ui5Yaml = (0, path_1.basename)(extractYamlConfigFileName(script));
204
+ unprocessedUi5YamlFileNames.splice(unprocessedUi5YamlFileNames.indexOf(ui5Yaml), 1);
205
+ if (!isUi5YamlToBeConverted(ui5Yaml, scriptName, ui5YamlFileNames, logger) ||
206
+ (await isUi5YamlAlreadyConverted(fs, basePath, ui5Yaml, scriptName, script, logger))) {
207
+ continue;
208
+ }
209
+ try {
210
+ await processUi5YamlConfig(fs, basePath, ui5Yaml, script);
211
+ }
212
+ catch (error) {
213
+ logger?.warn(`Skipping script '${scriptName}', which refers to the UI5 YAML configuration file '${ui5Yaml}'. ${error.message}`);
214
+ continue;
215
+ }
216
+ const { path } = (0, package_json_1.extractUrlDetails)(script);
217
+ if (path) {
218
+ await (0, preview_files_1.renameSandbox)(fs, (0, path_1.join)(await (0, project_access_1.getWebappPath)(basePath), path), logger);
219
+ }
220
+ (0, package_json_1.ensurePreviewMiddlewareDependency)(packageJson, fs, packageJsonPath);
221
+ logger?.info(`The UI5 YAML configuration file '${ui5Yaml}', has been updated according to script, '${scriptName}'.`);
222
+ }
223
+ for (const ui5Yaml of unprocessedUi5YamlFileNames) {
224
+ //at least adjust deprecated preview config of unused ui5 yaml configurations
225
+ try {
226
+ await processUi5YamlConfig(fs, basePath, ui5Yaml, '', true);
227
+ }
228
+ catch (error) {
229
+ logger?.warn(`Skipping UI5 yaml configuration file '${ui5Yaml}'. ${error.mesage}`);
230
+ }
231
+ logger?.warn(`The UI5 YAML configuration file '${ui5Yaml}', is not used in any preview script. Outdated preview middleware will be adjusted, if necessary.`);
232
+ }
233
+ }
234
+ //# sourceMappingURL=ui5-yaml.js.map
@@ -5,7 +5,7 @@ import type { ToolsLogger } from '@sap-ux/logger';
5
5
  *
6
6
  * @param fs - mem-fs reference to be used for file access
7
7
  * @param basePath - path to application root, where package.json is
8
- * @param yamlPath - path to the ui5*.yaml file passed by cli
8
+ * @param yamlPath - path to the ui5*.yaml file
9
9
  * @param logger - logger
10
10
  * @returns Promise<void> - rejects in case variants management script can't be added to package.json
11
11
  */
@@ -10,7 +10,7 @@ const ERROR_MSG = `Script 'start-variants-management' cannot be written to packa
10
10
  *
11
11
  * @param fs - mem-fs reference to be used for file access
12
12
  * @param basePath - path to application root, where package.json is
13
- * @param yamlPath - path to the ui5*.yaml file passed by cli
13
+ * @param yamlPath - path to the ui5*.yaml file
14
14
  * @param logger - logger
15
15
  * @returns Promise<void> - rejects in case variants management script can't be added to package.json
16
16
  */
@@ -30,7 +30,7 @@ async function addVariantsManagementScript(fs, basePath, yamlPath, logger) {
30
30
  if (sapClient) {
31
31
  urlParameters['sap-client'] = sapClient;
32
32
  }
33
- const url = await (0, utils_1.getRTAUrl)(basePath, (0, utils_1.getUI5UrlParameters)(urlParameters), ui5YamlFileName);
33
+ const url = await (0, utils_1.getRTAUrl)(basePath, (0, utils_1.enhanceUrlParametersWithRta)(packageJson, urlParameters), ui5YamlFileName, fs);
34
34
  const serveCommand = await (0, utils_1.getRTAServe)(basePath, ui5YamlFileName, fs);
35
35
  if (!url) {
36
36
  throw new Error(`${ERROR_MSG} No RTA editor specified in ui5.yaml.`);
@@ -20,7 +20,7 @@ export declare function getEnhancedReloadMiddleware(yamlConfig: UI5Config): Prom
20
20
  */
21
21
  export declare function createPreviewMiddlewareConfig(fs: Editor, basePath: string): CustomMiddleware<PreviewConfigOptions>;
22
22
  /**
23
- * Checks the project for ui5.yaml files and reads out the configuration to update the preview and reload middlewares.
23
+ * Checks the project for ui5 configuration yaml files and reads the configuration to update the preview and reload middlewares.
24
24
  * If a reload middleware exists, then a delay of 300ms will be inserted and the preview middleware will be set afterward.
25
25
  *
26
26
  * @param fs - mem-fs reference to be used for file access
@@ -44,7 +44,7 @@ function createPreviewMiddlewareConfig(fs, basePath) {
44
44
  };
45
45
  }
46
46
  /**
47
- * Checks the project for ui5.yaml files and reads out the configuration to update the preview and reload middlewares.
47
+ * Checks the project for ui5 configuration yaml files and reads the configuration to update the preview and reload middlewares.
48
48
  * If a reload middleware exists, then a delay of 300ms will be inserted and the preview middleware will be set afterward.
49
49
  *
50
50
  * @param fs - mem-fs reference to be used for file access
@@ -54,7 +54,7 @@ function createPreviewMiddlewareConfig(fs, basePath) {
54
54
  */
55
55
  async function updateMiddlewares(fs, basePath, yamlPath, logger) {
56
56
  const ui5YamlFile = yamlPath ? (0, path_1.basename)(yamlPath) : project_access_1.FileName.Ui5Yaml;
57
- const ui5YamlConfig = await (0, project_access_1.readUi5Yaml)(basePath, ui5YamlFile);
57
+ const ui5YamlConfig = await (0, project_access_1.readUi5Yaml)(basePath, ui5YamlFile, fs);
58
58
  let previewMiddleware = await (0, utils_1.getPreviewMiddleware)(ui5YamlConfig);
59
59
  const reloadMiddleware = await getEnhancedReloadMiddleware(ui5YamlConfig);
60
60
  if (!previewMiddleware) {
@@ -1,6 +1,6 @@
1
1
  import type { Package } from '@sap-ux/project-access';
2
2
  import type { CustomMiddleware, UI5Config } from '@sap-ux/ui5-config';
3
- import type { PreviewConfigOptions } from '../types';
3
+ import type { PreviewConfigOptions, FioriToolsDeprecatedPreviewConfig } from '../types';
4
4
  import type { Editor } from 'mem-fs-editor';
5
5
  /**
6
6
  * Gets the preview middleware form the yamlConfig or provided path.
@@ -14,6 +14,13 @@ import type { Editor } from 'mem-fs-editor';
14
14
  * Rejects if neither yamlConfig nor basePath is provided or if the file can't be read
15
15
  */
16
16
  export declare function getPreviewMiddleware(yamlConfig?: UI5Config, basePath?: string, filename?: string, fs?: Editor): Promise<CustomMiddleware<PreviewConfigOptions> | undefined>;
17
+ /**
18
+ * Type guard to check if the given configuration is a deprecated preview middleware configuration.
19
+ *
20
+ * @param configuration preview middleware configuration
21
+ * @returns true, if a preview middleware configuration is deprecated
22
+ */
23
+ export declare function isFioriToolsDeprecatedPreviewConfig(configuration: PreviewConfigOptions | undefined): configuration is FioriToolsDeprecatedPreviewConfig;
17
24
  /**
18
25
  * Extracts sap client string from existing scripts in package.json.
19
26
  *
@@ -22,13 +29,21 @@ export declare function getPreviewMiddleware(yamlConfig?: UI5Config, basePath?:
22
29
  */
23
30
  export declare function getSapClientFromPackageJson(scripts: Package['scripts']): string | undefined;
24
31
  /**
25
- * Returns the UI5 url parameters.
26
- * This is needed for the UI5 run time adaptation.
32
+ * Extracts the version of the given dependency from the given package.json file.
27
33
  *
28
- * @param overwritingParams - parameters to be overwritten
29
- * @returns - UI5 url parameters
34
+ * @param packageJson - package.json file
35
+ * @param dependencyName - name of the (dev-)dependency
36
+ * @returns version of the dependency as an array of numbers
30
37
  */
31
- export declare function getUI5UrlParameters(overwritingParams?: Record<string, string>): string;
38
+ export declare function getDependencyVersion(packageJson: Package, dependencyName: string): number[] | undefined;
39
+ /**
40
+ * Enhances the given url parameters with the ones needed for the UI5 run time adaptation.
41
+ *
42
+ @param packageJson - package.json file
43
+ * @param existingParams - parameters to be enhanced
44
+ * @returns enhanced url parameters
45
+ */
46
+ export declare function enhanceUrlParametersWithRta(packageJson: Package, existingParams?: Record<string, string>): string;
32
47
  /**
33
48
  * Returns the serve command for the preview middleware configuration of the ui5.yaml file, if given.
34
49
  * If the fiori-tools-preview middleware is used, then the serve command will be 'fiori run'.
@@ -47,7 +62,8 @@ export declare function getRTAServe(basePath: string, yamlFileName: string, fs:
47
62
  * @param basePath - path to project root, where package.json and ui5.yaml is located
48
63
  * @param query - query to create fragment
49
64
  * @param yamlFileName - path of the ui5 yaml file
65
+ * @param fs - the memfs editor instance
50
66
  * @returns - review url parameters
51
67
  */
52
- export declare function getRTAUrl(basePath: string, query: string, yamlFileName: string): Promise<string | undefined>;
68
+ export declare function getRTAUrl(basePath: string, query: string, yamlFileName: string, fs?: Editor): Promise<string | undefined>;
53
69
  //# sourceMappingURL=utils.d.ts.map
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getPreviewMiddleware = getPreviewMiddleware;
4
+ exports.isFioriToolsDeprecatedPreviewConfig = isFioriToolsDeprecatedPreviewConfig;
4
5
  exports.getSapClientFromPackageJson = getSapClientFromPackageJson;
5
- exports.getUI5UrlParameters = getUI5UrlParameters;
6
+ exports.getDependencyVersion = getDependencyVersion;
7
+ exports.enhanceUrlParametersWithRta = enhanceUrlParametersWithRta;
6
8
  exports.getRTAServe = getRTAServe;
7
9
  exports.getRTAUrl = getRTAUrl;
8
10
  const project_access_1 = require("@sap-ux/project-access");
@@ -52,19 +54,53 @@ function getSapClientFromPackageJson(scripts) {
52
54
  return undefined;
53
55
  }
54
56
  /**
55
- * Returns the UI5 url parameters.
56
- * This is needed for the UI5 run time adaptation.
57
+ * Extracts the version of the given dependency from the given package.json file.
57
58
  *
58
- * @param overwritingParams - parameters to be overwritten
59
- * @returns - UI5 url parameters
59
+ * @param packageJson - package.json file
60
+ * @param dependencyName - name of the (dev-)dependency
61
+ * @returns version of the dependency as an array of numbers
60
62
  */
61
- function getUI5UrlParameters(overwritingParams = {}) {
62
- const parameters = {
63
- 'fiori-tools-rta-mode': 'true',
64
- 'sap-ui-rta-skip-flex-validation': 'true',
65
- 'sap-ui-xx-condense-changes': 'true'
66
- };
67
- return (0, querystring_1.stringify)(Object.assign(parameters, overwritingParams));
63
+ function getDependencyVersion(packageJson, dependencyName) {
64
+ return (packageJson?.devDependencies?.[dependencyName] ?? packageJson?.dependencies?.[dependencyName])
65
+ ?.split('.')
66
+ .map((versionPart) => parseInt(versionPart, 10));
67
+ }
68
+ /**
69
+ * Checks if the given version is less than the given major, minor and patch version.
70
+ *
71
+ * @param version - version to be checked
72
+ * @param major - major version to be compared with
73
+ * @param minor - minor version to be compared with
74
+ * @param patch - patch version to be compared with
75
+ * @returns true, if the given version is less than the given major, minor and patch version
76
+ */
77
+ function isVersionLessThan(version, major, minor, patch) {
78
+ if (!version) {
79
+ return undefined;
80
+ }
81
+ const [vMajor, vMinor, vPatch] = version;
82
+ return vMajor < major || (vMajor === major && (vMinor < minor || (vMinor === minor && vPatch < patch)));
83
+ }
84
+ /**
85
+ * Enhances the given url parameters with the ones needed for the UI5 run time adaptation.
86
+ *
87
+ @param packageJson - package.json file
88
+ * @param existingParams - parameters to be enhanced
89
+ * @returns enhanced url parameters
90
+ */
91
+ function enhanceUrlParametersWithRta(packageJson, existingParams = {}) {
92
+ const parameters = {};
93
+ const previewMiddlewareVersion = getDependencyVersion(packageJson, '@sap-ux/preview-middleware');
94
+ const uxUi5ToolingVersion = getDependencyVersion(packageJson, '@sap/ux-ui5-tooling');
95
+ if (isVersionLessThan(previewMiddlewareVersion, 0, 16, 89) ??
96
+ isVersionLessThan(uxUi5ToolingVersion, 1, 15, 4) ??
97
+ true) {
98
+ parameters['fiori-tools-rta-mode'] = 'true';
99
+ parameters['sap-ui-rta-skip-flex-validation'] = 'true';
100
+ parameters['sap-ui-xx-condense-changes'] = 'true';
101
+ parameters['sap-ui-xx-viewCache'] = 'false';
102
+ }
103
+ return (0, querystring_1.stringify)(Object.assign(parameters, existingParams));
68
104
  }
69
105
  /**
70
106
  * Returns the RTA mount point of the preview middleware configuration from the ui5.yaml file, if given.
@@ -117,12 +153,13 @@ async function getRTAServe(basePath, yamlFileName, fs) {
117
153
  * @param basePath - path to project root, where package.json and ui5.yaml is located
118
154
  * @param query - query to create fragment
119
155
  * @param yamlFileName - path of the ui5 yaml file
156
+ * @param fs - the memfs editor instance
120
157
  * @returns - review url parameters
121
158
  */
122
- async function getRTAUrl(basePath, query, yamlFileName) {
159
+ async function getRTAUrl(basePath, query, yamlFileName, fs) {
123
160
  let previewMiddleware;
124
161
  try {
125
- previewMiddleware = await getPreviewMiddleware(undefined, basePath, yamlFileName);
162
+ previewMiddleware = await getPreviewMiddleware(undefined, basePath, yamlFileName, fs);
126
163
  }
127
164
  catch (error) {
128
165
  throw new Error(`No ${yamlFileName} file found. ${error}`);
@@ -133,8 +170,9 @@ async function getRTAUrl(basePath, query, yamlFileName) {
133
170
  }
134
171
  const mountPoint = getRTAMountPoint(previewMiddleware?.configuration) ?? '/preview.html';
135
172
  const intent = getRTAIntent(previewMiddleware?.configuration) ?? '#app-preview';
173
+ const queryString = query ? '?' + query : '';
136
174
  return isFioriToolsDeprecatedPreviewConfig(previewMiddleware?.configuration)
137
- ? `${mountPoint}?${query}#preview-app`
138
- : `${mountPoint}?${query}${intent}`;
175
+ ? `${mountPoint}${queryString}#preview-app`
176
+ : `${mountPoint}${queryString}${intent}`;
139
177
  }
140
178
  //# sourceMappingURL=utils.js.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sap-ux/app-config-writer",
3
3
  "description": "Add or update configuration for SAP Fiori tools application",
4
- "version": "0.5.1",
4
+ "version": "0.5.4",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/SAP/open-ux-tools.git",
@@ -26,10 +26,10 @@
26
26
  "mem-fs": "2.1.0",
27
27
  "mem-fs-editor": "9.4.0",
28
28
  "prompts": "2.4.2",
29
- "@sap-ux/axios-extension": "1.17.4",
30
- "@sap-ux/btp-utils": "0.17.0",
29
+ "@sap-ux/axios-extension": "1.17.6",
30
+ "@sap-ux/btp-utils": "0.17.1",
31
31
  "@sap-ux/logger": "0.6.0",
32
- "@sap-ux/project-access": "1.28.8",
32
+ "@sap-ux/project-access": "1.28.9",
33
33
  "@sap-ux/store": "0.9.3",
34
34
  "@sap-ux/ui5-config": "0.26.0"
35
35
  },
@@ -40,7 +40,7 @@
40
40
  "@types/prompts": "2.4.4",
41
41
  "axios": "1.7.4",
42
42
  "nock": "13.4.0",
43
- "@sap-ux/preview-middleware": "0.16.136"
43
+ "@sap-ux/preview-middleware": "0.16.144"
44
44
  },
45
45
  "engines": {
46
46
  "node": ">=18.x"