@sap-ux/odata-service-inquirer 0.3.11 → 0.4.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/error-handler/error-handler.js +108 -109
- package/dist/i18n.js +12 -23
- package/dist/index.js +20 -33
- package/dist/prompts/datasources/cap-project/cap-helpers.js +87 -127
- package/dist/prompts/datasources/cap-project/questions.js +29 -42
- package/dist/prompts/datasources/cap-project/validators.js +9 -20
- package/dist/prompts/datasources/metadata-file/index.js +3 -12
- package/dist/prompts/datasources/metadata-file/validators.js +4 -13
- package/dist/prompts/datasources/service-url/connectionValidator.js +93 -111
- package/dist/prompts/datasources/service-url/questions.js +18 -27
- package/dist/prompts/datasources/service-url/validators.js +48 -60
- package/dist/prompts/logger-helper.js +1 -1
- package/dist/prompts/prompts.js +14 -29
- package/dist/types.js +3 -0
- package/dist/utils/prompt-state.js +2 -2
- package/package.json +9 -9
|
@@ -1,20 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
12
|
-
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
13
|
-
var m = o[Symbol.asyncIterator], i;
|
|
14
|
-
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
15
|
-
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
16
|
-
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
17
|
-
};
|
|
18
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
19
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
20
4
|
};
|
|
@@ -32,24 +16,21 @@ exports.enterCapPathChoiceValue = 'enterCapPath';
|
|
|
32
16
|
* @param paths - The paths used to search for CAP projects
|
|
33
17
|
* @returns The CAP project paths and the number of folders with the same name
|
|
34
18
|
*/
|
|
35
|
-
function getCapProjectPaths(paths) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
capRootPaths
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
folderCounts: folderNameCount
|
|
51
|
-
};
|
|
52
|
-
});
|
|
19
|
+
async function getCapProjectPaths(paths) {
|
|
20
|
+
const capProjectRoots = await (0, project_access_1.findCapProjects)({ wsFolders: paths });
|
|
21
|
+
const capRootPaths = [];
|
|
22
|
+
// Keep track of duplicate folder names to append the path to the name when displaying the choices
|
|
23
|
+
const folderNameCount = new Map();
|
|
24
|
+
for (const root of capProjectRoots) {
|
|
25
|
+
const folderName = (0, path_1.basename)(root);
|
|
26
|
+
capRootPaths.push({ folderName, path: root });
|
|
27
|
+
folderNameCount.set(folderName, (folderNameCount.get(folderName) ?? 0) + 1);
|
|
28
|
+
}
|
|
29
|
+
capRootPaths.sort((a, b) => a.folderName.localeCompare(b.folderName));
|
|
30
|
+
return {
|
|
31
|
+
capProjectPaths: capRootPaths,
|
|
32
|
+
folderCounts: folderNameCount
|
|
33
|
+
};
|
|
53
34
|
}
|
|
54
35
|
/**
|
|
55
36
|
* Search for CAP projects in the specified paths and create prompt choices from the results.
|
|
@@ -58,40 +39,24 @@ function getCapProjectPaths(paths) {
|
|
|
58
39
|
* @param paths - The paths used to search for CAP projects
|
|
59
40
|
* @returns The CAP project prompt choices
|
|
60
41
|
*/
|
|
61
|
-
function getCapProjectChoices(paths) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
81
|
-
finally {
|
|
82
|
-
try {
|
|
83
|
-
if (!_e && !_a && (_b = capProjectPaths_1.return)) yield _b.call(capProjectPaths_1);
|
|
84
|
-
}
|
|
85
|
-
finally { if (e_1) throw e_1.error; }
|
|
42
|
+
async function getCapProjectChoices(paths) {
|
|
43
|
+
const { capProjectPaths, folderCounts } = await getCapProjectPaths(paths);
|
|
44
|
+
const capChoices = [];
|
|
45
|
+
for await (const capProjectPath of capProjectPaths) {
|
|
46
|
+
const customCapPaths = await (0, project_access_1.getCapCustomPaths)(capProjectPath.path);
|
|
47
|
+
const folderCount = folderCounts.get(capProjectPath.folderName) ?? 1;
|
|
48
|
+
capChoices.push({
|
|
49
|
+
name: `${capProjectPath.folderName}${folderCount > 1 ? ' (' + capProjectPath.path + ')' : ''}`,
|
|
50
|
+
value: Object.assign(capProjectPath, customCapPaths)
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
return [
|
|
54
|
+
...capChoices,
|
|
55
|
+
{
|
|
56
|
+
name: (0, i18n_1.t)('prompts.capProject.enterCapPathChoiceName'),
|
|
57
|
+
value: exports.enterCapPathChoiceValue
|
|
86
58
|
}
|
|
87
|
-
|
|
88
|
-
...capChoices,
|
|
89
|
-
{
|
|
90
|
-
name: (0, i18n_1.t)('prompts.capProject.enterCapPathChoiceName'),
|
|
91
|
-
value: exports.enterCapPathChoiceValue
|
|
92
|
-
}
|
|
93
|
-
];
|
|
94
|
-
});
|
|
59
|
+
];
|
|
95
60
|
}
|
|
96
61
|
exports.getCapProjectChoices = getCapProjectChoices;
|
|
97
62
|
/**
|
|
@@ -105,16 +70,15 @@ exports.getCapProjectChoices = getCapProjectChoices;
|
|
|
105
70
|
* @returns a cap service choice
|
|
106
71
|
*/
|
|
107
72
|
function createCapServiceChoice(capModel, serviceInfo, projectPath, appPath, cdsVersionInfo) {
|
|
108
|
-
|
|
109
|
-
const srvDef = (_a = capModel.definitions) === null || _a === void 0 ? void 0 : _a[serviceInfo.name];
|
|
73
|
+
const srvDef = capModel.definitions?.[serviceInfo.name];
|
|
110
74
|
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
|
|
111
|
-
const serviceFilePath =
|
|
75
|
+
const serviceFilePath = srvDef?.$location?.file;
|
|
112
76
|
logger_helper_1.default.logger.debug(`Cap service def: ${JSON.stringify(srvDef)}`);
|
|
113
77
|
logger_helper_1.default.logger.debug(`Cap service def $location.file: ${JSON.stringify(serviceFilePath)}`);
|
|
114
78
|
// Find the source path for the service definition file, we cannot resolve '../' path segments as
|
|
115
79
|
// we have no idea where the cwd was when the cds compiler was run. Remove the '../' or '..\\' path segments so the relative path can
|
|
116
80
|
// be resolved against the project root. This is a workaround until cds provides the correct path in the service info.
|
|
117
|
-
const absServicePath =
|
|
81
|
+
const absServicePath = capModel.$sources?.find((source) => source.indexOf(serviceFilePath.replace(/\.\.\\\\|\.\.\\|\.\.\//g, '')) > -1);
|
|
118
82
|
logger_helper_1.default.logger.debug(`Source file path for service: ${serviceInfo.name}: ${absServicePath}`);
|
|
119
83
|
if (absServicePath && (0, path_1.isAbsolute)(absServicePath)) {
|
|
120
84
|
let serviceCdsFilePath = (0, path_1.relative)(projectPath, absServicePath);
|
|
@@ -147,50 +111,48 @@ function createCapServiceChoice(capModel, serviceInfo, projectPath, appPath, cds
|
|
|
147
111
|
* @param capProjectPaths - The CAP project paths
|
|
148
112
|
* @returns The CAP project service choices
|
|
149
113
|
*/
|
|
150
|
-
function getCapServiceChoices(capProjectPaths) {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
114
|
+
async function getCapServiceChoices(capProjectPaths) {
|
|
115
|
+
logger_helper_1.default.logger.debug(`getCapServiceChoices: ${JSON.stringify(capProjectPaths)}`);
|
|
116
|
+
if (!capProjectPaths) {
|
|
117
|
+
return [];
|
|
118
|
+
}
|
|
119
|
+
try {
|
|
120
|
+
let capServices = [];
|
|
121
|
+
let capModel;
|
|
122
|
+
let capCdsVersionInfo;
|
|
156
123
|
try {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
});
|
|
169
|
-
capServices = services;
|
|
170
|
-
capModel = model;
|
|
171
|
-
capCdsVersionInfo = cdsVersionInfo;
|
|
172
|
-
}
|
|
173
|
-
catch (error) {
|
|
174
|
-
prompt_helpers_1.errorHandler.logErrorMsgs(error);
|
|
175
|
-
logger_helper_1.default.logger.error((0, i18n_1.t)('errors.capModelAndServicesLoadError', { error: error === null || error === void 0 ? void 0 : error.message }));
|
|
176
|
-
return [];
|
|
177
|
-
}
|
|
178
|
-
// We need the relative service definitions file paths (.cds) for the generated annotation file
|
|
179
|
-
const projectPath = capProjectPaths.path;
|
|
180
|
-
const appPath = capProjectPaths.app;
|
|
181
|
-
logger_helper_1.default.logger.debug(`CDS model source paths: ${JSON.stringify(capModel.$sources)}`);
|
|
182
|
-
const serviceChoices = capServices
|
|
183
|
-
.map((service) => {
|
|
184
|
-
return createCapServiceChoice(capModel, service, projectPath, appPath, capCdsVersionInfo);
|
|
185
|
-
})
|
|
186
|
-
.filter((service) => !!service); // filter undefined entries
|
|
187
|
-
return serviceChoices !== null && serviceChoices !== void 0 ? serviceChoices : [];
|
|
124
|
+
// Workaround for missing clear cache functionality in `getCapModelAnsdServices`, this resets the cds.resolve.cache.
|
|
125
|
+
// If this is not done then errors can be thrown where out-of-processs changes to the files system have occurred
|
|
126
|
+
await (0, project_access_1.getCdsRoots)(capProjectPaths.path, true);
|
|
127
|
+
// Load the CAP model and services
|
|
128
|
+
const { model, services, cdsVersionInfo } = await (0, project_access_1.getCapModelAndServices)({
|
|
129
|
+
projectRoot: capProjectPaths.path,
|
|
130
|
+
logger: logger_helper_1.default.logger
|
|
131
|
+
});
|
|
132
|
+
capServices = services;
|
|
133
|
+
capModel = model;
|
|
134
|
+
capCdsVersionInfo = cdsVersionInfo;
|
|
188
135
|
}
|
|
189
|
-
catch (
|
|
190
|
-
prompt_helpers_1.errorHandler.logErrorMsgs(
|
|
136
|
+
catch (error) {
|
|
137
|
+
prompt_helpers_1.errorHandler.logErrorMsgs(error);
|
|
138
|
+
logger_helper_1.default.logger.error((0, i18n_1.t)('errors.capModelAndServicesLoadError', { error: error?.message }));
|
|
139
|
+
return [];
|
|
191
140
|
}
|
|
192
|
-
|
|
193
|
-
|
|
141
|
+
// We need the relative service definitions file paths (.cds) for the generated annotation file
|
|
142
|
+
const projectPath = capProjectPaths.path;
|
|
143
|
+
const appPath = capProjectPaths.app;
|
|
144
|
+
logger_helper_1.default.logger.debug(`CDS model source paths: ${JSON.stringify(capModel.$sources)}`);
|
|
145
|
+
const serviceChoices = capServices
|
|
146
|
+
.map((service) => {
|
|
147
|
+
return createCapServiceChoice(capModel, service, projectPath, appPath, capCdsVersionInfo);
|
|
148
|
+
})
|
|
149
|
+
.filter((service) => !!service); // filter undefined entries
|
|
150
|
+
return serviceChoices ?? [];
|
|
151
|
+
}
|
|
152
|
+
catch (err) {
|
|
153
|
+
prompt_helpers_1.errorHandler.logErrorMsgs(err);
|
|
154
|
+
}
|
|
155
|
+
return [];
|
|
194
156
|
}
|
|
195
157
|
exports.getCapServiceChoices = getCapServiceChoices;
|
|
196
158
|
/**
|
|
@@ -199,21 +161,19 @@ exports.getCapServiceChoices = getCapServiceChoices;
|
|
|
199
161
|
* @param capService - The CAP service
|
|
200
162
|
* @returns The edmx metadata for the CAP service
|
|
201
163
|
*/
|
|
202
|
-
function getCapEdmx(capService) {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
}
|
|
216
|
-
});
|
|
164
|
+
async function getCapEdmx(capService) {
|
|
165
|
+
if (!capService.urlPath) {
|
|
166
|
+
const errorMsg = (0, i18n_1.t)('errors.capServiceUrlPathNotDefined', { serviceName: capService.serviceName });
|
|
167
|
+
prompt_helpers_1.errorHandler.logErrorMsgs(errorMsg);
|
|
168
|
+
return undefined;
|
|
169
|
+
}
|
|
170
|
+
try {
|
|
171
|
+
return await (0, project_access_1.readCapServiceMetadataEdmx)(capService.projectPath, capService.urlPath, 'v4');
|
|
172
|
+
}
|
|
173
|
+
catch (error) {
|
|
174
|
+
prompt_helpers_1.errorHandler.logErrorMsgs((0, i18n_1.t)('errors.cannotReadCapServiceMetadata', { serviceName: capService.serviceName }));
|
|
175
|
+
logger_helper_1.default.logger.error(error);
|
|
176
|
+
}
|
|
217
177
|
}
|
|
218
178
|
exports.getCapEdmx = getCapEdmx;
|
|
219
179
|
//# sourceMappingURL=cap-helpers.js.map
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.getLocalCapProjectPrompts = void 0;
|
|
13
4
|
const odata_service_writer_1 = require("@sap-ux/odata-service-writer");
|
|
@@ -49,21 +40,19 @@ function getDefaultCapChoice(capChoices, defaultChoicePath) {
|
|
|
49
40
|
* @returns the prompt used to provide input for selecting a CAP project
|
|
50
41
|
*/
|
|
51
42
|
function getLocalCapProjectPrompts(promptOptions) {
|
|
52
|
-
var _a, _b;
|
|
53
43
|
let capChoices = [];
|
|
54
|
-
const defaultCapPath =
|
|
55
|
-
const defaultCapService =
|
|
44
|
+
const defaultCapPath = promptOptions?.[types_1.promptNames.capProject]?.defaultChoice;
|
|
45
|
+
const defaultCapService = promptOptions?.[types_1.promptNames.capService]?.defaultChoice;
|
|
56
46
|
let selectedCapProject;
|
|
57
47
|
let capServiceChoices;
|
|
58
48
|
let defaultServiceIndex = 0;
|
|
59
49
|
utils_1.PromptState.reset();
|
|
60
50
|
const prompts = [
|
|
61
51
|
{
|
|
62
|
-
when: () =>
|
|
63
|
-
|
|
64
|
-
capChoices
|
|
65
|
-
|
|
66
|
-
}),
|
|
52
|
+
when: async () => {
|
|
53
|
+
capChoices = await (0, cap_helpers_1.getCapProjectChoices)(promptOptions?.[types_1.promptNames.capProject]?.capSearchPaths ?? []);
|
|
54
|
+
return capChoices?.length > 1;
|
|
55
|
+
},
|
|
67
56
|
type: 'list',
|
|
68
57
|
name: types_1.promptNames.capProject,
|
|
69
58
|
message: (0, i18n_1.t)('prompts.capProject.message'),
|
|
@@ -79,7 +68,7 @@ function getLocalCapProjectPrompts(promptOptions) {
|
|
|
79
68
|
}
|
|
80
69
|
},
|
|
81
70
|
{
|
|
82
|
-
when: (answers) => capChoices.length === 1 ||
|
|
71
|
+
when: (answers) => capChoices.length === 1 || answers?.capProject === cap_helpers_1.enterCapPathChoiceValue,
|
|
83
72
|
type: 'input',
|
|
84
73
|
guiType: 'folder-browser',
|
|
85
74
|
name: types_2.capInternalPromptNames.capProjectPath,
|
|
@@ -90,41 +79,39 @@ function getLocalCapProjectPrompts(promptOptions) {
|
|
|
90
79
|
}
|
|
91
80
|
},
|
|
92
81
|
guiOptions: { mandatory: true, breadcrumb: (0, i18n_1.t)('prompts.capProject.breadcrumb') },
|
|
93
|
-
validate: (projectPath) =>
|
|
94
|
-
const validCapPath =
|
|
82
|
+
validate: async (projectPath) => {
|
|
83
|
+
const validCapPath = await (0, validators_1.validateCapPath)(projectPath);
|
|
95
84
|
// Load the cap paths if the path is valid
|
|
96
85
|
if (validCapPath === true) {
|
|
97
|
-
selectedCapProject = Object.assign({ path: projectPath },
|
|
86
|
+
selectedCapProject = Object.assign({ path: projectPath }, await (0, project_access_1.getCapCustomPaths)(projectPath));
|
|
98
87
|
return true;
|
|
99
88
|
}
|
|
100
89
|
selectedCapProject = undefined;
|
|
101
90
|
return validCapPath;
|
|
102
|
-
}
|
|
91
|
+
}
|
|
103
92
|
},
|
|
104
93
|
{
|
|
105
|
-
when: (answers) =>
|
|
106
|
-
if (typeof
|
|
94
|
+
when: async (answers) => {
|
|
95
|
+
if (typeof answers?.capProject === 'object') {
|
|
107
96
|
selectedCapProject = answers.capProject;
|
|
108
97
|
}
|
|
109
98
|
if (selectedCapProject) {
|
|
110
|
-
capServiceChoices =
|
|
99
|
+
capServiceChoices = await (0, cap_helpers_1.getCapServiceChoices)(selectedCapProject);
|
|
111
100
|
return true;
|
|
112
101
|
}
|
|
113
102
|
return false;
|
|
114
|
-
}
|
|
103
|
+
},
|
|
115
104
|
type: 'list',
|
|
116
105
|
name: types_1.promptNames.capService,
|
|
117
106
|
message: (0, i18n_1.t)('prompts.capService.message'),
|
|
118
107
|
choices: () => {
|
|
119
108
|
if (defaultCapService) {
|
|
120
109
|
// Find the cap service, qualified by the provided project path
|
|
121
|
-
defaultServiceIndex = capServiceChoices
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
((_b = choice.value) === null || _b === void 0 ? void 0 : _b.serviceName) === (defaultCapService === null || defaultCapService === void 0 ? void 0 : defaultCapService.serviceName);
|
|
127
|
-
});
|
|
110
|
+
defaultServiceIndex = capServiceChoices?.findIndex((choice) =>
|
|
111
|
+
// project path is an extra validation that the prompt options for each
|
|
112
|
+
// of `defaultCapProject` and `defaultCapService` are compatible
|
|
113
|
+
choice.value?.projectPath === defaultCapService?.projectPath &&
|
|
114
|
+
choice.value?.serviceName === defaultCapService?.serviceName);
|
|
128
115
|
}
|
|
129
116
|
return capServiceChoices;
|
|
130
117
|
},
|
|
@@ -134,15 +121,15 @@ function getLocalCapProjectPrompts(promptOptions) {
|
|
|
134
121
|
breadcrumb: true
|
|
135
122
|
},
|
|
136
123
|
default: () => {
|
|
137
|
-
return
|
|
124
|
+
return capServiceChoices?.length > 1 ? defaultServiceIndex : 0;
|
|
138
125
|
},
|
|
139
|
-
validate: (capService) =>
|
|
126
|
+
validate: async (capService) => {
|
|
140
127
|
const errMsg = prompt_helpers_1.errorHandler.getErrorMsg(undefined, true);
|
|
141
128
|
if (errMsg) {
|
|
142
129
|
return errMsg;
|
|
143
130
|
}
|
|
144
131
|
if (capService) {
|
|
145
|
-
utils_1.PromptState.odataService.metadata =
|
|
132
|
+
utils_1.PromptState.odataService.metadata = await (0, cap_helpers_1.getCapEdmx)(capService);
|
|
146
133
|
utils_1.PromptState.odataService.servicePath = capService.urlPath;
|
|
147
134
|
utils_1.PromptState.odataService.odataVersion = odata_service_writer_1.OdataVersion.v4;
|
|
148
135
|
return utils_1.PromptState.odataService.metadata !== undefined
|
|
@@ -150,19 +137,19 @@ function getLocalCapProjectPrompts(promptOptions) {
|
|
|
150
137
|
: (0, i18n_1.t)('prompts.validationMessages.metadataInvalid');
|
|
151
138
|
}
|
|
152
139
|
return false;
|
|
153
|
-
}
|
|
140
|
+
}
|
|
154
141
|
}
|
|
155
142
|
];
|
|
156
143
|
if ((0, utils_1.getHostEnvironment)() === types_1.hostEnvironment.cli) {
|
|
157
144
|
prompts.push({
|
|
158
|
-
when: (answers) =>
|
|
159
|
-
if (answers
|
|
160
|
-
utils_1.PromptState.odataService.metadata =
|
|
161
|
-
utils_1.PromptState.odataService.servicePath = answers
|
|
145
|
+
when: async (answers) => {
|
|
146
|
+
if (answers?.capService) {
|
|
147
|
+
utils_1.PromptState.odataService.metadata = await (0, cap_helpers_1.getCapEdmx)(answers?.capService);
|
|
148
|
+
utils_1.PromptState.odataService.servicePath = answers?.capService.urlPath;
|
|
162
149
|
utils_1.PromptState.odataService.odataVersion = odata_service_writer_1.OdataVersion.v4;
|
|
163
150
|
}
|
|
164
151
|
return false;
|
|
165
|
-
}
|
|
152
|
+
},
|
|
166
153
|
name: types_2.capInternalPromptNames.capCliStateSetter
|
|
167
154
|
});
|
|
168
155
|
}
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.validateCapPath = void 0;
|
|
13
4
|
const project_access_1 = require("@sap-ux/project-access");
|
|
@@ -18,18 +9,16 @@ const i18n_1 = require("../../../i18n");
|
|
|
18
9
|
* @param capProjectPath - The path to the CAP project
|
|
19
10
|
* @returns A boolean indicating if the path is a valid CAP project or an error message
|
|
20
11
|
*/
|
|
21
|
-
function validateCapPath(capProjectPath) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return !!(yield (0, project_access_1.getCapProjectType)(capProjectPath)) || (0, i18n_1.t)('prompts.validationMessages.capProjectNotFound');
|
|
26
|
-
}
|
|
27
|
-
catch (err) {
|
|
28
|
-
return (0, i18n_1.t)('prompts.validationMessages.capProjectNotFound');
|
|
29
|
-
}
|
|
12
|
+
async function validateCapPath(capProjectPath) {
|
|
13
|
+
if (capProjectPath) {
|
|
14
|
+
try {
|
|
15
|
+
return !!(await (0, project_access_1.getCapProjectType)(capProjectPath)) || (0, i18n_1.t)('prompts.validationMessages.capProjectNotFound');
|
|
30
16
|
}
|
|
31
|
-
|
|
32
|
-
|
|
17
|
+
catch (err) {
|
|
18
|
+
return (0, i18n_1.t)('prompts.validationMessages.capProjectNotFound');
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return false;
|
|
33
22
|
}
|
|
34
23
|
exports.validateCapPath = validateCapPath;
|
|
35
24
|
//# sourceMappingURL=validators.js.map
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.getMetadataFileQuestion = void 0;
|
|
13
4
|
const i18n_1 = require("../../../i18n");
|
|
@@ -27,9 +18,9 @@ function getMetadataFileQuestion(promptOptions) {
|
|
|
27
18
|
name: types_1.promptNames.metadataFilePath,
|
|
28
19
|
guiOptions: { mandatory: true, breadcrumb: true },
|
|
29
20
|
message: (0, i18n_1.t)('prompts.metadataFile.message'),
|
|
30
|
-
validate: (path) =>
|
|
21
|
+
validate: async (path) => {
|
|
31
22
|
utils_1.PromptState.reset();
|
|
32
|
-
const validateResult =
|
|
23
|
+
const validateResult = await (0, validators_1.validateMetadataFile)(path, promptOptions?.requiredOdataVersion);
|
|
33
24
|
if (typeof validateResult === 'string' || typeof validateResult === 'boolean') {
|
|
34
25
|
return validateResult;
|
|
35
26
|
}
|
|
@@ -39,7 +30,7 @@ function getMetadataFileQuestion(promptOptions) {
|
|
|
39
30
|
utils_1.PromptState.odataService.servicePath = (0, i18n_1.t)('prompts.metadataFile.placeholder_odata_service_url'); // Dummy path used by v4 preview server middleware
|
|
40
31
|
}
|
|
41
32
|
return true;
|
|
42
|
-
}
|
|
33
|
+
}
|
|
43
34
|
};
|
|
44
35
|
return metadataFileQuestion;
|
|
45
36
|
}
|
|
@@ -6,40 +6,31 @@
|
|
|
6
6
|
* @param odataVersion
|
|
7
7
|
* @returns
|
|
8
8
|
*/
|
|
9
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
10
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
11
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
12
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
13
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
14
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
15
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
16
|
-
});
|
|
17
|
-
};
|
|
18
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
10
|
exports.validateMetadataFile = void 0;
|
|
20
11
|
const odata_service_writer_1 = require("@sap-ux/odata-service-writer");
|
|
21
12
|
const promises_1 = require("fs/promises");
|
|
22
13
|
const validators_1 = require("../../validators");
|
|
23
14
|
const i18n_1 = require("../../../i18n");
|
|
24
|
-
const validateMetadataFile = (path, odataVersion) =>
|
|
15
|
+
const validateMetadataFile = async (path, odataVersion) => {
|
|
25
16
|
if (!path) {
|
|
26
17
|
return false;
|
|
27
18
|
}
|
|
28
19
|
try {
|
|
29
|
-
const metadata =
|
|
20
|
+
const metadata = await (0, promises_1.readFile)(path, 'utf-8');
|
|
30
21
|
metadata.replace(/ & /g, ' & ');
|
|
31
22
|
const { validationMsg, version } = (0, validators_1.validateODataVersion)(metadata, odataVersion);
|
|
32
23
|
if (validationMsg) {
|
|
33
24
|
return validationMsg;
|
|
34
25
|
}
|
|
35
26
|
return {
|
|
36
|
-
version: version
|
|
27
|
+
version: version ?? odata_service_writer_1.OdataVersion.v4,
|
|
37
28
|
metadata
|
|
38
29
|
};
|
|
39
30
|
}
|
|
40
31
|
catch (error) {
|
|
41
32
|
return (0, i18n_1.t)('prompts.validationMessages.metadataFilePathNotValid');
|
|
42
33
|
}
|
|
43
|
-
}
|
|
34
|
+
};
|
|
44
35
|
exports.validateMetadataFile = validateMetadataFile;
|
|
45
36
|
//# sourceMappingURL=validators.js.map
|