@sap-ux/app-config-writer 0.7.6 → 1.0.1
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/cards-config/index.js +19 -22
- package/dist/common/package-json.js +19 -30
- package/dist/common/ui5-yaml.d.ts +2 -2
- package/dist/common/ui5-yaml.js +37 -48
- package/dist/common/utils.d.ts +1 -1
- package/dist/common/utils.js +13 -20
- package/dist/eslint-config/add.js +13 -16
- package/dist/eslint-config/convert.js +29 -35
- package/dist/eslint-config/index.d.ts +2 -2
- package/dist/eslint-config/index.js +2 -7
- package/dist/flp-embedded-config/index.js +11 -15
- package/dist/i18n.js +15 -25
- package/dist/index.d.ts +8 -8
- package/dist/index.js +8 -24
- package/dist/navigation-config/index.js +14 -18
- package/dist/preview-config/index.js +15 -18
- package/dist/preview-config/package-json.js +12 -16
- package/dist/preview-config/prerequisites.js +14 -17
- package/dist/preview-config/preview-files.js +28 -34
- package/dist/preview-config/ui5-yaml.d.ts +1 -1
- package/dist/preview-config/ui5-yaml.js +35 -40
- package/dist/prompt/index.d.ts +2 -2
- package/dist/prompt/index.js +2 -21
- package/dist/prompt/preview-config.js +6 -9
- package/dist/prompt/smartlinks-config.d.ts +1 -1
- package/dist/prompt/smartlinks-config.js +46 -49
- package/dist/smartlinks-config/generateSmartLinks.d.ts +1 -1
- package/dist/smartlinks-config/generateSmartLinks.js +6 -9
- package/dist/smartlinks-config/index.d.ts +2 -2
- package/dist/smartlinks-config/index.js +2 -21
- package/dist/smartlinks-config/ui5-yaml.d.ts +1 -1
- package/dist/smartlinks-config/ui5-yaml.js +14 -18
- package/dist/smartlinks-config/utils.d.ts +1 -1
- package/dist/smartlinks-config/utils.js +33 -40
- package/dist/templates.js +5 -6
- package/dist/types/index.d.ts +3 -3
- package/dist/types/index.js +3 -19
- package/dist/types/navigation.js +1 -2
- package/dist/types/smartLinks.js +4 -7
- package/dist/types/variantsConfig.js +2 -5
- package/dist/variants-config/generateVariantsConfig.js +8 -11
- package/dist/variants-config/index.d.ts +1 -1
- package/dist/variants-config/index.js +1 -17
- package/dist/variants-config/package-json.js +10 -13
- package/dist/variants-config/utils.js +13 -17
- package/package.json +13 -11
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
exports.renameDefaultTestFiles = renameDefaultTestFiles;
|
|
6
|
-
exports.deleteNoLongerUsedFiles = deleteNoLongerUsedFiles;
|
|
7
|
-
const node_path_1 = require("node:path");
|
|
8
|
-
const project_access_1 = require("@sap-ux/project-access");
|
|
9
|
-
const ui5_yaml_1 = require("../common/ui5-yaml");
|
|
10
|
-
const utils_1 = require("../common/utils");
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
import { getWebappPath } from '@sap-ux/project-access';
|
|
3
|
+
import { TEST_CONFIG_DEFAULTS } from '../common/ui5-yaml.js';
|
|
4
|
+
import { deleteFiles } from '../common/utils.js';
|
|
11
5
|
const renameMessage = (filePath) => `Renamed '${filePath}' to '${filePath.slice(0, -5)}_old.html'. This file is no longer needed for the virtual endpoints. 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://github.com/SAP/open-ux-tools/tree/main/packages/preview-middleware#migration.`;
|
|
12
6
|
/**
|
|
13
7
|
* Renames the sandbox file which is used in a given script.
|
|
@@ -19,8 +13,8 @@ const renameMessage = (filePath) => `Renamed '${filePath}' to '${filePath.slice(
|
|
|
19
13
|
* @param path - file path to be used for the renaming
|
|
20
14
|
* @param logger logger to report info to the user
|
|
21
15
|
*/
|
|
22
|
-
async function renameSandbox(fs, basePath, path, logger) {
|
|
23
|
-
const filePath =
|
|
16
|
+
export async function renameSandbox(fs, basePath, path, logger) {
|
|
17
|
+
const filePath = join(await getWebappPath(basePath), path);
|
|
24
18
|
if (fs.exists(filePath)) {
|
|
25
19
|
if (path.endsWith('unitTests.qunit.html')) {
|
|
26
20
|
logger?.warn(`Unit test files will be discovered automatically using the default pattern '/test/**/*Test.{js,ts}'. If your unit test files do not match this pattern, add a 'pattern' property to the QUnit test entry in your UI5 YAML configuration (e.g. pattern: '/test/unit/controller/*.{js,ts}'). For more details see https://github.com/SAP/open-ux-tools/blob/main/packages/preview-middleware/README.md#configuration-option-test`);
|
|
@@ -49,8 +43,8 @@ async function renameSandbox(fs, basePath, path, logger) {
|
|
|
49
43
|
* @param basePath - base path to be used for the conversion
|
|
50
44
|
* @param logger logger to report info to the user
|
|
51
45
|
*/
|
|
52
|
-
async function renameDefaultSandboxes(fs, basePath, logger) {
|
|
53
|
-
const defaultSandboxPaths = [
|
|
46
|
+
export async function renameDefaultSandboxes(fs, basePath, logger) {
|
|
47
|
+
const defaultSandboxPaths = [join('test', 'flpSandbox.html'), join('test', 'flpSandboxMockserver.html')];
|
|
54
48
|
for (const path of defaultSandboxPaths) {
|
|
55
49
|
await renameSandbox(fs, basePath, path, logger);
|
|
56
50
|
}
|
|
@@ -64,8 +58,8 @@ async function renameDefaultSandboxes(fs, basePath, logger) {
|
|
|
64
58
|
* @param basePath - base path to be used for the conversion
|
|
65
59
|
* @param logger logger to report info to the user
|
|
66
60
|
*/
|
|
67
|
-
async function renameDefaultTestFiles(fs, basePath, logger) {
|
|
68
|
-
for (const path of Object.values(
|
|
61
|
+
export async function renameDefaultTestFiles(fs, basePath, logger) {
|
|
62
|
+
for (const path of Object.values(TEST_CONFIG_DEFAULTS).map((config) => config.path)) {
|
|
69
63
|
await renameSandbox(fs, basePath, path, logger);
|
|
70
64
|
}
|
|
71
65
|
}
|
|
@@ -77,27 +71,27 @@ async function renameDefaultTestFiles(fs, basePath, logger) {
|
|
|
77
71
|
* @param convertTests - indicator if test suite and test runner should be included in the conversion
|
|
78
72
|
* @param logger logger to report info to the user
|
|
79
73
|
*/
|
|
80
|
-
async function deleteNoLongerUsedFiles(fs, basePath, convertTests, logger) {
|
|
81
|
-
const webappTestPath =
|
|
74
|
+
export async function deleteNoLongerUsedFiles(fs, basePath, convertTests, logger) {
|
|
75
|
+
const webappTestPath = join(await getWebappPath(basePath, fs), 'test');
|
|
82
76
|
const files = [
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
77
|
+
join(webappTestPath, 'locate-reuse-libs.js'),
|
|
78
|
+
join(webappTestPath, 'changes_loader.js'),
|
|
79
|
+
join(webappTestPath, 'changes_loader.ts'),
|
|
80
|
+
join(webappTestPath, 'changes_preview.js'),
|
|
81
|
+
join(webappTestPath, 'changes_preview.ts'),
|
|
82
|
+
join(webappTestPath, 'flpSandbox.js'),
|
|
83
|
+
join(webappTestPath, 'flpSandbox.ts'),
|
|
84
|
+
join(webappTestPath, 'initFlpSandbox.js'),
|
|
85
|
+
join(webappTestPath, 'initFlpSandbox.ts')
|
|
92
86
|
];
|
|
93
87
|
if (convertTests) {
|
|
94
|
-
files.push(
|
|
95
|
-
files.push(
|
|
96
|
-
files.push(
|
|
97
|
-
files.push(
|
|
98
|
-
files.push(
|
|
99
|
-
files.push(
|
|
88
|
+
files.push(join(webappTestPath, 'testsuite.qunit.js'));
|
|
89
|
+
files.push(join(webappTestPath, 'testsuite.qunit.ts'));
|
|
90
|
+
files.push(join(webappTestPath, 'integration', 'opaTests.qunit.js'));
|
|
91
|
+
files.push(join(webappTestPath, 'integration', 'opaTests.qunit.ts'));
|
|
92
|
+
files.push(join(webappTestPath, 'unit', 'unitTests.qunit.js'));
|
|
93
|
+
files.push(join(webappTestPath, 'unit', 'unitTests.qunit.ts'));
|
|
100
94
|
}
|
|
101
|
-
await
|
|
95
|
+
await deleteFiles(fs, files, logger);
|
|
102
96
|
}
|
|
103
97
|
//# sourceMappingURL=preview-files.js.map
|
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const package_json_1 = require("./package-json");
|
|
9
|
-
const project_access_1 = require("@sap-ux/project-access");
|
|
10
|
-
const utils_1 = require("../common/utils");
|
|
11
|
-
const package_json_2 = require("../common/package-json");
|
|
12
|
-
const preview_files_1 = require("./preview-files");
|
|
1
|
+
import { basename, join } from 'node:path';
|
|
2
|
+
import { createPreviewMiddlewareConfig, updatePreviewMiddlewareConfig, updateTestConfig, DEFAULT_FLP_PATH, TEST_CONFIG_DEFAULTS } from '../common/ui5-yaml.js';
|
|
3
|
+
import { ensurePreviewMiddlewareDependency } from './package-json.js';
|
|
4
|
+
import { FileName, getAllUi5YamlFileNames, readUi5Yaml } from '@sap-ux/project-access';
|
|
5
|
+
import { getPreviewMiddleware } from '../common/utils.js';
|
|
6
|
+
import { extractUrlDetails, isValidPreviewScript, extractYamlConfigFileName, isTestPath, getScriptsFromPackageJson } from '../common/package-json.js';
|
|
7
|
+
import { renameSandbox } from './preview-files.js';
|
|
13
8
|
/**
|
|
14
9
|
* Checks if a script can be converted based on the used UI5 yaml configuration file.
|
|
15
10
|
*
|
|
@@ -45,11 +40,11 @@ async function isUi5YamlFlpPathAlreadyConverted(fs, basePath, ui5Yaml, script, c
|
|
|
45
40
|
const yamlConfigAlreadyAdjusted = Object.keys(fs.dump(basePath, (file) => {
|
|
46
41
|
return file.basename === ui5Yaml && file.state === 'modified';
|
|
47
42
|
})).length > 0;
|
|
48
|
-
const flpPath = (await
|
|
43
|
+
const flpPath = (await getPreviewMiddleware(undefined, basePath, ui5Yaml, fs))
|
|
49
44
|
?.configuration?.flp?.path;
|
|
50
|
-
const { path: scriptPath } =
|
|
51
|
-
if (yamlConfigAlreadyAdjusted && flpPath != scriptPath && (convertTests ? !
|
|
52
|
-
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 ??
|
|
45
|
+
const { path: scriptPath } = extractUrlDetails(script.value);
|
|
46
|
+
if (yamlConfigAlreadyAdjusted && flpPath != scriptPath && (convertTests ? !isTestPath(script) : true)) {
|
|
47
|
+
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}'.`);
|
|
53
48
|
return true;
|
|
54
49
|
}
|
|
55
50
|
return false;
|
|
@@ -67,24 +62,24 @@ async function isUi5YamlFlpPathAlreadyConverted(fs, basePath, ui5Yaml, script, c
|
|
|
67
62
|
* @param logger logger to report info to the user
|
|
68
63
|
* @param skipPreviewMiddlewareCreation - (default: false) indicator if the preview middleware creation should be skipped if no preview middleware is configured.
|
|
69
64
|
*/
|
|
70
|
-
async function processUi5YamlConfig(fs, basePath, ui5Yaml, script, logger, skipPreviewMiddlewareCreation = false) {
|
|
65
|
+
export async function processUi5YamlConfig(fs, basePath, ui5Yaml, script, logger, skipPreviewMiddlewareCreation = false) {
|
|
71
66
|
let ui5YamlConfig;
|
|
72
67
|
try {
|
|
73
|
-
ui5YamlConfig = await
|
|
68
|
+
ui5YamlConfig = await readUi5Yaml(basePath, ui5Yaml, fs, { validateSchema: true });
|
|
74
69
|
}
|
|
75
70
|
catch (error) {
|
|
76
71
|
throw new Error(`An error occurred when reading '${ui5Yaml}': ${error.message}`);
|
|
77
72
|
}
|
|
78
|
-
let previewMiddleware = await
|
|
73
|
+
let previewMiddleware = await getPreviewMiddleware(ui5YamlConfig);
|
|
79
74
|
if (skipPreviewMiddlewareCreation && !previewMiddleware) {
|
|
80
75
|
return;
|
|
81
76
|
}
|
|
82
77
|
if (!previewMiddleware) {
|
|
83
|
-
previewMiddleware =
|
|
78
|
+
previewMiddleware = createPreviewMiddlewareConfig(fs, basePath);
|
|
84
79
|
}
|
|
85
|
-
previewMiddleware = await
|
|
80
|
+
previewMiddleware = await updatePreviewMiddlewareConfig(previewMiddleware, script, basePath, fs, logger);
|
|
86
81
|
ui5YamlConfig.updateCustomMiddleware(previewMiddleware);
|
|
87
|
-
const yamlPath =
|
|
82
|
+
const yamlPath = join(basePath, ui5Yaml);
|
|
88
83
|
fs.write(yamlPath, ui5YamlConfig.toString());
|
|
89
84
|
}
|
|
90
85
|
/**
|
|
@@ -94,34 +89,34 @@ async function processUi5YamlConfig(fs, basePath, ui5Yaml, script, logger, skipP
|
|
|
94
89
|
* @param basePath - base path to be used for the conversion
|
|
95
90
|
* @param logger logger to report info to the user
|
|
96
91
|
*/
|
|
97
|
-
async function updateDefaultTestConfig(fs, basePath, logger) {
|
|
98
|
-
const ui5YamlFileNames = await
|
|
99
|
-
for (const ui5Yaml of ui5YamlFileNames.filter((ui5Yaml) => ui5Yaml !==
|
|
100
|
-
const ui5YamlConfig = await
|
|
101
|
-
const previewMiddleware = (await
|
|
92
|
+
export async function updateDefaultTestConfig(fs, basePath, logger) {
|
|
93
|
+
const ui5YamlFileNames = await getAllUi5YamlFileNames(basePath, fs);
|
|
94
|
+
for (const ui5Yaml of ui5YamlFileNames.filter((ui5Yaml) => ui5Yaml !== FileName.Ui5Yaml)) {
|
|
95
|
+
const ui5YamlConfig = await readUi5Yaml(basePath, ui5Yaml, fs);
|
|
96
|
+
const previewMiddleware = (await getPreviewMiddleware(ui5YamlConfig));
|
|
102
97
|
if (previewMiddleware?.configuration?.test) {
|
|
103
98
|
return;
|
|
104
99
|
}
|
|
105
100
|
}
|
|
106
101
|
let ui5YamlConfig;
|
|
107
102
|
try {
|
|
108
|
-
ui5YamlConfig = await
|
|
103
|
+
ui5YamlConfig = await readUi5Yaml(basePath, FileName.Ui5Yaml, fs);
|
|
109
104
|
}
|
|
110
105
|
catch (error) {
|
|
111
106
|
logger?.warn(`The UI5 YAML configuration file 'ui5.yaml', can't be updated to support test frameworks: '${error}'. Please manually add the test configuration to the UI5 YAML configuration file used for testing according to https://github.com/SAP/open-ux-tools/tree/main/packages/preview-middleware#configuration-option-test.`);
|
|
112
107
|
return;
|
|
113
108
|
}
|
|
114
|
-
const previewMiddleware = (await
|
|
115
|
-
for (const defaultConfig of Object.values(
|
|
109
|
+
const previewMiddleware = (await getPreviewMiddleware(ui5YamlConfig));
|
|
110
|
+
for (const defaultConfig of Object.values(TEST_CONFIG_DEFAULTS)) {
|
|
116
111
|
if (previewMiddleware.configuration?.test?.some((testConfig) => testConfig.framework.toLowerCase() === defaultConfig.framework.toLowerCase())) {
|
|
117
112
|
//do not touch existing test config
|
|
118
113
|
break;
|
|
119
114
|
}
|
|
120
|
-
previewMiddleware.configuration.test = await
|
|
115
|
+
previewMiddleware.configuration.test = await updateTestConfig(previewMiddleware.configuration.test, defaultConfig.path, basePath, fs, logger);
|
|
121
116
|
logger?.info(`The UI5 YAML configuration file 'ui5.yaml', has been updated to support the test framework '${defaultConfig.framework}'. Please consider transferring the test configuration to the UI5 YAML configuration file used for testing.`);
|
|
122
117
|
}
|
|
123
118
|
ui5YamlConfig.updateCustomMiddleware(previewMiddleware);
|
|
124
|
-
const yamlPath =
|
|
119
|
+
const yamlPath = join(basePath, FileName.Ui5Yaml);
|
|
125
120
|
fs.write(yamlPath, ui5YamlConfig.toString());
|
|
126
121
|
}
|
|
127
122
|
/**
|
|
@@ -136,15 +131,15 @@ async function updateDefaultTestConfig(fs, basePath, logger) {
|
|
|
136
131
|
* @param convertTests - indicator if test suite and test runner should be included in the conversion
|
|
137
132
|
* @param logger logger to report info to the user
|
|
138
133
|
*/
|
|
139
|
-
async function updatePreviewMiddlewareConfigs(fs, basePath, convertTests, logger) {
|
|
140
|
-
const ui5YamlFileNames = await
|
|
134
|
+
export async function updatePreviewMiddlewareConfigs(fs, basePath, convertTests, logger) {
|
|
135
|
+
const ui5YamlFileNames = await getAllUi5YamlFileNames(basePath, fs);
|
|
141
136
|
const unprocessedUi5YamlFileNames = [...ui5YamlFileNames];
|
|
142
|
-
for (const [scriptName, scriptValue] of
|
|
137
|
+
for (const [scriptName, scriptValue] of getScriptsFromPackageJson(fs, basePath)) {
|
|
143
138
|
const script = { name: scriptName, value: scriptValue };
|
|
144
|
-
if (!scriptValue || !
|
|
139
|
+
if (!scriptValue || !isValidPreviewScript(script, convertTests)) {
|
|
145
140
|
continue;
|
|
146
141
|
}
|
|
147
|
-
const ui5Yaml =
|
|
142
|
+
const ui5Yaml = basename(extractYamlConfigFileName(scriptValue));
|
|
148
143
|
unprocessedUi5YamlFileNames.splice(unprocessedUi5YamlFileNames.indexOf(ui5Yaml), 1);
|
|
149
144
|
if (!isUi5YamlToBeConverted(ui5Yaml, scriptName, ui5YamlFileNames, logger) ||
|
|
150
145
|
(await isUi5YamlFlpPathAlreadyConverted(fs, basePath, ui5Yaml, script, convertTests, logger))) {
|
|
@@ -157,11 +152,11 @@ async function updatePreviewMiddlewareConfigs(fs, basePath, convertTests, logger
|
|
|
157
152
|
logger?.warn(`Skipping script '${scriptName}', which refers to the UI5 YAML configuration file '${ui5Yaml}'. ${error.message}`);
|
|
158
153
|
continue;
|
|
159
154
|
}
|
|
160
|
-
const { path } =
|
|
155
|
+
const { path } = extractUrlDetails(scriptValue);
|
|
161
156
|
if (path) {
|
|
162
|
-
await
|
|
157
|
+
await renameSandbox(fs, basePath, path, logger);
|
|
163
158
|
}
|
|
164
|
-
|
|
159
|
+
ensurePreviewMiddlewareDependency(fs, basePath);
|
|
165
160
|
logger?.info(`The UI5 YAML configuration file '${ui5Yaml}', has been updated according to script, '${scriptName}'.`);
|
|
166
161
|
}
|
|
167
162
|
for (const ui5Yaml of unprocessedUi5YamlFileNames) {
|
package/dist/prompt/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { getSmartLinksTargetFromPrompt, promptUserPass } from './smartlinks-config';
|
|
2
|
-
export * from './preview-config';
|
|
1
|
+
export { getSmartLinksTargetFromPrompt, promptUserPass } from './smartlinks-config.js';
|
|
2
|
+
export * from './preview-config.js';
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/prompt/index.js
CHANGED
|
@@ -1,22 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
-
exports.promptUserPass = exports.getSmartLinksTargetFromPrompt = void 0;
|
|
18
|
-
var smartlinks_config_1 = require("./smartlinks-config");
|
|
19
|
-
Object.defineProperty(exports, "getSmartLinksTargetFromPrompt", { enumerable: true, get: function () { return smartlinks_config_1.getSmartLinksTargetFromPrompt; } });
|
|
20
|
-
Object.defineProperty(exports, "promptUserPass", { enumerable: true, get: function () { return smartlinks_config_1.promptUserPass; } });
|
|
21
|
-
__exportStar(require("./preview-config"), exports);
|
|
1
|
+
export { getSmartLinksTargetFromPrompt, promptUserPass } from './smartlinks-config.js';
|
|
2
|
+
export * from './preview-config.js';
|
|
22
3
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.simulatePrompt = simulatePrompt;
|
|
4
|
-
exports.includeTestRunnersPrompt = includeTestRunnersPrompt;
|
|
5
|
-
const prompts_1 = require("prompts");
|
|
1
|
+
import prompts from 'prompts';
|
|
2
|
+
const { prompt } = prompts;
|
|
6
3
|
/**
|
|
7
4
|
* Prompt if the conversion should be done in simulation.
|
|
8
5
|
*
|
|
9
6
|
* @returns Indicator if the conversion should be simulated.
|
|
10
7
|
*/
|
|
11
|
-
async function simulatePrompt() {
|
|
8
|
+
export async function simulatePrompt() {
|
|
12
9
|
const PROMPT_NAME = 'simulate';
|
|
13
10
|
const question = {
|
|
14
11
|
type: 'confirm',
|
|
@@ -17,7 +14,7 @@ async function simulatePrompt() {
|
|
|
17
14
|
message: `The converter renames the local HTML files, deletes the JavaScript and TypeScript files used for the existing preview functionality, and configures virtual endpoints instead.
|
|
18
15
|
Do you want to simulate the conversion?`
|
|
19
16
|
};
|
|
20
|
-
const answer = (await
|
|
17
|
+
const answer = (await prompt([question]));
|
|
21
18
|
return (answer.simulate ?? (await Promise.reject(new Error('An error has occurred. The conversion has been canceled.')))); //in case of doubt, reject
|
|
22
19
|
}
|
|
23
20
|
/**
|
|
@@ -25,7 +22,7 @@ Do you want to simulate the conversion?`
|
|
|
25
22
|
*
|
|
26
23
|
* @returns Indicator if the conversion should include test runners.
|
|
27
24
|
*/
|
|
28
|
-
async function includeTestRunnersPrompt() {
|
|
25
|
+
export async function includeTestRunnersPrompt() {
|
|
29
26
|
const PROMPT_NAME = 'includeTests';
|
|
30
27
|
const question = {
|
|
31
28
|
type: 'confirm',
|
|
@@ -33,7 +30,7 @@ async function includeTestRunnersPrompt() {
|
|
|
33
30
|
initial: false,
|
|
34
31
|
message: 'Do you want to convert the test runners?'
|
|
35
32
|
};
|
|
36
|
-
const answer = (await
|
|
33
|
+
const answer = (await prompt([question]));
|
|
37
34
|
return (answer.includeTests ??
|
|
38
35
|
(await Promise.reject(new Error('An error has occurred. The conversion has been canceled.')))); //in case of doubt, reject
|
|
39
36
|
}
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
const i18n_1 = require("../i18n");
|
|
10
|
-
const smartlinks_config_1 = require("../smartlinks-config");
|
|
11
|
-
const types_1 = require("../types");
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import prompts from 'prompts';
|
|
3
|
+
import { isAppStudio, listDestinations } from '@sap-ux/btp-utils';
|
|
4
|
+
import { FileName } from '@sap-ux/project-access';
|
|
5
|
+
import { t } from '../i18n.js';
|
|
6
|
+
import { getLocalStoredCredentials, getTargetDefinition } from '../smartlinks-config/index.js';
|
|
7
|
+
const { prompt } = prompts;
|
|
8
|
+
import { TargetType } from '../types/index.js';
|
|
12
9
|
/**
|
|
13
10
|
* Validator helper function for prompts.
|
|
14
11
|
*
|
|
@@ -18,7 +15,7 @@ const types_1 = require("../types");
|
|
|
18
15
|
*/
|
|
19
16
|
const validator = (value, error) => {
|
|
20
17
|
if (!value?.trim()) {
|
|
21
|
-
return
|
|
18
|
+
return t(error);
|
|
22
19
|
}
|
|
23
20
|
else {
|
|
24
21
|
return true;
|
|
@@ -34,8 +31,8 @@ const addAppStudioQuestions = (questions, target) => {
|
|
|
34
31
|
// Offer existing configuration
|
|
35
32
|
if (target?.destination || target?.url) {
|
|
36
33
|
questions.push({
|
|
37
|
-
name: target?.destination ?
|
|
38
|
-
message:
|
|
34
|
+
name: target?.destination ? TargetType.destination : TargetType.url,
|
|
35
|
+
message: t('questions.useTarget', { target: target.destination || target.url }),
|
|
39
36
|
type: 'confirm',
|
|
40
37
|
initial: true,
|
|
41
38
|
format: (confirm) => (confirm ? target.destination || target.url : confirm)
|
|
@@ -45,20 +42,20 @@ const addAppStudioQuestions = (questions, target) => {
|
|
|
45
42
|
questions.push({
|
|
46
43
|
name: 'select',
|
|
47
44
|
type: (prev) => (!prev ? 'select' : null),
|
|
48
|
-
message:
|
|
45
|
+
message: t('questions.target', { type: '', file: '' }),
|
|
49
46
|
choices: [
|
|
50
|
-
{ title:
|
|
51
|
-
{ title:
|
|
47
|
+
{ title: t('questions.enter', { type: TargetType.destination }), value: TargetType.destination },
|
|
48
|
+
{ title: t('questions.enter', { type: TargetType.url }), value: TargetType.url }
|
|
52
49
|
]
|
|
53
50
|
});
|
|
54
51
|
// destination
|
|
55
52
|
questions.push({
|
|
56
|
-
type: (prev) => (prev ===
|
|
57
|
-
name:
|
|
53
|
+
type: (prev) => (prev === TargetType.destination ? 'text' : null),
|
|
54
|
+
name: TargetType.destination,
|
|
58
55
|
initial: target?.destination,
|
|
59
|
-
message:
|
|
60
|
-
type:
|
|
61
|
-
file: target?.destination ? `(${
|
|
56
|
+
message: t('questions.target', {
|
|
57
|
+
type: TargetType.destination,
|
|
58
|
+
file: target?.destination ? `(${FileName.UI5DeployYaml})` : ''
|
|
62
59
|
}),
|
|
63
60
|
validate: (value) => validator(value, 'error.target')
|
|
64
61
|
});
|
|
@@ -71,25 +68,25 @@ const addAppStudioQuestions = (questions, target) => {
|
|
|
71
68
|
*/
|
|
72
69
|
const getTargetPromptQuestions = (target) => {
|
|
73
70
|
const questions = [];
|
|
74
|
-
if (
|
|
71
|
+
if (isAppStudio()) {
|
|
75
72
|
addAppStudioQuestions(questions, target);
|
|
76
73
|
}
|
|
77
74
|
// Offer url configuration for VSCode and BAS instance
|
|
78
75
|
questions.push({
|
|
79
|
-
type: (prev) => (!prev || prev ===
|
|
80
|
-
name:
|
|
76
|
+
type: (prev) => (!prev || prev === TargetType.url ? 'text' : null),
|
|
77
|
+
name: TargetType.url,
|
|
81
78
|
initial: target?.url,
|
|
82
|
-
message:
|
|
83
|
-
type:
|
|
84
|
-
file: target?.url ? `(${
|
|
79
|
+
message: t('questions.target', {
|
|
80
|
+
type: TargetType.url,
|
|
81
|
+
file: target?.url ? `(${FileName.UI5DeployYaml})` : ''
|
|
85
82
|
}),
|
|
86
83
|
validate: (value) => validator(value, 'error.target')
|
|
87
84
|
}, {
|
|
88
85
|
name: 'client',
|
|
89
86
|
type: (_prev, values) => (values?.url ? 'text' : null),
|
|
90
87
|
initial: target?.client,
|
|
91
|
-
message:
|
|
92
|
-
file: target?.client ? `(${
|
|
88
|
+
message: t('questions.client', {
|
|
89
|
+
file: target?.client ? `(${FileName.UI5DeployYaml})` : ''
|
|
93
90
|
}),
|
|
94
91
|
format: (val) => (typeof val === 'number' ? val.toString() : val)
|
|
95
92
|
});
|
|
@@ -105,12 +102,12 @@ const getTargetPromptQuestions = (target) => {
|
|
|
105
102
|
const getTargetPrompt = async (config, logger) => {
|
|
106
103
|
const cancel = {
|
|
107
104
|
onCancel: () => {
|
|
108
|
-
logger?.info(
|
|
105
|
+
logger?.info(chalk.yellow(t('info.operationAborted')));
|
|
109
106
|
return process.exit(1);
|
|
110
107
|
}
|
|
111
108
|
};
|
|
112
109
|
const questions = getTargetPromptQuestions(config?.target);
|
|
113
|
-
const { url, client, destination } = await
|
|
110
|
+
const { url, client, destination } = await prompt(questions, cancel);
|
|
114
111
|
return { url, client, destination };
|
|
115
112
|
};
|
|
116
113
|
/**
|
|
@@ -119,15 +116,15 @@ const getTargetPrompt = async (config, logger) => {
|
|
|
119
116
|
* @param log logger to report info to the user
|
|
120
117
|
* @returns prompted user and password serialized for a basic auth header
|
|
121
118
|
*/
|
|
122
|
-
async function promptUserPass(log) {
|
|
123
|
-
const { username, password } = await
|
|
119
|
+
export async function promptUserPass(log) {
|
|
120
|
+
const { username, password } = await prompt([
|
|
124
121
|
{
|
|
125
122
|
type: 'text',
|
|
126
123
|
name: 'username',
|
|
127
|
-
message: `${
|
|
124
|
+
message: `${chalk.cyan(t('info.username'))}`,
|
|
128
125
|
validate: (value) => {
|
|
129
126
|
if (!value?.trim()) {
|
|
130
|
-
return `${
|
|
127
|
+
return `${t('error.emptyUsername')}`;
|
|
131
128
|
}
|
|
132
129
|
else {
|
|
133
130
|
return true;
|
|
@@ -137,10 +134,10 @@ async function promptUserPass(log) {
|
|
|
137
134
|
{
|
|
138
135
|
type: 'invisible',
|
|
139
136
|
name: 'password',
|
|
140
|
-
message: `${
|
|
137
|
+
message: `${chalk.cyan(t('info.password'))}`,
|
|
141
138
|
validate: (value) => {
|
|
142
139
|
if (!value?.trim()) {
|
|
143
|
-
return `${
|
|
140
|
+
return `${t('error.emptyPassword')}`;
|
|
144
141
|
}
|
|
145
142
|
else {
|
|
146
143
|
return true;
|
|
@@ -149,7 +146,7 @@ async function promptUserPass(log) {
|
|
|
149
146
|
}
|
|
150
147
|
], {
|
|
151
148
|
onCancel: () => {
|
|
152
|
-
log?.info(
|
|
149
|
+
log?.info(chalk.yellow(t('info.operationAborted')));
|
|
153
150
|
return process.exit(1);
|
|
154
151
|
}
|
|
155
152
|
});
|
|
@@ -163,27 +160,27 @@ async function promptUserPass(log) {
|
|
|
163
160
|
* @returns credentials for target definition
|
|
164
161
|
*/
|
|
165
162
|
async function getCredentialsPrompt(target, logger) {
|
|
166
|
-
if (
|
|
167
|
-
const destinations = await
|
|
163
|
+
if (isAppStudio() && target.destination) {
|
|
164
|
+
const destinations = await listDestinations();
|
|
168
165
|
const destination = destinations?.[target.destination];
|
|
169
166
|
if (destination?.Authentication === 'NoAuthentication') {
|
|
170
|
-
logger?.info(
|
|
167
|
+
logger?.info(t('info.credentialsRequired'));
|
|
171
168
|
return await promptUserPass(logger);
|
|
172
169
|
}
|
|
173
170
|
else if (destination) {
|
|
174
|
-
logger?.info(
|
|
171
|
+
logger?.info(t('info.credentialsAvailable'));
|
|
175
172
|
return undefined;
|
|
176
173
|
}
|
|
177
174
|
}
|
|
178
175
|
else if (target.url) {
|
|
179
|
-
const auth = await
|
|
176
|
+
const auth = await getLocalStoredCredentials(target.url, target.client, logger);
|
|
180
177
|
if (auth?.username) {
|
|
181
178
|
const choices = [
|
|
182
179
|
{ title: `Use ${auth.username}`, value: auth },
|
|
183
|
-
{ title:
|
|
180
|
+
{ title: t('questions.credentialsDescription'), value: false }
|
|
184
181
|
];
|
|
185
|
-
const { credentials } = await
|
|
186
|
-
{ name: 'credentials', type: 'select', message:
|
|
182
|
+
const { credentials } = await prompt([
|
|
183
|
+
{ name: 'credentials', type: 'select', message: t('questions.credentials'), choices, initial: 0 }
|
|
187
184
|
]);
|
|
188
185
|
if (credentials) {
|
|
189
186
|
return credentials;
|
|
@@ -199,8 +196,8 @@ async function getCredentialsPrompt(target, logger) {
|
|
|
199
196
|
* @param logger logger to report info to the user
|
|
200
197
|
* @returns - array of questions that serves as input for prompt module
|
|
201
198
|
*/
|
|
202
|
-
async function getSmartLinksTargetFromPrompt(basePath, logger) {
|
|
203
|
-
const definition = await
|
|
199
|
+
export async function getSmartLinksTargetFromPrompt(basePath, logger) {
|
|
200
|
+
const definition = await getTargetDefinition(basePath, logger);
|
|
204
201
|
const target = await getTargetPrompt(definition, logger);
|
|
205
202
|
const auth = await getCredentialsPrompt(target, logger);
|
|
206
203
|
return { target, auth, ignoreCertErrors: definition?.ignoreCertErrors };
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const mem_fs_1 = require("mem-fs");
|
|
5
|
-
const mem_fs_editor_1 = require("mem-fs-editor");
|
|
6
|
-
const utils_1 = require("./utils");
|
|
1
|
+
import { create as createStorage } from 'mem-fs';
|
|
2
|
+
import { create } from 'mem-fs-editor';
|
|
3
|
+
import { writeSmartLinksConfig } from './utils.js';
|
|
7
4
|
/**
|
|
8
5
|
* Add smartlinks configuration to a UI5 application.
|
|
9
6
|
*
|
|
@@ -13,11 +10,11 @@ const utils_1 = require("./utils");
|
|
|
13
10
|
* @param fs - the memfs editor instance
|
|
14
11
|
* @returns Promise<Editor> - memfs editor instance with updated files
|
|
15
12
|
*/
|
|
16
|
-
async function generateSmartLinksConfig(basePath, config, logger, fs) {
|
|
13
|
+
export async function generateSmartLinksConfig(basePath, config, logger, fs) {
|
|
17
14
|
if (!fs) {
|
|
18
|
-
fs =
|
|
15
|
+
fs = create(createStorage());
|
|
19
16
|
}
|
|
20
|
-
await
|
|
17
|
+
await writeSmartLinksConfig(basePath, config, fs, logger);
|
|
21
18
|
return fs;
|
|
22
19
|
}
|
|
23
20
|
//# sourceMappingURL=generateSmartLinks.js.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './generateSmartLinks';
|
|
2
|
-
export { getTargetDefinition, getLocalStoredCredentials } from './utils';
|
|
1
|
+
export * from './generateSmartLinks.js';
|
|
2
|
+
export { getTargetDefinition, getLocalStoredCredentials } from './utils.js';
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,22 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
-
exports.getLocalStoredCredentials = exports.getTargetDefinition = void 0;
|
|
18
|
-
__exportStar(require("./generateSmartLinks"), exports);
|
|
19
|
-
var utils_1 = require("./utils");
|
|
20
|
-
Object.defineProperty(exports, "getTargetDefinition", { enumerable: true, get: function () { return utils_1.getTargetDefinition; } });
|
|
21
|
-
Object.defineProperty(exports, "getLocalStoredCredentials", { enumerable: true, get: function () { return utils_1.getLocalStoredCredentials; } });
|
|
1
|
+
export * from './generateSmartLinks.js';
|
|
2
|
+
export { getTargetDefinition, getLocalStoredCredentials } from './utils.js';
|
|
22
3
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Editor } from 'mem-fs-editor';
|
|
2
2
|
import type { ToolsLogger } from '@sap-ux/logger';
|
|
3
|
-
import type { TargetConfig } from '../types';
|
|
3
|
+
import type { TargetConfig } from '../types/index.js';
|
|
4
4
|
/**
|
|
5
5
|
* Reads and returns target information from ui5-deploy.yaml, if existing.
|
|
6
6
|
*
|