@sap-ux/app-config-writer 0.5.28 → 0.5.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import type { Editor } from 'mem-fs-editor';
|
|
2
2
|
import type { ToolsLogger } from '@sap-ux/logger';
|
|
3
|
-
import type { Package } from '@sap-ux/project-access';
|
|
4
3
|
import type { FlpConfig } from '@sap-ux/preview-middleware';
|
|
4
|
+
import type { Script } from './ui5-yaml';
|
|
5
5
|
/**
|
|
6
6
|
* Ensures that the @sap/ux-ui5-tooling or @sap-ux/preview-middleware dependency exists in the package.json.
|
|
7
7
|
*
|
|
8
8
|
* If none dependency is given, the @sap-ux/preview-middleware will be added as a devDependency.
|
|
9
9
|
*
|
|
10
|
-
* @param packageJson - the package.json file content
|
|
11
10
|
* @param fs - file system reference
|
|
12
|
-
* @param
|
|
11
|
+
* @param basePath - base path to be used for the conversion
|
|
13
12
|
*/
|
|
14
|
-
export declare function ensurePreviewMiddlewareDependency(
|
|
13
|
+
export declare function ensurePreviewMiddlewareDependency(fs: Editor, basePath: string): void;
|
|
15
14
|
/**
|
|
16
15
|
* Extracts the URL details from a given script.
|
|
17
16
|
*
|
|
@@ -36,12 +35,11 @@ export declare function extractUrlDetails(script: string): {
|
|
|
36
35
|
* - must not be 'start-variants-management'
|
|
37
36
|
* - must not be 'start-control-property-editor'.
|
|
38
37
|
*
|
|
39
|
-
* @param
|
|
40
|
-
* @param script - the content of the script from the package.json file
|
|
38
|
+
* @param script - the script from the package.json file
|
|
41
39
|
* @param convertTests - indicator if test suite and test runner should be included in the conversion (default: false)
|
|
42
40
|
* @returns indicator if the script is valid
|
|
43
41
|
*/
|
|
44
|
-
export declare function isValidPreviewScript(
|
|
42
|
+
export declare function isValidPreviewScript(script: Script, convertTests?: boolean): boolean;
|
|
45
43
|
/**
|
|
46
44
|
* Updates the variants creation script in package.json if needed.
|
|
47
45
|
*
|
|
@@ -12,11 +12,12 @@ const variants_config_1 = require("../variants-config");
|
|
|
12
12
|
*
|
|
13
13
|
* If none dependency is given, the @sap-ux/preview-middleware will be added as a devDependency.
|
|
14
14
|
*
|
|
15
|
-
* @param packageJson - the package.json file content
|
|
16
15
|
* @param fs - file system reference
|
|
17
|
-
* @param
|
|
16
|
+
* @param basePath - base path to be used for the conversion
|
|
18
17
|
*/
|
|
19
|
-
function ensurePreviewMiddlewareDependency(
|
|
18
|
+
function ensurePreviewMiddlewareDependency(fs, basePath) {
|
|
19
|
+
const packageJsonPath = (0, path_1.join)(basePath, 'package.json');
|
|
20
|
+
const packageJson = fs.readJSON(packageJsonPath);
|
|
20
21
|
if (!packageJson) {
|
|
21
22
|
return;
|
|
22
23
|
}
|
|
@@ -67,17 +68,16 @@ function extractUrlDetails(script) {
|
|
|
67
68
|
* - must not be 'start-variants-management'
|
|
68
69
|
* - must not be 'start-control-property-editor'.
|
|
69
70
|
*
|
|
70
|
-
* @param
|
|
71
|
-
* @param script - the content of the script from the package.json file
|
|
71
|
+
* @param script - the script from the package.json file
|
|
72
72
|
* @param convertTests - indicator if test suite and test runner should be included in the conversion (default: false)
|
|
73
73
|
* @returns indicator if the script is valid
|
|
74
74
|
*/
|
|
75
|
-
function isValidPreviewScript(
|
|
76
|
-
const isValidScriptName =
|
|
75
|
+
function isValidPreviewScript(script, convertTests = false) {
|
|
76
|
+
const isValidScriptName = script.name != 'start-variants-management' && script.name != 'start-control-property-editor';
|
|
77
77
|
//eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
78
|
-
const startsWebServer = !!(script
|
|
79
|
-
const { path } = extractUrlDetails(script
|
|
80
|
-
const opensTest = (0, ui5_yaml_1.isTestPath)(
|
|
78
|
+
const startsWebServer = !!(script.value.includes('ui5 serve') || script.value.includes('fiori run'));
|
|
79
|
+
const { path } = extractUrlDetails(script.value);
|
|
80
|
+
const opensTest = (0, ui5_yaml_1.isTestPath)(script ?? '');
|
|
81
81
|
const opensIndexHtml = path === 'index.html';
|
|
82
82
|
//tests are only relevant if the conversion of test runners is excluded
|
|
83
83
|
return isValidScriptName && startsWebServer && !opensIndexHtml && (convertTests ? true : !opensTest);
|
|
@@ -71,6 +71,10 @@ async function checkPrerequisites(basePath, fs, convertTests = false, logger) {
|
|
|
71
71
|
if (convertTests && (packageJson?.devDependencies?.['karma-ui5'] ?? packageJson?.dependencies?.['karma-ui5'])) {
|
|
72
72
|
logger?.warn("This app seems to use Karma as a test runner. Please note that the converter does not convert any Karma configuration files. Please update your karma configuration ('ui5.configPath' and 'ui5.testpage') according to the new virtual endpoints after the conversion.");
|
|
73
73
|
}
|
|
74
|
+
if (convertTests &&
|
|
75
|
+
(packageJson?.devDependencies?.['wdio-qunit-service'] ?? packageJson?.dependencies?.['wdio-qunit-service'])) {
|
|
76
|
+
logger?.warn('This app seems to use the WebdriverIO QUnit Service as a test runner. Please note that the converter does not convert any WebdriverIO configuration files. Please update your WebdriverIO QUnit Service test paths according to the new virtual endpoints after the conversion.');
|
|
77
|
+
}
|
|
74
78
|
return prerequisitesMet;
|
|
75
79
|
}
|
|
76
80
|
//# sourceMappingURL=prerequisites.js.map
|
|
@@ -1,21 +1,40 @@
|
|
|
1
1
|
import type { CustomMiddleware } from '@sap-ux/ui5-config';
|
|
2
2
|
import type { Editor } from 'mem-fs-editor';
|
|
3
|
-
import type {
|
|
3
|
+
import type { MiddlewareConfig as PreviewConfig, TestConfig } from '@sap-ux/preview-middleware';
|
|
4
4
|
import type { PreviewConfigOptions } from '../types';
|
|
5
5
|
import type { ToolsLogger } from '@sap-ux/logger';
|
|
6
6
|
type ArrayElement<ArrayType extends readonly unknown[]> = ArrayType[number];
|
|
7
7
|
type PreviewTestConfig = ArrayElement<Required<PreviewConfig>['test']>;
|
|
8
|
+
export type Script = {
|
|
9
|
+
name: string;
|
|
10
|
+
value: string;
|
|
11
|
+
};
|
|
8
12
|
export declare const TEST_CONFIG_DEFAULTS: Record<string, Readonly<Required<PreviewTestConfig>>>;
|
|
9
13
|
/**
|
|
10
14
|
* Check if the path is a test path.
|
|
11
15
|
* 1) path matches pattern '**.qunit.html'
|
|
12
16
|
* 2) path is being used as test configuration path in yaml configuration.
|
|
13
17
|
*
|
|
14
|
-
* @param
|
|
18
|
+
* @param script - the script content
|
|
15
19
|
* @param configuration - the preview configuration
|
|
16
20
|
* @returns indicator if the path is a test path
|
|
17
21
|
*/
|
|
18
|
-
export declare function isTestPath(
|
|
22
|
+
export declare function isTestPath(script: Script, configuration?: PreviewConfig): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Extracts the test path of a given script name from the related ui5-test-runner script.
|
|
25
|
+
* The relation is defined as usage in another script that references the given script name directly or via max. one indirection.
|
|
26
|
+
*
|
|
27
|
+
* Example:
|
|
28
|
+
* - 'ui:test-server': 'ui5 serve --config ./ui5-deprecated-tools-preview-theme.yaml'
|
|
29
|
+
* - 'ui:test-runner': 'ui5-test-runner --port 8081 --url http://localhost:8080/test/testsuite.qunit.html --report-dir ./target/'
|
|
30
|
+
* - 'ui:test': 'start-server-and-test ui:test-server http://localhost:8080/ ui:test-runner'
|
|
31
|
+
*
|
|
32
|
+
* The test path for script 'ui:test-server' is 'http://localhost:8080/test/testsuite.qunit.html' from 'ui:test-runner' as they are connected via one indirection ('ui:test').
|
|
33
|
+
*
|
|
34
|
+
* @param scriptName - the name of the script from the package.json file
|
|
35
|
+
* @returns the related test path
|
|
36
|
+
*/
|
|
37
|
+
export declare function getTestPathForUi5TestRunner(scriptName: string): string | undefined;
|
|
19
38
|
/**
|
|
20
39
|
* Extract the UI5 yaml configuration file name from the script.
|
|
21
40
|
*
|
|
@@ -36,21 +55,20 @@ export declare function extractYamlConfigFileName(script: string): string;
|
|
|
36
55
|
* @param logger logger to report info to the user
|
|
37
56
|
* @param skipPreviewMiddlewareCreation - (default: false) indicator if the preview middleware creation should be skipped if no preview middleware is configured.
|
|
38
57
|
*/
|
|
39
|
-
export declare function processUi5YamlConfig(fs: Editor, basePath: string, ui5Yaml: string, script:
|
|
58
|
+
export declare function processUi5YamlConfig(fs: Editor, basePath: string, ui5Yaml: string, script: Script, logger?: ToolsLogger, skipPreviewMiddlewareCreation?: boolean): Promise<void>;
|
|
40
59
|
/**
|
|
41
60
|
* Creates a preview middleware configuration.
|
|
42
61
|
*
|
|
43
62
|
* It will sanitize the given preview middleware configuration and construct the flp configuration out of the given intent and path.
|
|
44
63
|
*
|
|
45
64
|
* @param previewMiddleware - the preview middleware configuration
|
|
46
|
-
* @param
|
|
47
|
-
* @param path - the flp path
|
|
65
|
+
* @param script - the content of the script from the package.json file
|
|
48
66
|
* @param basePath - the base path
|
|
49
67
|
* @param fs - file system reference
|
|
50
68
|
* @param logger logger to report info to the user
|
|
51
69
|
* @returns the preview middleware configuration
|
|
52
70
|
*/
|
|
53
|
-
export declare function updatePreviewMiddlewareConfig(previewMiddleware: CustomMiddleware<PreviewConfigOptions>,
|
|
71
|
+
export declare function updatePreviewMiddlewareConfig(previewMiddleware: CustomMiddleware<PreviewConfigOptions>, script: Script, basePath: string, fs: Editor, logger?: ToolsLogger): Promise<CustomMiddleware<PreviewConfigOptions>>;
|
|
54
72
|
/**
|
|
55
73
|
* Sanitize the test script (*.qunit.[jt]s)
|
|
56
74
|
* If the OPA5 test script uses the JourneyRunner, it will be renamed and added as pattern to the respective UI5 yaml configuration.
|
|
@@ -82,6 +100,15 @@ export declare function updateTestConfig(testConfiguration: PreviewConfig['test'
|
|
|
82
100
|
* @param logger logger to report info to the user
|
|
83
101
|
*/
|
|
84
102
|
export declare function updateDefaultTestConfig(fs: Editor, basePath: string, logger?: ToolsLogger): Promise<void>;
|
|
103
|
+
/**
|
|
104
|
+
* Reads the scripts from the package.json file.
|
|
105
|
+
* Scripts will be buffered map 'scriptsFromPackageJson' to avoid multiple reads of the package.json file.
|
|
106
|
+
*
|
|
107
|
+
* @param fs - file system reference
|
|
108
|
+
* @param basePath - base path to be used for the conversion
|
|
109
|
+
* @returns the scripts from the package.json file
|
|
110
|
+
*/
|
|
111
|
+
export declare function getScriptsFromPackageJson(fs: Editor, basePath: string): Map<string, string>;
|
|
85
112
|
/**
|
|
86
113
|
* Updates the preview middleware configurations according to the scripts they are being used in package.json.
|
|
87
114
|
*
|
|
@@ -2,12 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TEST_CONFIG_DEFAULTS = void 0;
|
|
4
4
|
exports.isTestPath = isTestPath;
|
|
5
|
+
exports.getTestPathForUi5TestRunner = getTestPathForUi5TestRunner;
|
|
5
6
|
exports.extractYamlConfigFileName = extractYamlConfigFileName;
|
|
6
7
|
exports.processUi5YamlConfig = processUi5YamlConfig;
|
|
7
8
|
exports.updatePreviewMiddlewareConfig = updatePreviewMiddlewareConfig;
|
|
8
9
|
exports.sanitizeTestScript = sanitizeTestScript;
|
|
9
10
|
exports.updateTestConfig = updateTestConfig;
|
|
10
11
|
exports.updateDefaultTestConfig = updateDefaultTestConfig;
|
|
12
|
+
exports.getScriptsFromPackageJson = getScriptsFromPackageJson;
|
|
11
13
|
exports.updatePreviewMiddlewareConfigs = updatePreviewMiddlewareConfigs;
|
|
12
14
|
const path_1 = require("path");
|
|
13
15
|
const ui5_yaml_1 = require("../variants-config/ui5-yaml");
|
|
@@ -34,6 +36,10 @@ exports.TEST_CONFIG_DEFAULTS = {
|
|
|
34
36
|
framework: 'Testsuite'
|
|
35
37
|
}
|
|
36
38
|
};
|
|
39
|
+
/**
|
|
40
|
+
* Map of scripts from the package.json file.
|
|
41
|
+
*/
|
|
42
|
+
const scriptsFromPackageJson = new Map();
|
|
37
43
|
/**
|
|
38
44
|
* Checks if a script can be converted based on the used UI5 yaml configuration file.
|
|
39
45
|
*
|
|
@@ -60,21 +66,20 @@ function isUi5YamlToBeConverted(ui5Yaml, scriptName, ui5YamlFileNames, logger) {
|
|
|
60
66
|
* @param fs - file system reference
|
|
61
67
|
* @param basePath - base path to be used for the conversion
|
|
62
68
|
* @param ui5Yaml - the name of the UI5 yaml configuration file
|
|
63
|
-
* @param
|
|
64
|
-
* @param script - the content of the script from the package.json file
|
|
69
|
+
* @param script - the script from the package.json file
|
|
65
70
|
* @param convertTests - indicator if test suite and test runner should be included in the conversion
|
|
66
71
|
* @param logger logger to report info to the user
|
|
67
72
|
* @returns indicator if the UI5 yaml configuration file has already been converted
|
|
68
73
|
*/
|
|
69
|
-
async function isUi5YamlFlpPathAlreadyConverted(fs, basePath, ui5Yaml,
|
|
74
|
+
async function isUi5YamlFlpPathAlreadyConverted(fs, basePath, ui5Yaml, script, convertTests, logger) {
|
|
70
75
|
const yamlConfigAlreadyAdjusted = Object.keys(fs.dump(basePath, (file) => {
|
|
71
76
|
return file.basename === ui5Yaml && file.state === 'modified';
|
|
72
77
|
})).length > 0;
|
|
73
78
|
const flpPath = (await (0, utils_1.getPreviewMiddleware)(undefined, basePath, ui5Yaml, fs))
|
|
74
79
|
?.configuration?.flp?.path;
|
|
75
|
-
const { path: scriptPath } = (0, package_json_1.extractUrlDetails)(script);
|
|
76
|
-
if (yamlConfigAlreadyAdjusted && flpPath != scriptPath && (convertTests ? !isTestPath(
|
|
77
|
-
logger?.warn(`Skipping script '${
|
|
80
|
+
const { path: scriptPath } = (0, package_json_1.extractUrlDetails)(script.value);
|
|
81
|
+
if (yamlConfigAlreadyAdjusted && flpPath != scriptPath && (convertTests ? !isTestPath(script) : true)) {
|
|
82
|
+
logger?.warn(`Skipping script '${script.name}', 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 '${script.name}'. ${ui5Yaml} currently uses ${flpPath ?? DEFAULT_FLP_PATH} whereas script '${script.name}' uses '${scriptPath}'.`);
|
|
78
83
|
return true;
|
|
79
84
|
}
|
|
80
85
|
return false;
|
|
@@ -82,35 +87,76 @@ async function isUi5YamlFlpPathAlreadyConverted(fs, basePath, ui5Yaml, scriptNam
|
|
|
82
87
|
/**
|
|
83
88
|
* Checks if the passed path is a FLP path.
|
|
84
89
|
*
|
|
85
|
-
* @param
|
|
90
|
+
* @param script - the script content
|
|
86
91
|
* @param configuration - the preview configuration
|
|
87
92
|
* @returns indicator if the path is an FLP path
|
|
88
93
|
*/
|
|
89
|
-
function isFlpPath(
|
|
94
|
+
function isFlpPath(script, configuration) {
|
|
95
|
+
const { path } = (0, package_json_1.extractUrlDetails)(script.value);
|
|
90
96
|
if (!path) {
|
|
91
97
|
return false;
|
|
92
98
|
}
|
|
93
99
|
const isRtaEditorPath = configuration.rta?.editors?.some((editor) => editor.path === path) ?? false;
|
|
94
|
-
return !isRtaEditorPath && !isTestPath(
|
|
100
|
+
return !isRtaEditorPath && !isTestPath(script, configuration);
|
|
95
101
|
}
|
|
96
102
|
/**
|
|
97
103
|
* Check if the path is a test path.
|
|
98
104
|
* 1) path matches pattern '**.qunit.html'
|
|
99
105
|
* 2) path is being used as test configuration path in yaml configuration.
|
|
100
106
|
*
|
|
101
|
-
* @param
|
|
107
|
+
* @param script - the script content
|
|
102
108
|
* @param configuration - the preview configuration
|
|
103
109
|
* @returns indicator if the path is a test path
|
|
104
110
|
*/
|
|
105
|
-
function isTestPath(
|
|
111
|
+
function isTestPath(script, configuration) {
|
|
112
|
+
const { path } = (0, package_json_1.extractUrlDetails)(script.value);
|
|
106
113
|
if (!path) {
|
|
107
|
-
return
|
|
114
|
+
return !!getTestPathForUi5TestRunner(script.name);
|
|
108
115
|
}
|
|
109
116
|
if (path.includes('.qunit.html')) {
|
|
110
117
|
return true;
|
|
111
118
|
}
|
|
112
119
|
return configuration?.test?.some((testConfig) => testConfig.path === path) ?? false;
|
|
113
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* Extracts the test path of a given script name from the related ui5-test-runner script.
|
|
123
|
+
* The relation is defined as usage in another script that references the given script name directly or via max. one indirection.
|
|
124
|
+
*
|
|
125
|
+
* Example:
|
|
126
|
+
* - 'ui:test-server': 'ui5 serve --config ./ui5-deprecated-tools-preview-theme.yaml'
|
|
127
|
+
* - 'ui:test-runner': 'ui5-test-runner --port 8081 --url http://localhost:8080/test/testsuite.qunit.html --report-dir ./target/'
|
|
128
|
+
* - 'ui:test': 'start-server-and-test ui:test-server http://localhost:8080/ ui:test-runner'
|
|
129
|
+
*
|
|
130
|
+
* The test path for script 'ui:test-server' is 'http://localhost:8080/test/testsuite.qunit.html' from 'ui:test-runner' as they are connected via one indirection ('ui:test').
|
|
131
|
+
*
|
|
132
|
+
* @param scriptName - the name of the script from the package.json file
|
|
133
|
+
* @returns the related test path
|
|
134
|
+
*/
|
|
135
|
+
function getTestPathForUi5TestRunner(scriptName) {
|
|
136
|
+
const TEST_RUNNER_COMMAND = 'ui5-test-runner';
|
|
137
|
+
const extractUrl = (script) => {
|
|
138
|
+
return / (?:--url|-u|--testsuite) (\S*)/.exec(script)?.[1] ?? undefined;
|
|
139
|
+
};
|
|
140
|
+
const findReferencingScriptByScriptName = (scriptName) => {
|
|
141
|
+
return [...scriptsFromPackageJson.values()].find((tmpScriptValue) => tmpScriptValue.includes(` ${scriptName} `));
|
|
142
|
+
};
|
|
143
|
+
const findReferencingUi5TestRunnerScriptByScriptValue = (script) => {
|
|
144
|
+
for (const scriptPart of script.split(' ')) {
|
|
145
|
+
const scriptValue = scriptsFromPackageJson.get(scriptPart);
|
|
146
|
+
if (scriptValue?.includes(TEST_RUNNER_COMMAND)) {
|
|
147
|
+
return scriptValue;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return undefined;
|
|
151
|
+
};
|
|
152
|
+
let testRunnerScript = findReferencingScriptByScriptName(scriptName);
|
|
153
|
+
let url = testRunnerScript?.includes(TEST_RUNNER_COMMAND) ? extractUrl(testRunnerScript) : undefined;
|
|
154
|
+
if (!url) {
|
|
155
|
+
testRunnerScript = findReferencingUi5TestRunnerScriptByScriptValue(testRunnerScript ?? '');
|
|
156
|
+
url = extractUrl(testRunnerScript ?? '');
|
|
157
|
+
}
|
|
158
|
+
return url ? new URL(url).pathname : undefined;
|
|
159
|
+
}
|
|
114
160
|
/**
|
|
115
161
|
* Sanitizes the preview middleware configuration.
|
|
116
162
|
*
|
|
@@ -173,8 +219,7 @@ async function processUi5YamlConfig(fs, basePath, ui5Yaml, script, logger, skipP
|
|
|
173
219
|
if (!previewMiddleware) {
|
|
174
220
|
previewMiddleware = (0, ui5_yaml_1.createPreviewMiddlewareConfig)(fs, basePath);
|
|
175
221
|
}
|
|
176
|
-
|
|
177
|
-
previewMiddleware = await updatePreviewMiddlewareConfig(previewMiddleware, intent, path, basePath, fs, logger);
|
|
222
|
+
previewMiddleware = await updatePreviewMiddlewareConfig(previewMiddleware, script, basePath, fs, logger);
|
|
178
223
|
ui5YamlConfig.updateCustomMiddleware(previewMiddleware);
|
|
179
224
|
const yamlPath = (0, path_1.join)(basePath, ui5Yaml);
|
|
180
225
|
fs.write(yamlPath, ui5YamlConfig.toString());
|
|
@@ -185,20 +230,20 @@ async function processUi5YamlConfig(fs, basePath, ui5Yaml, script, logger, skipP
|
|
|
185
230
|
* It will sanitize the given preview middleware configuration and construct the flp configuration out of the given intent and path.
|
|
186
231
|
*
|
|
187
232
|
* @param previewMiddleware - the preview middleware configuration
|
|
188
|
-
* @param
|
|
189
|
-
* @param path - the flp path
|
|
233
|
+
* @param script - the content of the script from the package.json file
|
|
190
234
|
* @param basePath - the base path
|
|
191
235
|
* @param fs - file system reference
|
|
192
236
|
* @param logger logger to report info to the user
|
|
193
237
|
* @returns the preview middleware configuration
|
|
194
238
|
*/
|
|
195
|
-
async function updatePreviewMiddlewareConfig(previewMiddleware,
|
|
239
|
+
async function updatePreviewMiddlewareConfig(previewMiddleware, script, basePath, fs, logger) {
|
|
240
|
+
const { path, intent } = (0, package_json_1.extractUrlDetails)(script.value);
|
|
196
241
|
const defaultIntent = `${DEFAULT_INTENT.object}-${DEFAULT_INTENT.action}`;
|
|
197
242
|
const newMiddlewareConfig = sanitizePreviewMiddleware(previewMiddleware);
|
|
198
243
|
//copy of configuration to avoid ending up with an empty configuration object in some cases
|
|
199
244
|
const configuration = { ...newMiddlewareConfig.configuration };
|
|
200
245
|
let writeConfig = false;
|
|
201
|
-
if (isFlpPath(
|
|
246
|
+
if (isFlpPath(script, configuration)) {
|
|
202
247
|
//adjust path but respect defaults
|
|
203
248
|
if (!path?.includes(DEFAULT_FLP_PATH)) {
|
|
204
249
|
configuration.flp = configuration.flp ?? {};
|
|
@@ -215,10 +260,17 @@ async function updatePreviewMiddlewareConfig(previewMiddleware, intent, path, ba
|
|
|
215
260
|
writeConfig = true;
|
|
216
261
|
}
|
|
217
262
|
}
|
|
218
|
-
else if (isTestPath(
|
|
263
|
+
else if (path && isTestPath(script, configuration)) {
|
|
219
264
|
configuration.test = await updateTestConfig(configuration.test, path, basePath, fs, logger);
|
|
220
265
|
writeConfig = true;
|
|
221
266
|
}
|
|
267
|
+
else if (!path) {
|
|
268
|
+
const ui5TestRunnerPath = getTestPathForUi5TestRunner(script.name);
|
|
269
|
+
if (ui5TestRunnerPath) {
|
|
270
|
+
configuration.test = await updateTestConfig(configuration.test, ui5TestRunnerPath, basePath, fs);
|
|
271
|
+
writeConfig = true;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
222
274
|
if (writeConfig) {
|
|
223
275
|
newMiddlewareConfig.configuration = configuration;
|
|
224
276
|
}
|
|
@@ -246,7 +298,7 @@ async function sanitizeTestScript(fs, basePath, path, newConfig, logger) {
|
|
|
246
298
|
const filePathRenamed = testScriptPath.replace(/(\.([jt])s)$/, '.custom$1');
|
|
247
299
|
fs.move(testScriptPath, filePathRenamed);
|
|
248
300
|
newConfig.pattern = `/test/**/${(0, path_1.basename)(filePathRenamed)}`;
|
|
249
|
-
logger?.info(`Renamed '${(0, path_1.basename)(testScriptPath)}' to '${(0, path_1.basename)(filePathRenamed)}'. This file creates the JourneyRunner for OPA5 tests. As the handling of journey runners is not part of the virtual OPA5 test runner endpoint, this file has been renamed and added to the respective UI5
|
|
301
|
+
logger?.info(`Renamed '${(0, path_1.basename)(testScriptPath)}' to '${(0, path_1.basename)(filePathRenamed)}'. This file creates the JourneyRunner for OPA5 tests. As the handling of journey runners is not part of the virtual OPA5 test runner endpoint, this file has been renamed and added to the respective UI5 YAML configuration.`);
|
|
250
302
|
}
|
|
251
303
|
else {
|
|
252
304
|
await (0, preview_files_1.deleteFiles)(fs, [testScriptPath]);
|
|
@@ -341,6 +393,23 @@ async function updateDefaultTestConfig(fs, basePath, logger) {
|
|
|
341
393
|
const yamlPath = (0, path_1.join)(basePath, project_access_1.FileName.Ui5Yaml);
|
|
342
394
|
fs.write(yamlPath, ui5YamlConfig.toString());
|
|
343
395
|
}
|
|
396
|
+
/**
|
|
397
|
+
* Reads the scripts from the package.json file.
|
|
398
|
+
* Scripts will be buffered map 'scriptsFromPackageJson' to avoid multiple reads of the package.json file.
|
|
399
|
+
*
|
|
400
|
+
* @param fs - file system reference
|
|
401
|
+
* @param basePath - base path to be used for the conversion
|
|
402
|
+
* @returns the scripts from the package.json file
|
|
403
|
+
*/
|
|
404
|
+
function getScriptsFromPackageJson(fs, basePath) {
|
|
405
|
+
const packageJsonPath = (0, path_1.join)(basePath, 'package.json');
|
|
406
|
+
const packageJson = fs.readJSON(packageJsonPath);
|
|
407
|
+
scriptsFromPackageJson.clear();
|
|
408
|
+
Object.entries(packageJson?.scripts ?? {}).forEach(([scriptName, scriptContent]) => {
|
|
409
|
+
scriptsFromPackageJson.set(scriptName, scriptContent ?? '');
|
|
410
|
+
});
|
|
411
|
+
return scriptsFromPackageJson;
|
|
412
|
+
}
|
|
344
413
|
/**
|
|
345
414
|
* Updates the preview middleware configurations according to the scripts they are being used in package.json.
|
|
346
415
|
*
|
|
@@ -356,16 +425,15 @@ async function updateDefaultTestConfig(fs, basePath, logger) {
|
|
|
356
425
|
async function updatePreviewMiddlewareConfigs(fs, basePath, convertTests, logger) {
|
|
357
426
|
const ui5YamlFileNames = await (0, project_access_1.getAllUi5YamlFileNames)(basePath, fs);
|
|
358
427
|
const unprocessedUi5YamlFileNames = [...ui5YamlFileNames];
|
|
359
|
-
const
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
if (!script || !(0, package_json_1.isValidPreviewScript)(scriptName, script, convertTests)) {
|
|
428
|
+
for (const [scriptName, scriptValue] of getScriptsFromPackageJson(fs, basePath)) {
|
|
429
|
+
const script = { name: scriptName, value: scriptValue };
|
|
430
|
+
if (!scriptValue || !(0, package_json_1.isValidPreviewScript)(script, convertTests)) {
|
|
363
431
|
continue;
|
|
364
432
|
}
|
|
365
|
-
const ui5Yaml = (0, path_1.basename)(extractYamlConfigFileName(
|
|
433
|
+
const ui5Yaml = (0, path_1.basename)(extractYamlConfigFileName(scriptValue));
|
|
366
434
|
unprocessedUi5YamlFileNames.splice(unprocessedUi5YamlFileNames.indexOf(ui5Yaml), 1);
|
|
367
435
|
if (!isUi5YamlToBeConverted(ui5Yaml, scriptName, ui5YamlFileNames, logger) ||
|
|
368
|
-
(await isUi5YamlFlpPathAlreadyConverted(fs, basePath, ui5Yaml,
|
|
436
|
+
(await isUi5YamlFlpPathAlreadyConverted(fs, basePath, ui5Yaml, script, convertTests, logger))) {
|
|
369
437
|
continue;
|
|
370
438
|
}
|
|
371
439
|
try {
|
|
@@ -375,20 +443,21 @@ async function updatePreviewMiddlewareConfigs(fs, basePath, convertTests, logger
|
|
|
375
443
|
logger?.warn(`Skipping script '${scriptName}', which refers to the UI5 YAML configuration file '${ui5Yaml}'. ${error.message}`);
|
|
376
444
|
continue;
|
|
377
445
|
}
|
|
378
|
-
const { path } = (0, package_json_1.extractUrlDetails)(
|
|
446
|
+
const { path } = (0, package_json_1.extractUrlDetails)(scriptValue);
|
|
379
447
|
if (path) {
|
|
380
448
|
await (0, preview_files_1.renameSandbox)(fs, basePath, path, logger);
|
|
381
449
|
}
|
|
382
|
-
(0, package_json_1.ensurePreviewMiddlewareDependency)(
|
|
450
|
+
(0, package_json_1.ensurePreviewMiddlewareDependency)(fs, basePath);
|
|
383
451
|
logger?.info(`The UI5 YAML configuration file '${ui5Yaml}', has been updated according to script, '${scriptName}'.`);
|
|
384
452
|
}
|
|
385
453
|
for (const ui5Yaml of unprocessedUi5YamlFileNames) {
|
|
386
454
|
//at least adjust deprecated preview config of unused ui5 yaml configurations
|
|
455
|
+
const emptyScript = { name: '', value: '' };
|
|
387
456
|
try {
|
|
388
|
-
await processUi5YamlConfig(fs, basePath, ui5Yaml,
|
|
457
|
+
await processUi5YamlConfig(fs, basePath, ui5Yaml, emptyScript, logger, true);
|
|
389
458
|
}
|
|
390
459
|
catch (error) {
|
|
391
|
-
logger?.warn(`Skipping UI5
|
|
460
|
+
logger?.warn(`Skipping UI5 YAML configuration file '${ui5Yaml}'. ${error.mesage}`);
|
|
392
461
|
}
|
|
393
462
|
logger?.warn(`The UI5 YAML configuration file '${ui5Yaml}', is not used in any preview script. Outdated preview middleware will be adjusted, if necessary.`);
|
|
394
463
|
}
|
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.
|
|
4
|
+
"version": "0.5.29",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "https://github.com/SAP/open-ux-tools.git",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"@types/semver": "7.5.8",
|
|
43
43
|
"axios": "1.7.9",
|
|
44
44
|
"nock": "13.4.0",
|
|
45
|
-
"@sap-ux/preview-middleware": "0.17.
|
|
45
|
+
"@sap-ux/preview-middleware": "0.17.29"
|
|
46
46
|
},
|
|
47
47
|
"engines": {
|
|
48
48
|
"node": ">=18.x"
|