@sap-ux/project-access 1.11.2 → 1.12.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/project/cap.js +77 -2
- package/package.json +1 -1
package/dist/project/cap.js
CHANGED
|
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.toReferenceUri = exports.toAbsoluteUri = exports.getCapEnvironment = exports.readCapServiceMetadataEdmx = exports.getCapModelAndServices = exports.getCapCustomPaths = exports.getCapProjectType = exports.isCapJavaProject = exports.isCapNodeJsProject = void 0;
|
|
13
|
+
const child_process_1 = require("child_process");
|
|
13
14
|
const path_1 = require("path");
|
|
14
15
|
const constants_1 = require("../constants");
|
|
15
16
|
const file_1 = require("../file");
|
|
@@ -183,14 +184,37 @@ function getCapEnvironment(capProjectPath) {
|
|
|
183
184
|
}
|
|
184
185
|
exports.getCapEnvironment = getCapEnvironment;
|
|
185
186
|
/**
|
|
186
|
-
* Load CAP CDS module for a project based on its root.
|
|
187
|
+
* Load CAP CDS module. First attempt loads @sap/cds for a project based on its root.
|
|
188
|
+
* Second attempt loads @sap/cds from global installed @sap/cds-dk.
|
|
189
|
+
* Throws error if module could not be loaded.
|
|
187
190
|
*
|
|
188
191
|
* @param capProjectPath - project root of a CAP project
|
|
189
192
|
* @returns - CAP CDS module for a CAP project
|
|
190
193
|
*/
|
|
191
194
|
function loadCdsModuleFromProject(capProjectPath) {
|
|
192
195
|
return __awaiter(this, void 0, void 0, function* () {
|
|
193
|
-
|
|
196
|
+
let module;
|
|
197
|
+
let loadProjectError;
|
|
198
|
+
let loadError;
|
|
199
|
+
try {
|
|
200
|
+
// First approach, load @sap/cds from project
|
|
201
|
+
module = yield (0, module_loader_1.loadModuleFromProject)(capProjectPath, '@sap/cds');
|
|
202
|
+
}
|
|
203
|
+
catch (error) {
|
|
204
|
+
loadProjectError = error;
|
|
205
|
+
}
|
|
206
|
+
if (!module) {
|
|
207
|
+
try {
|
|
208
|
+
// Second approach, load @sap/cds from @sap/cds-dk
|
|
209
|
+
module = yield loadGlobalCdsModule();
|
|
210
|
+
}
|
|
211
|
+
catch (error) {
|
|
212
|
+
loadError = error;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
if (!module) {
|
|
216
|
+
throw Error(`Could not load cds module. Attempt to load module @sap/cds from project threw error '${loadProjectError}', attempt to load module @sap/cds from @sap/cds-dk threw error '${loadError}'`);
|
|
217
|
+
}
|
|
194
218
|
return 'default' in module ? module.default : module;
|
|
195
219
|
});
|
|
196
220
|
}
|
|
@@ -293,4 +317,55 @@ function readPackageNameForFolder(baseUri, relativeUri) {
|
|
|
293
317
|
return packageName;
|
|
294
318
|
});
|
|
295
319
|
}
|
|
320
|
+
let globalCdsPathCache;
|
|
321
|
+
/**
|
|
322
|
+
* Try to load global installation of @sap/cds, usually child of @sap/cds-dk.
|
|
323
|
+
*
|
|
324
|
+
* @returns - module @sap/cds from global installed @sap/cds-dk
|
|
325
|
+
*/
|
|
326
|
+
function loadGlobalCdsModule() {
|
|
327
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
328
|
+
if (!globalCdsPathCache) {
|
|
329
|
+
const versions = yield getCdsVersionInfo();
|
|
330
|
+
if (!versions.home) {
|
|
331
|
+
throw Error('Can not find global installation of module @sap/cds, which should be part of @sap/cds-dk');
|
|
332
|
+
}
|
|
333
|
+
globalCdsPathCache = versions.home;
|
|
334
|
+
}
|
|
335
|
+
return (0, module_loader_1.loadModuleFromProject)(globalCdsPathCache, '@sap/cds');
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Get cds information, which includes versions and also the home path of cds module.
|
|
340
|
+
*
|
|
341
|
+
* @param [cwd] - optional folder in which cds --version should be executed
|
|
342
|
+
* @returns - result of call 'cds --version'
|
|
343
|
+
*/
|
|
344
|
+
function getCdsVersionInfo(cwd) {
|
|
345
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
346
|
+
return new Promise((resolve, reject) => {
|
|
347
|
+
let out = '';
|
|
348
|
+
const cdsVersionInfo = (0, child_process_1.spawn)('cds', ['--version'], { cwd, shell: true });
|
|
349
|
+
cdsVersionInfo.stdout.on('data', (data) => {
|
|
350
|
+
out += data.toString();
|
|
351
|
+
});
|
|
352
|
+
cdsVersionInfo.on('close', () => {
|
|
353
|
+
if (out) {
|
|
354
|
+
const versions = {};
|
|
355
|
+
for (const line of out.split('\n').filter((v) => v)) {
|
|
356
|
+
const [key, value] = line.split(': ');
|
|
357
|
+
versions[key] = value;
|
|
358
|
+
}
|
|
359
|
+
resolve(versions);
|
|
360
|
+
}
|
|
361
|
+
else {
|
|
362
|
+
reject(new Error('Module path not found'));
|
|
363
|
+
}
|
|
364
|
+
});
|
|
365
|
+
cdsVersionInfo.on('error', (error) => {
|
|
366
|
+
reject(error);
|
|
367
|
+
});
|
|
368
|
+
});
|
|
369
|
+
});
|
|
370
|
+
}
|
|
296
371
|
//# sourceMappingURL=cap.js.map
|