@sap-ux/app-config-writer 0.4.42 → 0.4.44
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 +1 -0
- package/dist/index.js +3 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +1 -0
- package/dist/types/variantsConfig.d.ts +14 -0
- package/dist/types/variantsConfig.js +11 -0
- package/dist/variants-config/generateVariantsConfig.d.ts +13 -0
- package/dist/variants-config/generateVariantsConfig.js +25 -0
- package/dist/variants-config/index.d.ts +2 -0
- package/dist/variants-config/index.js +18 -0
- package/dist/variants-config/package-json.d.ts +13 -0
- package/dist/variants-config/package-json.js +43 -0
- package/dist/variants-config/ui5-yaml.d.ts +32 -0
- package/dist/variants-config/ui5-yaml.js +86 -0
- package/dist/variants-config/utils.d.ts +40 -0
- package/dist/variants-config/utils.js +127 -0
- package/package.json +4 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { getSmartLinksTargetFromPrompt, promptInboundNavigationConfig, validateText } from './prompt';
|
|
2
2
|
export { generateSmartLinksConfig } from './smartlinks-config';
|
|
3
3
|
export { generateInboundNavigationConfig } from './navigation-config';
|
|
4
|
+
export { generateVariantsConfig } from './variants-config';
|
|
4
5
|
//# 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.generateInboundNavigationConfig = exports.generateSmartLinksConfig = exports.validateText = exports.promptInboundNavigationConfig = exports.getSmartLinksTargetFromPrompt = void 0;
|
|
3
|
+
exports.generateVariantsConfig = exports.generateInboundNavigationConfig = exports.generateSmartLinksConfig = exports.validateText = exports.promptInboundNavigationConfig = 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
|
Object.defineProperty(exports, "promptInboundNavigationConfig", { enumerable: true, get: function () { return prompt_1.promptInboundNavigationConfig; } });
|
|
@@ -9,4 +9,6 @@ var smartlinks_config_1 = require("./smartlinks-config");
|
|
|
9
9
|
Object.defineProperty(exports, "generateSmartLinksConfig", { enumerable: true, get: function () { return smartlinks_config_1.generateSmartLinksConfig; } });
|
|
10
10
|
var navigation_config_1 = require("./navigation-config");
|
|
11
11
|
Object.defineProperty(exports, "generateInboundNavigationConfig", { enumerable: true, get: function () { return navigation_config_1.generateInboundNavigationConfig; } });
|
|
12
|
+
var variants_config_1 = require("./variants-config");
|
|
13
|
+
Object.defineProperty(exports, "generateVariantsConfig", { enumerable: true, get: function () { return variants_config_1.generateVariantsConfig; } });
|
|
12
14
|
//# sourceMappingURL=index.js.map
|
package/dist/types/index.d.ts
CHANGED
package/dist/types/index.js
CHANGED
|
@@ -15,5 +15,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./smartLinks"), exports);
|
|
18
|
+
__exportStar(require("./variantsConfig"), exports);
|
|
18
19
|
__exportStar(require("./navigation"), exports);
|
|
19
20
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { MiddlewareConfig as PreviewConfig } from '@sap-ux/preview-middleware';
|
|
2
|
+
export type FioriToolsDeprecatedPreviewConfig = {
|
|
3
|
+
component: string;
|
|
4
|
+
libs?: boolean;
|
|
5
|
+
ui5Theme?: string;
|
|
6
|
+
};
|
|
7
|
+
export type PreviewConfigOptions = FioriToolsDeprecatedPreviewConfig | PreviewConfig;
|
|
8
|
+
export declare enum MiddlewareConfigs {
|
|
9
|
+
FioriToolsPreview = "fiori-tools-preview",
|
|
10
|
+
PreviewMiddleware = "preview-middleware",
|
|
11
|
+
ReloadMiddleware = "reload-middleware",
|
|
12
|
+
FioriToolsAppreload = "fiori-tools-appreload"
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=variantsConfig.d.ts.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MiddlewareConfigs = void 0;
|
|
4
|
+
var MiddlewareConfigs;
|
|
5
|
+
(function (MiddlewareConfigs) {
|
|
6
|
+
MiddlewareConfigs["FioriToolsPreview"] = "fiori-tools-preview";
|
|
7
|
+
MiddlewareConfigs["PreviewMiddleware"] = "preview-middleware";
|
|
8
|
+
MiddlewareConfigs["ReloadMiddleware"] = "reload-middleware";
|
|
9
|
+
MiddlewareConfigs["FioriToolsAppreload"] = "fiori-tools-appreload";
|
|
10
|
+
})(MiddlewareConfigs || (exports.MiddlewareConfigs = MiddlewareConfigs = {}));
|
|
11
|
+
//# sourceMappingURL=variantsConfig.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Editor } from 'mem-fs-editor';
|
|
2
|
+
import type { ToolsLogger } from '@sap-ux/logger';
|
|
3
|
+
/**
|
|
4
|
+
* Add variants configuration to an app or project.
|
|
5
|
+
*
|
|
6
|
+
* @param basePath - the base path where the package.json and ui5.yaml is
|
|
7
|
+
* @param yamlPath - the path where the ui5.yaml is
|
|
8
|
+
* @param logger - logger
|
|
9
|
+
* @param fs - the memfs editor instance
|
|
10
|
+
* @returns Promise<Editor> - memfs editor instance with updated files
|
|
11
|
+
*/
|
|
12
|
+
export declare function generateVariantsConfig(basePath: string, yamlPath?: string, logger?: ToolsLogger, fs?: Editor): Promise<Editor>;
|
|
13
|
+
//# sourceMappingURL=generateVariantsConfig.d.ts.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateVariantsConfig = generateVariantsConfig;
|
|
4
|
+
const mem_fs_editor_1 = require("mem-fs-editor");
|
|
5
|
+
const mem_fs_1 = require("mem-fs");
|
|
6
|
+
const ui5_yaml_1 = require("./ui5-yaml");
|
|
7
|
+
const package_json_1 = require("./package-json");
|
|
8
|
+
/**
|
|
9
|
+
* Add variants configuration to an app or project.
|
|
10
|
+
*
|
|
11
|
+
* @param basePath - the base path where the package.json and ui5.yaml is
|
|
12
|
+
* @param yamlPath - the path where the ui5.yaml is
|
|
13
|
+
* @param logger - logger
|
|
14
|
+
* @param fs - the memfs editor instance
|
|
15
|
+
* @returns Promise<Editor> - memfs editor instance with updated files
|
|
16
|
+
*/
|
|
17
|
+
async function generateVariantsConfig(basePath, yamlPath, logger, fs) {
|
|
18
|
+
if (!fs) {
|
|
19
|
+
fs = (0, mem_fs_editor_1.create)((0, mem_fs_1.create)());
|
|
20
|
+
}
|
|
21
|
+
await (0, package_json_1.addVariantsManagementScript)(fs, basePath, yamlPath, logger);
|
|
22
|
+
await (0, ui5_yaml_1.updateMiddlewares)(fs, basePath, yamlPath, logger);
|
|
23
|
+
return fs;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=generateVariantsConfig.js.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./generateVariantsConfig"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Editor } from 'mem-fs-editor';
|
|
2
|
+
import type { ToolsLogger } from '@sap-ux/logger';
|
|
3
|
+
/**
|
|
4
|
+
* Add the start-variants-management script to the package.json.
|
|
5
|
+
*
|
|
6
|
+
* @param fs - mem-fs reference to be used for file access
|
|
7
|
+
* @param basePath - path to application root, where package.json is
|
|
8
|
+
* @param yamlPath - path to the ui5*.yaml file
|
|
9
|
+
* @param logger - logger
|
|
10
|
+
* @returns Promise<void> - rejects in case variants management script can't be added to package.json
|
|
11
|
+
*/
|
|
12
|
+
export declare function addVariantsManagementScript(fs: Editor, basePath: string, yamlPath?: string, logger?: ToolsLogger): Promise<void>;
|
|
13
|
+
//# sourceMappingURL=package-json.d.ts.map
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addVariantsManagementScript = addVariantsManagementScript;
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
const utils_1 = require("./utils");
|
|
6
|
+
const ERROR_MSG = `Script 'start-variants-management' cannot be written to package.json.`;
|
|
7
|
+
/**
|
|
8
|
+
* Add the start-variants-management script to the package.json.
|
|
9
|
+
*
|
|
10
|
+
* @param fs - mem-fs reference to be used for file access
|
|
11
|
+
* @param basePath - path to application root, where package.json is
|
|
12
|
+
* @param yamlPath - path to the ui5*.yaml file
|
|
13
|
+
* @param logger - logger
|
|
14
|
+
* @returns Promise<void> - rejects in case variants management script can't be added to package.json
|
|
15
|
+
*/
|
|
16
|
+
async function addVariantsManagementScript(fs, basePath, yamlPath, logger) {
|
|
17
|
+
const packageJsonPath = (0, path_1.join)(basePath, 'package.json');
|
|
18
|
+
const packageJson = fs.readJSON(packageJsonPath);
|
|
19
|
+
if (!packageJson) {
|
|
20
|
+
throw new Error(`${ERROR_MSG} File 'package.json' not found at ${basePath}`);
|
|
21
|
+
}
|
|
22
|
+
if (packageJson?.scripts?.['start-variants-management']) {
|
|
23
|
+
throw new Error(`${ERROR_MSG} Script already exists.`);
|
|
24
|
+
}
|
|
25
|
+
if (!packageJson.scripts) {
|
|
26
|
+
logger?.warn(`File 'package.json' does not contain a script section. Script section added.`);
|
|
27
|
+
packageJson.scripts = {};
|
|
28
|
+
}
|
|
29
|
+
const urlParameters = {};
|
|
30
|
+
const sapClient = (0, utils_1.getSapClientFromPackageJson)(packageJson.scripts);
|
|
31
|
+
if (sapClient) {
|
|
32
|
+
urlParameters['sap-client'] = sapClient;
|
|
33
|
+
}
|
|
34
|
+
const url = await (0, utils_1.getRTAUrl)(basePath, (0, utils_1.getUI5UrlParameters)(urlParameters), yamlPath);
|
|
35
|
+
if (!url) {
|
|
36
|
+
throw new Error(`${ERROR_MSG} No RTA editor specified in ui5.yaml.`);
|
|
37
|
+
}
|
|
38
|
+
packageJson.scripts['start-variants-management'] = `fiori run --open "${url}"`;
|
|
39
|
+
fs.writeJSON(packageJsonPath, packageJson);
|
|
40
|
+
logger?.debug(`Script 'start-variants-management' written to 'package.json'.`);
|
|
41
|
+
return Promise.resolve();
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=package-json.js.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Editor } from 'mem-fs-editor';
|
|
2
|
+
import type { ToolsLogger } from '@sap-ux/logger';
|
|
3
|
+
import type { PreviewConfigOptions } from '../types';
|
|
4
|
+
import type { CustomMiddleware, FioriAppReloadConfig, UI5Config } from '@sap-ux/ui5-config';
|
|
5
|
+
/**
|
|
6
|
+
* Gets the reload middleware form the provided yamlConfig.
|
|
7
|
+
* The middleware can either be named 'fiori-tools-appreload' or 'reload-middleware'.
|
|
8
|
+
* If the middleware is found, a delay of 300ms will be inserted.
|
|
9
|
+
*
|
|
10
|
+
* @param yamlConfig - the yaml configuration to use
|
|
11
|
+
* @returns reload middleware configuration if found or undefined
|
|
12
|
+
*/
|
|
13
|
+
export declare function getEnhancedReloadMiddleware(yamlConfig: UI5Config): Promise<CustomMiddleware<FioriAppReloadConfig> | undefined>;
|
|
14
|
+
/**
|
|
15
|
+
* Creates a preview middleware configuration based on the presence of the @sap/ux-ui5-tooling dependency.
|
|
16
|
+
*
|
|
17
|
+
* @param fs - mem-fs reference to be used for file access
|
|
18
|
+
* @param basePath - path to project root, where package.json and ui5.yaml is
|
|
19
|
+
* @returns 'fiori-tools-preview' or 'preview-middleware' configuration
|
|
20
|
+
*/
|
|
21
|
+
export declare function createPreviewMiddlewareConfig(fs: Editor, basePath: string): CustomMiddleware<PreviewConfigOptions>;
|
|
22
|
+
/**
|
|
23
|
+
* Checks the project for ui5.yaml files and reads out the configuration to update the preview and reload middlewares.
|
|
24
|
+
* If a reload middleware exists, then a delay of 300ms will be inserted and the preview middleware will be set afterward.
|
|
25
|
+
*
|
|
26
|
+
* @param fs - mem-fs reference to be used for file access
|
|
27
|
+
* @param basePath - path to project root, where package.json and ui5.yaml is
|
|
28
|
+
* @param yamlPath - the path where the ui5.yaml is
|
|
29
|
+
* @param logger - logger
|
|
30
|
+
*/
|
|
31
|
+
export declare function updateMiddlewares(fs: Editor, basePath: string, yamlPath?: string, logger?: ToolsLogger): Promise<void>;
|
|
32
|
+
//# sourceMappingURL=ui5-yaml.d.ts.map
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getEnhancedReloadMiddleware = getEnhancedReloadMiddleware;
|
|
4
|
+
exports.createPreviewMiddlewareConfig = createPreviewMiddlewareConfig;
|
|
5
|
+
exports.updateMiddlewares = updateMiddlewares;
|
|
6
|
+
const path_1 = require("path");
|
|
7
|
+
const types_1 = require("../types");
|
|
8
|
+
const project_access_1 = require("@sap-ux/project-access");
|
|
9
|
+
const utils_1 = require("./utils");
|
|
10
|
+
/**
|
|
11
|
+
* Gets the reload middleware form the provided yamlConfig.
|
|
12
|
+
* The middleware can either be named 'fiori-tools-appreload' or 'reload-middleware'.
|
|
13
|
+
* If the middleware is found, a delay of 300ms will be inserted.
|
|
14
|
+
*
|
|
15
|
+
* @param yamlConfig - the yaml configuration to use
|
|
16
|
+
* @returns reload middleware configuration if found or undefined
|
|
17
|
+
*/
|
|
18
|
+
async function getEnhancedReloadMiddleware(yamlConfig) {
|
|
19
|
+
const reloadMiddleware = yamlConfig.findCustomMiddleware(types_1.MiddlewareConfigs.FioriToolsAppreload) ??
|
|
20
|
+
yamlConfig.findCustomMiddleware(types_1.MiddlewareConfigs.ReloadMiddleware);
|
|
21
|
+
if (!reloadMiddleware) {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
if (!reloadMiddleware?.configuration?.delay) {
|
|
25
|
+
reloadMiddleware.configuration = { ...reloadMiddleware.configuration, delay: 300 };
|
|
26
|
+
}
|
|
27
|
+
return reloadMiddleware;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Creates a preview middleware configuration based on the presence of the @sap/ux-ui5-tooling dependency.
|
|
31
|
+
*
|
|
32
|
+
* @param fs - mem-fs reference to be used for file access
|
|
33
|
+
* @param basePath - path to project root, where package.json and ui5.yaml is
|
|
34
|
+
* @returns 'fiori-tools-preview' or 'preview-middleware' configuration
|
|
35
|
+
*/
|
|
36
|
+
function createPreviewMiddlewareConfig(fs, basePath) {
|
|
37
|
+
const packageJsonPath = (0, path_1.join)(basePath, 'package.json');
|
|
38
|
+
const packageJson = fs.readJSON(packageJsonPath);
|
|
39
|
+
return {
|
|
40
|
+
name: packageJson?.devDependencies?.['@sap/ux-ui5-tooling']
|
|
41
|
+
? types_1.MiddlewareConfigs.FioriToolsPreview
|
|
42
|
+
: types_1.MiddlewareConfigs.PreviewMiddleware,
|
|
43
|
+
afterMiddleware: 'compression'
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Checks the project for ui5.yaml files and reads out the configuration to update the preview and reload middlewares.
|
|
48
|
+
* If a reload middleware exists, then a delay of 300ms will be inserted and the preview middleware will be set afterward.
|
|
49
|
+
*
|
|
50
|
+
* @param fs - mem-fs reference to be used for file access
|
|
51
|
+
* @param basePath - path to project root, where package.json and ui5.yaml is
|
|
52
|
+
* @param yamlPath - the path where the ui5.yaml is
|
|
53
|
+
* @param logger - logger
|
|
54
|
+
*/
|
|
55
|
+
async function updateMiddlewares(fs, basePath, yamlPath, logger) {
|
|
56
|
+
const ui5Yamls = [project_access_1.FileName.Ui5Yaml, project_access_1.FileName.Ui5MockYaml, project_access_1.FileName.Ui5LocalYaml];
|
|
57
|
+
if (yamlPath) {
|
|
58
|
+
ui5Yamls.unshift((0, path_1.basename)(yamlPath));
|
|
59
|
+
}
|
|
60
|
+
for (const ui5Yaml of ui5Yamls) {
|
|
61
|
+
let ui5YamlConfig;
|
|
62
|
+
try {
|
|
63
|
+
ui5YamlConfig = await (0, project_access_1.readUi5Yaml)(basePath, ui5Yaml);
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
logger?.debug(error.message);
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
let previewMiddleware = await (0, utils_1.getPreviewMiddleware)(ui5YamlConfig);
|
|
70
|
+
if (!previewMiddleware) {
|
|
71
|
+
logger?.warn(`No preview middleware found in ${ui5Yaml}. Preview middleware will be added.`);
|
|
72
|
+
previewMiddleware = createPreviewMiddlewareConfig(fs, basePath);
|
|
73
|
+
}
|
|
74
|
+
const reloadMiddleware = await getEnhancedReloadMiddleware(ui5YamlConfig);
|
|
75
|
+
if (reloadMiddleware) {
|
|
76
|
+
previewMiddleware.afterMiddleware = reloadMiddleware.name;
|
|
77
|
+
ui5YamlConfig.updateCustomMiddleware(reloadMiddleware);
|
|
78
|
+
logger?.debug(`Updated reload middleware in ${ui5Yaml}.`);
|
|
79
|
+
}
|
|
80
|
+
ui5YamlConfig.updateCustomMiddleware(previewMiddleware);
|
|
81
|
+
const yamlPath = (0, path_1.join)(basePath, ui5Yaml);
|
|
82
|
+
fs.write(yamlPath, ui5YamlConfig.toString());
|
|
83
|
+
logger?.debug(`Updated preview middleware in ${ui5Yaml}.`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=ui5-yaml.js.map
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { Package } from '@sap-ux/project-access';
|
|
2
|
+
import type { CustomMiddleware, UI5Config } from '@sap-ux/ui5-config';
|
|
3
|
+
import type { PreviewConfigOptions } from '../types';
|
|
4
|
+
/**
|
|
5
|
+
* Gets the preview middleware form the yamlConfig or provided path.
|
|
6
|
+
* The middleware can either be named 'fiori-tools-preview' or 'preview-middleware'.
|
|
7
|
+
*
|
|
8
|
+
* @param yamlConfig - the yaml configuration to use; if not provided, the file will be read with the provided basePath and filename
|
|
9
|
+
* @param basePath - path to project root, where ui5.yaml is located
|
|
10
|
+
* @param filename - name of the ui5 yaml file to read from basePath; default is 'ui5.yaml'
|
|
11
|
+
* @returns preview middleware configuration if found<br>
|
|
12
|
+
* Rejects if neither yamlConfig nor basePath is provided or if the file can't be read
|
|
13
|
+
*/
|
|
14
|
+
export declare function getPreviewMiddleware(yamlConfig?: UI5Config, basePath?: string, filename?: string): Promise<CustomMiddleware<PreviewConfigOptions> | undefined>;
|
|
15
|
+
/**
|
|
16
|
+
* Extracts sap client string from existing scripts in package.json.
|
|
17
|
+
*
|
|
18
|
+
* @param scripts - script section of the package.json
|
|
19
|
+
* @returns sap client
|
|
20
|
+
*/
|
|
21
|
+
export declare function getSapClientFromPackageJson(scripts: Package['scripts']): string | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* Returns the UI5 url parameters.
|
|
24
|
+
* This is needed for the UI5 run time adaptation.
|
|
25
|
+
*
|
|
26
|
+
* @param overwritingParams - parameters to be overwritten
|
|
27
|
+
* @returns - UI5 url parameters
|
|
28
|
+
*/
|
|
29
|
+
export declare function getUI5UrlParameters(overwritingParams?: Record<string, string>): string;
|
|
30
|
+
/**
|
|
31
|
+
* Returns the url for variants management in RTA mode.
|
|
32
|
+
* The url consist of a specified mount point and intent given from the ui5.yaml file as well as parameters for the RTA mode.
|
|
33
|
+
*
|
|
34
|
+
* @param basePath - path to project root, where package.json and ui5.yaml is located
|
|
35
|
+
* @param query - query to create fragment
|
|
36
|
+
* @param yamlPath - path of the ui5 yaml file provided by cli'
|
|
37
|
+
* @returns - review url parameters
|
|
38
|
+
*/
|
|
39
|
+
export declare function getRTAUrl(basePath: string, query: string, yamlPath?: string): Promise<string | undefined>;
|
|
40
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPreviewMiddleware = getPreviewMiddleware;
|
|
4
|
+
exports.getSapClientFromPackageJson = getSapClientFromPackageJson;
|
|
5
|
+
exports.getUI5UrlParameters = getUI5UrlParameters;
|
|
6
|
+
exports.getRTAUrl = getRTAUrl;
|
|
7
|
+
const project_access_1 = require("@sap-ux/project-access");
|
|
8
|
+
const types_1 = require("../types");
|
|
9
|
+
const querystring_1 = require("querystring");
|
|
10
|
+
const path_1 = require("path");
|
|
11
|
+
/**
|
|
12
|
+
* Gets the preview middleware form the yamlConfig or provided path.
|
|
13
|
+
* The middleware can either be named 'fiori-tools-preview' or 'preview-middleware'.
|
|
14
|
+
*
|
|
15
|
+
* @param yamlConfig - the yaml configuration to use; if not provided, the file will be read with the provided basePath and filename
|
|
16
|
+
* @param basePath - path to project root, where ui5.yaml is located
|
|
17
|
+
* @param filename - name of the ui5 yaml file to read from basePath; default is 'ui5.yaml'
|
|
18
|
+
* @returns preview middleware configuration if found<br>
|
|
19
|
+
* Rejects if neither yamlConfig nor basePath is provided or if the file can't be read
|
|
20
|
+
*/
|
|
21
|
+
async function getPreviewMiddleware(yamlConfig, basePath, filename = project_access_1.FileName.Ui5Yaml) {
|
|
22
|
+
if (!basePath && !yamlConfig) {
|
|
23
|
+
throw new Error('Either base path or yaml config must be provided.');
|
|
24
|
+
}
|
|
25
|
+
yamlConfig = yamlConfig ?? (await (0, project_access_1.readUi5Yaml)(basePath, filename));
|
|
26
|
+
return (yamlConfig.findCustomMiddleware(types_1.MiddlewareConfigs.FioriToolsPreview) ??
|
|
27
|
+
yamlConfig.findCustomMiddleware(types_1.MiddlewareConfigs.PreviewMiddleware));
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Type guard to check if the given configuration is a deprecated preview middleware configuration.
|
|
31
|
+
*
|
|
32
|
+
* @param configuration preview middleware configuration
|
|
33
|
+
* @returns true, if a preview middleware configuration is deprecated
|
|
34
|
+
*/
|
|
35
|
+
function isFioriToolsDeprecatedPreviewConfig(configuration) {
|
|
36
|
+
return configuration?.component !== undefined;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Extracts sap client string from existing scripts in package.json.
|
|
40
|
+
*
|
|
41
|
+
* @param scripts - script section of the package.json
|
|
42
|
+
* @returns sap client
|
|
43
|
+
*/
|
|
44
|
+
function getSapClientFromPackageJson(scripts) {
|
|
45
|
+
for (const value of Object.values(scripts)) {
|
|
46
|
+
const match = value?.match(/sap-client=(\d{3})/);
|
|
47
|
+
if (match) {
|
|
48
|
+
return match[1];
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Returns the UI5 url parameters.
|
|
55
|
+
* This is needed for the UI5 run time adaptation.
|
|
56
|
+
*
|
|
57
|
+
* @param overwritingParams - parameters to be overwritten
|
|
58
|
+
* @returns - UI5 url parameters
|
|
59
|
+
*/
|
|
60
|
+
function getUI5UrlParameters(overwritingParams = {}) {
|
|
61
|
+
const parameters = {
|
|
62
|
+
'fiori-tools-rta-mode': 'true',
|
|
63
|
+
'sap-ui-rta-skip-flex-validation': 'true',
|
|
64
|
+
'sap-ui-xx-condense-changes': 'true'
|
|
65
|
+
};
|
|
66
|
+
return (0, querystring_1.stringify)(Object.assign(parameters, overwritingParams));
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Returns the RTA mount point of the preview middleware configuration from the ui5.yaml file, if given.
|
|
70
|
+
*
|
|
71
|
+
* @param previewMiddlewareConfig - configuration of the preview middleware
|
|
72
|
+
* @returns - RTA mount point or undefined
|
|
73
|
+
*/
|
|
74
|
+
function getRTAMountPoint(previewMiddlewareConfig) {
|
|
75
|
+
if (!isFioriToolsDeprecatedPreviewConfig(previewMiddlewareConfig) && previewMiddlewareConfig?.rta?.editors) {
|
|
76
|
+
const editors = previewMiddlewareConfig.rta.editors;
|
|
77
|
+
for (const editor of editors) {
|
|
78
|
+
if (!('developerMode' in editor)) {
|
|
79
|
+
return editor.path;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return undefined;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Returns the intent of the preview middleware configuration from the ui5.yaml file, if given.
|
|
87
|
+
*
|
|
88
|
+
* @param previewMiddlewareConfig - configuration of the preview middleware
|
|
89
|
+
* @returns - preview intent or undefined
|
|
90
|
+
*/
|
|
91
|
+
function getRTAIntent(previewMiddlewareConfig) {
|
|
92
|
+
if (isFioriToolsDeprecatedPreviewConfig(previewMiddlewareConfig)) {
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
95
|
+
const intent = previewMiddlewareConfig?.flp?.intent;
|
|
96
|
+
return intent ? `#${intent.object}-${intent.action}` : undefined;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Returns the url for variants management in RTA mode.
|
|
100
|
+
* The url consist of a specified mount point and intent given from the ui5.yaml file as well as parameters for the RTA mode.
|
|
101
|
+
*
|
|
102
|
+
* @param basePath - path to project root, where package.json and ui5.yaml is located
|
|
103
|
+
* @param query - query to create fragment
|
|
104
|
+
* @param yamlPath - path of the ui5 yaml file provided by cli'
|
|
105
|
+
* @returns - review url parameters
|
|
106
|
+
*/
|
|
107
|
+
async function getRTAUrl(basePath, query, yamlPath) {
|
|
108
|
+
let previewMiddleware;
|
|
109
|
+
let fileName = '';
|
|
110
|
+
try {
|
|
111
|
+
fileName = yamlPath ? (0, path_1.basename)(yamlPath) : project_access_1.FileName.Ui5Yaml;
|
|
112
|
+
previewMiddleware = await getPreviewMiddleware(undefined, basePath, fileName);
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
throw new Error(`No ${fileName} file found. ${error}`);
|
|
116
|
+
}
|
|
117
|
+
if (previewMiddleware?.name === types_1.MiddlewareConfigs.PreviewMiddleware &&
|
|
118
|
+
!getRTAMountPoint(previewMiddleware?.configuration)) {
|
|
119
|
+
return undefined;
|
|
120
|
+
}
|
|
121
|
+
const mountPoint = getRTAMountPoint(previewMiddleware?.configuration) ?? '/preview.html';
|
|
122
|
+
const intent = getRTAIntent(previewMiddleware?.configuration) ?? '#app-preview';
|
|
123
|
+
return isFioriToolsDeprecatedPreviewConfig(previewMiddleware?.configuration)
|
|
124
|
+
? `${mountPoint}?${query}#preview-app`
|
|
125
|
+
: `${mountPoint}?${query}${intent}`;
|
|
126
|
+
}
|
|
127
|
+
//# 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.4.
|
|
4
|
+
"version": "0.4.44",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "https://github.com/SAP/open-ux-tools.git",
|
|
@@ -26,7 +26,7 @@
|
|
|
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.16.
|
|
29
|
+
"@sap-ux/axios-extension": "1.16.7",
|
|
30
30
|
"@sap-ux/btp-utils": "0.15.2",
|
|
31
31
|
"@sap-ux/logger": "0.6.0",
|
|
32
32
|
"@sap-ux/project-access": "1.28.2",
|
|
@@ -39,7 +39,8 @@
|
|
|
39
39
|
"@types/mem-fs-editor": "7.0.1",
|
|
40
40
|
"@types/prompts": "2.4.4",
|
|
41
41
|
"axios": "1.7.4",
|
|
42
|
-
"nock": "13.4.0"
|
|
42
|
+
"nock": "13.4.0",
|
|
43
|
+
"@sap-ux/preview-middleware": "0.16.92"
|
|
43
44
|
},
|
|
44
45
|
"engines": {
|
|
45
46
|
"node": ">=18.x"
|