@sap-ux/mockserver-config-writer 0.10.2 → 1.0.0
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/app-info.js +2 -6
- package/dist/i18n.js +6 -13
- package/dist/index.d.ts +4 -4
- package/dist/index.js +4 -25
- package/dist/mockserver-config/index.d.ts +1 -1
- package/dist/mockserver-config/index.js +13 -17
- package/dist/mockserver-config/package-json.d.ts +1 -1
- package/dist/mockserver-config/package-json.js +5 -9
- package/dist/mockserver-config/ui5-mock-yaml.d.ts +1 -1
- package/dist/mockserver-config/ui5-mock-yaml.js +22 -27
- package/dist/prompt/index.js +12 -15
- package/dist/types/index.js +1 -2
- package/package.json +5 -4
package/dist/app-info.js
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getMainServiceDataSource = getMainServiceDataSource;
|
|
4
|
-
exports.getODataSources = getODataSources;
|
|
5
1
|
/**
|
|
6
2
|
* Get the main service data source name from manifest.json.
|
|
7
3
|
*
|
|
@@ -18,7 +14,7 @@ function getMainServiceDataSourceName(manifest) {
|
|
|
18
14
|
* @param manifest - Parsed manifest.json
|
|
19
15
|
* @returns - data source entry from manifest.json, parsed
|
|
20
16
|
*/
|
|
21
|
-
function getMainServiceDataSource(manifest) {
|
|
17
|
+
export function getMainServiceDataSource(manifest) {
|
|
22
18
|
let dataSource;
|
|
23
19
|
const dataSourceName = getMainServiceDataSourceName(manifest);
|
|
24
20
|
if (dataSourceName) {
|
|
@@ -33,7 +29,7 @@ function getMainServiceDataSource(manifest) {
|
|
|
33
29
|
* @param dataSourceType - optional to specify the type of OData sources to filter
|
|
34
30
|
* @returns data sources of type 'OData'
|
|
35
31
|
*/
|
|
36
|
-
function getODataSources(manifest, dataSourceType = 'OData') {
|
|
32
|
+
export function getODataSources(manifest, dataSourceType = 'OData') {
|
|
37
33
|
const result = {};
|
|
38
34
|
const dataSources = manifest['sap.app']?.dataSources ?? {};
|
|
39
35
|
for (const dataSource in dataSources) {
|
package/dist/i18n.js
CHANGED
|
@@ -1,22 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.initI18n = initI18n;
|
|
7
|
-
exports.t = t;
|
|
8
|
-
const i18next_1 = __importDefault(require("i18next"));
|
|
9
|
-
const mockserver_config_writer_i18n_json_1 = __importDefault(require("./translations/mockserver-config-writer.i18n.json"));
|
|
1
|
+
import i18next from 'i18next';
|
|
2
|
+
import translations from './translations/mockserver-config-writer.i18n.json' with { type: 'json' };
|
|
10
3
|
const NS = 'mockserver-config-writer';
|
|
11
4
|
let i18nInstance;
|
|
12
5
|
/**
|
|
13
6
|
* Initialize i18next with the translations for this module.
|
|
14
7
|
*/
|
|
15
|
-
async function initI18n() {
|
|
16
|
-
i18nInstance =
|
|
8
|
+
export async function initI18n() {
|
|
9
|
+
i18nInstance = i18next.createInstance({
|
|
17
10
|
resources: {
|
|
18
11
|
en: {
|
|
19
|
-
[NS]:
|
|
12
|
+
[NS]: translations
|
|
20
13
|
}
|
|
21
14
|
},
|
|
22
15
|
lng: 'en',
|
|
@@ -34,7 +27,7 @@ async function initI18n() {
|
|
|
34
27
|
* @param options additional options
|
|
35
28
|
* @returns {string} localized string stored for the given key
|
|
36
29
|
*/
|
|
37
|
-
function t(key, options) {
|
|
30
|
+
export function t(key, options) {
|
|
38
31
|
return i18nInstance.t(key, options);
|
|
39
32
|
}
|
|
40
33
|
initI18n().catch(() => {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { generateMockserverConfig, removeMockserverConfig } from './mockserver-config';
|
|
2
|
-
export { getMockserverConfigQuestions } from './prompt';
|
|
3
|
-
export { t } from './i18n';
|
|
4
|
-
export * from './types';
|
|
1
|
+
export { generateMockserverConfig, removeMockserverConfig } from './mockserver-config/index.js';
|
|
2
|
+
export { getMockserverConfigQuestions } from './prompt/index.js';
|
|
3
|
+
export { t } from './i18n.js';
|
|
4
|
+
export * from './types/index.js';
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,26 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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.t = exports.getMockserverConfigQuestions = exports.removeMockserverConfig = exports.generateMockserverConfig = void 0;
|
|
18
|
-
var mockserver_config_1 = require("./mockserver-config");
|
|
19
|
-
Object.defineProperty(exports, "generateMockserverConfig", { enumerable: true, get: function () { return mockserver_config_1.generateMockserverConfig; } });
|
|
20
|
-
Object.defineProperty(exports, "removeMockserverConfig", { enumerable: true, get: function () { return mockserver_config_1.removeMockserverConfig; } });
|
|
21
|
-
var prompt_1 = require("./prompt");
|
|
22
|
-
Object.defineProperty(exports, "getMockserverConfigQuestions", { enumerable: true, get: function () { return prompt_1.getMockserverConfigQuestions; } });
|
|
23
|
-
var i18n_1 = require("./i18n");
|
|
24
|
-
Object.defineProperty(exports, "t", { enumerable: true, get: function () { return i18n_1.t; } });
|
|
25
|
-
__exportStar(require("./types"), exports);
|
|
1
|
+
export { generateMockserverConfig, removeMockserverConfig } from './mockserver-config/index.js';
|
|
2
|
+
export { getMockserverConfigQuestions } from './prompt/index.js';
|
|
3
|
+
export { t } from './i18n.js';
|
|
4
|
+
export * from './types/index.js';
|
|
26
5
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const mem_fs_1 = require("mem-fs");
|
|
6
|
-
const mem_fs_editor_1 = require("mem-fs-editor");
|
|
7
|
-
const package_json_1 = require("./package-json");
|
|
8
|
-
const ui5_mock_yaml_1 = require("./ui5-mock-yaml");
|
|
1
|
+
import { create as createStorage } from 'mem-fs';
|
|
2
|
+
import { create } from 'mem-fs-editor';
|
|
3
|
+
import { enhancePackageJson, removeFromPackageJson } from './package-json.js';
|
|
4
|
+
import { enhanceYaml, removeMockDataFolders, removeUi5MockYaml } from './ui5-mock-yaml.js';
|
|
9
5
|
/**
|
|
10
6
|
* Add mockserver configuration to a UI5 application.
|
|
11
7
|
*
|
|
@@ -14,14 +10,14 @@ const ui5_mock_yaml_1 = require("./ui5-mock-yaml");
|
|
|
14
10
|
* @param fs - the memfs editor instance
|
|
15
11
|
* @returns Promise<Editor> - memfs editor instance with updated files
|
|
16
12
|
*/
|
|
17
|
-
async function generateMockserverConfig(basePath, data, fs) {
|
|
13
|
+
export async function generateMockserverConfig(basePath, data, fs) {
|
|
18
14
|
if (!fs) {
|
|
19
|
-
fs =
|
|
15
|
+
fs = create(createStorage());
|
|
20
16
|
}
|
|
21
17
|
if (!data.packageJsonConfig?.skip) {
|
|
22
|
-
|
|
18
|
+
enhancePackageJson(fs, basePath, data.packageJsonConfig);
|
|
23
19
|
}
|
|
24
|
-
await
|
|
20
|
+
await enhanceYaml(fs, basePath, data.webappPath, data.ui5MockYamlConfig);
|
|
25
21
|
return fs;
|
|
26
22
|
}
|
|
27
23
|
/**
|
|
@@ -31,13 +27,13 @@ async function generateMockserverConfig(basePath, data, fs) {
|
|
|
31
27
|
* @param fs - the memfs editor instance
|
|
32
28
|
* @returns Promise<Editor> - memfs editor instance with updated files
|
|
33
29
|
*/
|
|
34
|
-
async function removeMockserverConfig(basePath, fs) {
|
|
30
|
+
export async function removeMockserverConfig(basePath, fs) {
|
|
35
31
|
if (!fs) {
|
|
36
|
-
fs =
|
|
32
|
+
fs = create(createStorage());
|
|
37
33
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
await
|
|
34
|
+
removeFromPackageJson(fs, basePath);
|
|
35
|
+
removeUi5MockYaml(fs, basePath);
|
|
36
|
+
await removeMockDataFolders(fs, basePath);
|
|
41
37
|
return fs;
|
|
42
38
|
}
|
|
43
39
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.enhancePackageJson = enhancePackageJson;
|
|
4
|
-
exports.removeFromPackageJson = removeFromPackageJson;
|
|
5
|
-
const node_path_1 = require("node:path");
|
|
1
|
+
import { join } from 'node:path';
|
|
6
2
|
/**
|
|
7
3
|
* Enhance the package.json with dependency for mockserver.
|
|
8
4
|
*
|
|
@@ -10,8 +6,8 @@ const node_path_1 = require("node:path");
|
|
|
10
6
|
* @param basePath - path to application root, where package.json is
|
|
11
7
|
* @param config - optional config for mockserver
|
|
12
8
|
*/
|
|
13
|
-
function enhancePackageJson(fs, basePath, config) {
|
|
14
|
-
const packageJsonPath =
|
|
9
|
+
export function enhancePackageJson(fs, basePath, config) {
|
|
10
|
+
const packageJsonPath = join(basePath, 'package.json');
|
|
15
11
|
const packageJson = fs.readJSON(packageJsonPath);
|
|
16
12
|
enhanceDependencies(packageJson, config?.mockserverModule, config?.mockserverVersion);
|
|
17
13
|
enhanceScripts(fs, packageJson);
|
|
@@ -142,8 +138,8 @@ function removeMockserverUi5Dependencies(packageJson) {
|
|
|
142
138
|
* @param fs - mem-fs reference to be used for file access
|
|
143
139
|
* @param basePath - path to application root, where package.json is
|
|
144
140
|
*/
|
|
145
|
-
function removeFromPackageJson(fs, basePath) {
|
|
146
|
-
const packageJsonPath =
|
|
141
|
+
export function removeFromPackageJson(fs, basePath) {
|
|
142
|
+
const packageJsonPath = join(basePath, 'package.json');
|
|
147
143
|
const packageJson = fs.readJSON(packageJsonPath);
|
|
148
144
|
delete packageJson.scripts?.['start-mock'];
|
|
149
145
|
if (packageJson.scripts && Object.keys(packageJson.scripts).length === 0) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Editor } from 'mem-fs-editor';
|
|
2
|
-
import type { Ui5MockYamlConfig } from '../types';
|
|
2
|
+
import type { Ui5MockYamlConfig } from '../types/index.js';
|
|
3
3
|
/**
|
|
4
4
|
* Enhance or create the ui5-mock.yaml with mockserver config.
|
|
5
5
|
* Mockserver config services and annotations are collected from associated manifest.json file of the project.
|
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
exports.removeUi5MockYaml = removeUi5MockYaml;
|
|
6
|
-
const node_path_1 = require("node:path");
|
|
7
|
-
const ui5_config_1 = require("@sap-ux/ui5-config");
|
|
8
|
-
const project_access_1 = require("@sap-ux/project-access");
|
|
9
|
-
const app_info_1 = require("../app-info");
|
|
1
|
+
import { join, posix, relative, sep } from 'node:path';
|
|
2
|
+
import { UI5Config } from '@sap-ux/ui5-config';
|
|
3
|
+
import { DirName, FileName, getWebappPath, readUi5Yaml } from '@sap-ux/project-access';
|
|
4
|
+
import { getODataSources } from '../app-info.js';
|
|
10
5
|
/**
|
|
11
6
|
* Enhance or create the ui5-mock.yaml with mockserver config.
|
|
12
7
|
* Mockserver config services and annotations are collected from associated manifest.json file of the project.
|
|
@@ -29,13 +24,13 @@ const app_info_1 = require("../app-info");
|
|
|
29
24
|
* @param webappPath - path to webapp folder, where manifest.json is
|
|
30
25
|
* @param config - optional config passed in by consumer
|
|
31
26
|
*/
|
|
32
|
-
async function enhanceYaml(fs, basePath, webappPath, config) {
|
|
27
|
+
export async function enhanceYaml(fs, basePath, webappPath, config) {
|
|
33
28
|
const overwrite = !!config?.overwrite;
|
|
34
|
-
const ui5MockYamlPath =
|
|
29
|
+
const ui5MockYamlPath = join(basePath, 'ui5-mock.yaml');
|
|
35
30
|
let mockConfig;
|
|
36
|
-
const manifest = fs.readJSON(
|
|
31
|
+
const manifest = fs.readJSON(join(webappPath, 'manifest.json'));
|
|
37
32
|
// Prepare annotations list to be used in mockserver middleware config annotations
|
|
38
|
-
const annotationSource = Object.values(
|
|
33
|
+
const annotationSource = Object.values(getODataSources(manifest, 'ODataAnnotation'));
|
|
39
34
|
const annotationsConfig = [];
|
|
40
35
|
annotationSource.forEach((annotation) => {
|
|
41
36
|
// Ignore local annotations from YAML file, those are linked through manifest file
|
|
@@ -43,14 +38,14 @@ async function enhanceYaml(fs, basePath, webappPath, config) {
|
|
|
43
38
|
const localUri = annotation.settings?.localUri;
|
|
44
39
|
annotationsConfig.push({
|
|
45
40
|
localPath: localUri
|
|
46
|
-
? `.${
|
|
41
|
+
? `.${posix.sep}${relative(basePath, join(webappPath, localUri)).replaceAll(sep, posix.sep)}`
|
|
47
42
|
: undefined,
|
|
48
43
|
urlPath: annotation.uri
|
|
49
44
|
});
|
|
50
45
|
}
|
|
51
46
|
});
|
|
52
47
|
// Prepare dataSources list to be used in mockserver middleware config services
|
|
53
|
-
const dataSources =
|
|
48
|
+
const dataSources = getODataSources(manifest);
|
|
54
49
|
const dataSourcesConfig = [];
|
|
55
50
|
for (const dataSource in dataSources) {
|
|
56
51
|
const localUri = dataSources[dataSource].settings?.localUri;
|
|
@@ -59,7 +54,7 @@ async function enhanceYaml(fs, basePath, webappPath, config) {
|
|
|
59
54
|
serviceName: dataSource,
|
|
60
55
|
servicePath: dataSources[dataSource].uri,
|
|
61
56
|
metadataPath: localUri
|
|
62
|
-
? `.${
|
|
57
|
+
? `.${posix.sep}${relative(basePath, join(webappPath, localUri)).replaceAll(sep, posix.sep)}`
|
|
63
58
|
: undefined,
|
|
64
59
|
resolveExternalServiceReferences
|
|
65
60
|
});
|
|
@@ -68,7 +63,7 @@ async function enhanceYaml(fs, basePath, webappPath, config) {
|
|
|
68
63
|
mockConfig = await updateUi5MockYamlConfig(fs, basePath, webappPath, ui5MockYamlPath, dataSourcesConfig, annotationsConfig, overwrite);
|
|
69
64
|
}
|
|
70
65
|
else {
|
|
71
|
-
mockConfig = fs.exists(
|
|
66
|
+
mockConfig = fs.exists(join(basePath, 'ui5.yaml'))
|
|
72
67
|
? await generateUi5MockYamlBasedOnUi5Yaml(fs, basePath, webappPath, dataSourcesConfig, annotationsConfig)
|
|
73
68
|
: await generateNewUi5MockYamlConfig(manifest['sap.app']?.id || '', basePath, webappPath, dataSourcesConfig, annotationsConfig);
|
|
74
69
|
}
|
|
@@ -81,16 +76,16 @@ async function enhanceYaml(fs, basePath, webappPath, config) {
|
|
|
81
76
|
* @param fs - mem-fs reference to be used for file access
|
|
82
77
|
* @param basePath - path to project root, where package.json and ui5.yaml is
|
|
83
78
|
*/
|
|
84
|
-
async function removeMockDataFolders(fs, basePath) {
|
|
85
|
-
const webappPath = await
|
|
86
|
-
const manifestPath =
|
|
79
|
+
export async function removeMockDataFolders(fs, basePath) {
|
|
80
|
+
const webappPath = await getWebappPath(basePath, fs);
|
|
81
|
+
const manifestPath = join(webappPath, FileName.Manifest);
|
|
87
82
|
const manifest = fs.readJSON(manifestPath);
|
|
88
83
|
// Read service names from manifest.json
|
|
89
84
|
const dataSources = manifest['sap.app'].dataSources;
|
|
90
85
|
if (dataSources) {
|
|
91
86
|
const serviceNames = Object.keys(dataSources);
|
|
92
87
|
serviceNames.forEach((serviceName) => {
|
|
93
|
-
const mockdataPath =
|
|
88
|
+
const mockdataPath = join(webappPath, DirName.LocalService, serviceName, DirName.Data);
|
|
94
89
|
if (mockdataPath) {
|
|
95
90
|
fs.delete(mockdataPath);
|
|
96
91
|
}
|
|
@@ -112,7 +107,7 @@ async function removeMockDataFolders(fs, basePath) {
|
|
|
112
107
|
* @returns {*} {Promise<UI5Config>} - Updated Yaml Doc
|
|
113
108
|
*/
|
|
114
109
|
async function updateUi5MockYamlConfig(fs, basePath, webappPath, ui5MockYamlPath, dataSourcesConfig, annotationsConfig, overwrite = false) {
|
|
115
|
-
const existingUi5MockYamlConfig = await
|
|
110
|
+
const existingUi5MockYamlConfig = await UI5Config.newInstance(fs.read(ui5MockYamlPath));
|
|
116
111
|
if (overwrite) {
|
|
117
112
|
const newMockserverMiddleware = await getNewMockserverMiddleware(basePath, webappPath, dataSourcesConfig, annotationsConfig);
|
|
118
113
|
existingUi5MockYamlConfig.updateCustomMiddleware(newMockserverMiddleware);
|
|
@@ -135,7 +130,7 @@ async function updateUi5MockYamlConfig(fs, basePath, webappPath, ui5MockYamlPath
|
|
|
135
130
|
* @returns {*} {Promise<UI5Config>} - Update Yaml Doc
|
|
136
131
|
*/
|
|
137
132
|
async function generateUi5MockYamlBasedOnUi5Yaml(fs, basePath, webappPath, dataSourcesConfig, annotationsConfig) {
|
|
138
|
-
const ui5MockYamlConfig = await
|
|
133
|
+
const ui5MockYamlConfig = await readUi5Yaml(basePath, FileName.Ui5Yaml, fs);
|
|
139
134
|
const ui5MockServerMiddleware = await getNewMockserverMiddleware(basePath, webappPath, dataSourcesConfig, annotationsConfig);
|
|
140
135
|
ui5MockYamlConfig.updateCustomMiddleware(ui5MockServerMiddleware);
|
|
141
136
|
return ui5MockYamlConfig;
|
|
@@ -151,7 +146,7 @@ async function generateUi5MockYamlBasedOnUi5Yaml(fs, basePath, webappPath, dataS
|
|
|
151
146
|
* @returns {*} {Promise<UI5Config>} - Update Yaml Doc
|
|
152
147
|
*/
|
|
153
148
|
async function generateNewUi5MockYamlConfig(appId, basePath, webappPath, dataSourcesConfig, annotationsConfig) {
|
|
154
|
-
const ui5MockYaml = await
|
|
149
|
+
const ui5MockYaml = await UI5Config.newInstance('# yaml-language-server: $schema=https://sap.github.io/ui5-tooling/schema/ui5.yaml.json\n\nspecVersion: "2.5"');
|
|
155
150
|
ui5MockYaml.setMetadata({ name: appId });
|
|
156
151
|
ui5MockYaml.setType('application');
|
|
157
152
|
ui5MockYaml.addFioriToolsProxyMiddleware({ ui5: {} });
|
|
@@ -169,7 +164,7 @@ async function generateNewUi5MockYamlConfig(appId, basePath, webappPath, dataSou
|
|
|
169
164
|
* @returns - mockserver middleware
|
|
170
165
|
*/
|
|
171
166
|
async function getNewMockserverMiddleware(basePath, webappPath, dataSourcesConfig, annotationsConfig) {
|
|
172
|
-
const ui5MockYaml = await
|
|
167
|
+
const ui5MockYaml = await UI5Config.newInstance('');
|
|
173
168
|
ui5MockYaml.addMockServerMiddleware(basePath, webappPath, dataSourcesConfig, annotationsConfig);
|
|
174
169
|
const mockserverMiddleware = ui5MockYaml.findCustomMiddleware('sap-fe-mockserver');
|
|
175
170
|
if (!mockserverMiddleware) {
|
|
@@ -183,8 +178,8 @@ async function getNewMockserverMiddleware(basePath, webappPath, dataSourcesConfi
|
|
|
183
178
|
* @param fs - mem-fs reference to be used for file access
|
|
184
179
|
* @param basePath - path to project root, where package.json and ui5.yaml is
|
|
185
180
|
*/
|
|
186
|
-
function removeUi5MockYaml(fs, basePath) {
|
|
187
|
-
const ui5MockYamlPath =
|
|
181
|
+
export function removeUi5MockYaml(fs, basePath) {
|
|
182
|
+
const ui5MockYamlPath = join(basePath, 'ui5-mock.yaml');
|
|
188
183
|
if (fs.exists(ui5MockYamlPath)) {
|
|
189
184
|
fs.delete(ui5MockYamlPath);
|
|
190
185
|
}
|
package/dist/prompt/index.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const mem_fs_editor_1 = require("mem-fs-editor");
|
|
7
|
-
const app_info_1 = require("../app-info");
|
|
8
|
-
const __1 = require("..");
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
import { create as createStorage } from 'mem-fs';
|
|
3
|
+
import { create } from 'mem-fs-editor';
|
|
4
|
+
import { getODataSources, getMainServiceDataSource } from '../app-info.js';
|
|
5
|
+
import { t } from '../index.js';
|
|
9
6
|
/**
|
|
10
7
|
* Return the list of questions to configure mockserver.
|
|
11
8
|
*
|
|
@@ -15,17 +12,17 @@ const __1 = require("..");
|
|
|
15
12
|
* @param params.fs - optional memfs editor instance
|
|
16
13
|
* @returns - array of questions that serves as input for prompt module
|
|
17
14
|
*/
|
|
18
|
-
function getMockserverConfigQuestions(params) {
|
|
15
|
+
export function getMockserverConfigQuestions(params) {
|
|
19
16
|
const prompts = [];
|
|
20
17
|
const questionPath = {
|
|
21
18
|
name: 'path',
|
|
22
|
-
message:
|
|
19
|
+
message: t('questions.pathToMock')
|
|
23
20
|
};
|
|
24
21
|
if (params?.webappPath) {
|
|
25
|
-
const fs = params.fs ??
|
|
26
|
-
const manifest = JSON.parse(fs.read(
|
|
27
|
-
const mainDataSourceUri =
|
|
28
|
-
const oDataSources =
|
|
22
|
+
const fs = params.fs ?? create(createStorage());
|
|
23
|
+
const manifest = JSON.parse(fs.read(join(params.webappPath, 'manifest.json')));
|
|
24
|
+
const mainDataSourceUri = getMainServiceDataSource(manifest)?.uri ?? '';
|
|
25
|
+
const oDataSources = getODataSources(manifest);
|
|
29
26
|
const choices = [];
|
|
30
27
|
for (const dsName in oDataSources) {
|
|
31
28
|
choices.push({
|
|
@@ -46,7 +43,7 @@ function getMockserverConfigQuestions(params) {
|
|
|
46
43
|
const questionOverwrite = {
|
|
47
44
|
type: 'confirm',
|
|
48
45
|
name: 'overwrite',
|
|
49
|
-
message:
|
|
46
|
+
message: t('questions.overwrite')
|
|
50
47
|
};
|
|
51
48
|
prompts.push(questionOverwrite);
|
|
52
49
|
}
|
package/dist/types/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sap-ux/mockserver-config-writer",
|
|
3
3
|
"description": "Add or update configuration for SAP Fiori tools mockserver",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "1.0.0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "https://github.com/SAP/open-ux-tools.git",
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"bugs": {
|
|
11
11
|
"url": "https://github.com/SAP/open-ux-tools/issues?q=is%3Aopen+is%3Aissue+label%3Abug+label%3Amockserver-config-writer"
|
|
12
12
|
},
|
|
13
|
+
"type": "module",
|
|
13
14
|
"license": "Apache-2.0",
|
|
14
15
|
"main": "dist/index.js",
|
|
15
16
|
"files": [
|
|
@@ -22,8 +23,8 @@
|
|
|
22
23
|
"i18next": "25.10.10",
|
|
23
24
|
"mem-fs": "2.1.0",
|
|
24
25
|
"mem-fs-editor": "9.4.0",
|
|
25
|
-
"@sap-ux/project-access": "
|
|
26
|
-
"@sap-ux/ui5-config": "0.
|
|
26
|
+
"@sap-ux/project-access": "2.0.0",
|
|
27
|
+
"@sap-ux/ui5-config": "1.0.0"
|
|
27
28
|
},
|
|
28
29
|
"devDependencies": {
|
|
29
30
|
"@types/mem-fs": "1.1.2",
|
|
@@ -40,7 +41,7 @@
|
|
|
40
41
|
"format": "prettier --write '**/*.{js,json,ts,yaml,yml}' --ignore-path ../../.prettierignore",
|
|
41
42
|
"lint": "eslint",
|
|
42
43
|
"lint:fix": "eslint --fix",
|
|
43
|
-
"test": "jest --ci --forceExit --detectOpenHandles --colors",
|
|
44
|
+
"test": "cross-env NODE_OPTIONS='--experimental-vm-modules' jest --ci --forceExit --detectOpenHandles --colors",
|
|
44
45
|
"watch": "tsc --watch"
|
|
45
46
|
}
|
|
46
47
|
}
|