@sap-ux/project-access 1.8.3 → 1.9.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/file/file-search.d.ts +1 -1
- package/dist/file/file-search.js +1 -1
- package/dist/project/cap.d.ts +18 -0
- package/dist/project/cap.js +101 -1
- package/dist/project/search.d.ts +1 -0
- package/dist/project/search.js +1 -1
- package/package.json +3 -3
|
@@ -48,7 +48,7 @@ export declare function findFilesByExtension(extension: string, root: string, ex
|
|
|
48
48
|
export declare function findFileUp(fileName: string, startPath: string, fs?: Editor): Promise<string | undefined>;
|
|
49
49
|
/**
|
|
50
50
|
* @description Returns a flat list of all file paths under a directory tree,
|
|
51
|
-
* recursing through all subdirectories
|
|
51
|
+
* recursing through all subdirectories.
|
|
52
52
|
* @param {string} dir - the directory to walk
|
|
53
53
|
* @returns {string[]} - array of file path strings
|
|
54
54
|
* @throws if an error occurs reading a file path
|
package/dist/file/file-search.js
CHANGED
|
@@ -134,7 +134,7 @@ function findFileUp(fileName, startPath, fs) {
|
|
|
134
134
|
exports.findFileUp = findFileUp;
|
|
135
135
|
/**
|
|
136
136
|
* @description Returns a flat list of all file paths under a directory tree,
|
|
137
|
-
* recursing through all subdirectories
|
|
137
|
+
* recursing through all subdirectories.
|
|
138
138
|
* @param {string} dir - the directory to walk
|
|
139
139
|
* @returns {string[]} - array of file path strings
|
|
140
140
|
* @throws if an error occurs reading a file path
|
package/dist/project/cap.d.ts
CHANGED
|
@@ -35,6 +35,7 @@ export declare function getCapCustomPaths(capProjectPath: string): Promise<CapCu
|
|
|
35
35
|
* Return the CAP model and all services.
|
|
36
36
|
*
|
|
37
37
|
* @param projectRoot - CAP project root where package.json resides
|
|
38
|
+
* @returns {*} {Promise<{ model: csn; services: ServiceInfo[] }>} - CAP Model and Services
|
|
38
39
|
*/
|
|
39
40
|
export declare function getCapModelAndServices(projectRoot: string): Promise<{
|
|
40
41
|
model: csn;
|
|
@@ -47,5 +48,22 @@ export declare function getCapModelAndServices(projectRoot: string): Promise<{
|
|
|
47
48
|
* @returns - environment config for CAP project
|
|
48
49
|
*/
|
|
49
50
|
export declare function getCapEnvironment(capProjectPath: string): Promise<CdsEnvironment>;
|
|
51
|
+
/**
|
|
52
|
+
* Get absolute path to a resource.
|
|
53
|
+
*
|
|
54
|
+
* @param projectRoot - project root of a CAP project
|
|
55
|
+
* @param relativeUri - relative resource path.
|
|
56
|
+
* @returns {string} - absolute path.
|
|
57
|
+
*/
|
|
58
|
+
export declare const toAbsoluteUri: (projectRoot: string, relativeUri: string) => string;
|
|
59
|
+
/**
|
|
60
|
+
* Converts to referenced uri to be used in using statements.
|
|
61
|
+
*
|
|
62
|
+
* @param projectRoot - project root of a CAP project
|
|
63
|
+
* @param relativeUriFrom - relative uri of from directory
|
|
64
|
+
* @param relativeUriTo - relative uri of to directory
|
|
65
|
+
* @returns {Promise<string>} - reference uri
|
|
66
|
+
*/
|
|
67
|
+
export declare const toReferenceUri: (projectRoot: string, relativeUriFrom: string, relativeUriTo: string) => Promise<string>;
|
|
50
68
|
export {};
|
|
51
69
|
//# sourceMappingURL=cap.d.ts.map
|
package/dist/project/cap.js
CHANGED
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.getCapEnvironment = exports.getCapModelAndServices = exports.getCapCustomPaths = exports.getCapProjectType = exports.isCapJavaProject = exports.isCapNodeJsProject = void 0;
|
|
12
|
+
exports.toReferenceUri = exports.toAbsoluteUri = exports.getCapEnvironment = exports.getCapModelAndServices = exports.getCapCustomPaths = exports.getCapProjectType = exports.isCapJavaProject = exports.isCapNodeJsProject = void 0;
|
|
13
13
|
const path_1 = require("path");
|
|
14
14
|
const constants_1 = require("../constants");
|
|
15
15
|
const file_1 = require("../file");
|
|
@@ -95,6 +95,7 @@ exports.getCapCustomPaths = getCapCustomPaths;
|
|
|
95
95
|
* Return the CAP model and all services.
|
|
96
96
|
*
|
|
97
97
|
* @param projectRoot - CAP project root where package.json resides
|
|
98
|
+
* @returns {*} {Promise<{ model: csn; services: ServiceInfo[] }>} - CAP Model and Services
|
|
98
99
|
*/
|
|
99
100
|
function getCapModelAndServices(projectRoot) {
|
|
100
101
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -128,4 +129,103 @@ function getCapEnvironment(capProjectPath) {
|
|
|
128
129
|
});
|
|
129
130
|
}
|
|
130
131
|
exports.getCapEnvironment = getCapEnvironment;
|
|
132
|
+
/**
|
|
133
|
+
* Get absolute path to a resource.
|
|
134
|
+
*
|
|
135
|
+
* @param projectRoot - project root of a CAP project
|
|
136
|
+
* @param relativeUri - relative resource path.
|
|
137
|
+
* @returns {string} - absolute path.
|
|
138
|
+
*/
|
|
139
|
+
const toAbsoluteUri = (projectRoot, relativeUri) => (0, path_1.join)(projectRoot, relativeUri);
|
|
140
|
+
exports.toAbsoluteUri = toAbsoluteUri;
|
|
141
|
+
/**
|
|
142
|
+
* Converts to referenced uri to be used in using statements.
|
|
143
|
+
*
|
|
144
|
+
* @param projectRoot - project root of a CAP project
|
|
145
|
+
* @param relativeUriFrom - relative uri of from directory
|
|
146
|
+
* @param relativeUriTo - relative uri of to directory
|
|
147
|
+
* @returns {Promise<string>} - reference uri
|
|
148
|
+
*/
|
|
149
|
+
const toReferenceUri = (projectRoot, relativeUriFrom, relativeUriTo) => __awaiter(void 0, void 0, void 0, function* () {
|
|
150
|
+
let relativeUri = '';
|
|
151
|
+
const indexNodeModules = relativeUriTo.lastIndexOf('node_modules');
|
|
152
|
+
if (indexNodeModules >= 0) {
|
|
153
|
+
// extract module name from fileUri - e.g. '@sap/cds/common' from '../../node_modules/@sap/cds/common.cds'
|
|
154
|
+
const indexLastDot = relativeUriTo.lastIndexOf('.');
|
|
155
|
+
if (indexLastDot > indexNodeModules + 13) {
|
|
156
|
+
relativeUri = relativeUriTo.slice(indexNodeModules + 13, indexLastDot);
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
relativeUri = relativeUriTo.slice(indexNodeModules + 13);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
else if (relativeUriTo.startsWith('../') || relativeUriTo.startsWith('..\\')) {
|
|
163
|
+
// file outside current project (e.g. mono repo)
|
|
164
|
+
const result = yield getPackageNameInFolder(projectRoot, relativeUriTo);
|
|
165
|
+
if (result.packageName) {
|
|
166
|
+
relativeUri = result.packageName + relativeUriTo.slice(result.packageFolder.length);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
if (!relativeUri) {
|
|
170
|
+
// build relative path
|
|
171
|
+
const fromDir = (0, path_1.dirname)((0, exports.toAbsoluteUri)(projectRoot, relativeUriFrom));
|
|
172
|
+
relativeUri = (0, path_1.relative)(fromDir, (0, exports.toAbsoluteUri)(projectRoot, relativeUriTo));
|
|
173
|
+
if (!relativeUri.startsWith('.')) {
|
|
174
|
+
relativeUri = './' + relativeUri;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
// remove file extension
|
|
178
|
+
const fileExtension = relativeUri.lastIndexOf('.') > 0 ? relativeUri.slice(relativeUri.lastIndexOf('.') + 1) : '';
|
|
179
|
+
if (['CDS', 'JSON'].includes(fileExtension.toUpperCase())) {
|
|
180
|
+
relativeUri = relativeUri.slice(0, relativeUri.length - fileExtension.length - 1);
|
|
181
|
+
}
|
|
182
|
+
// always use '/' instead of platform specific separator
|
|
183
|
+
return relativeUri.split(path_1.sep).join('/');
|
|
184
|
+
});
|
|
185
|
+
exports.toReferenceUri = toReferenceUri;
|
|
186
|
+
/**
|
|
187
|
+
* Gets package name from the folder.
|
|
188
|
+
*
|
|
189
|
+
* @param baseUri - base uri of the cap project
|
|
190
|
+
* @param relativeUri - relative uri to the resource folder
|
|
191
|
+
* @returns {Promise<{ packageName: string; packageFolder: string }>} - package name and folder
|
|
192
|
+
*/
|
|
193
|
+
function getPackageNameInFolder(baseUri, relativeUri) {
|
|
194
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
195
|
+
const refUriParts = relativeUri.split(path_1.sep);
|
|
196
|
+
const result = { packageName: '', packageFolder: relativeUri };
|
|
197
|
+
for (let i = refUriParts.length - 1; i >= 0 && !result.packageName; i--) {
|
|
198
|
+
const currentFolder = refUriParts.slice(0, i).join(path_1.sep);
|
|
199
|
+
result.packageName = yield readPackageNameForFolder(baseUri, currentFolder);
|
|
200
|
+
if (result.packageName) {
|
|
201
|
+
result.packageFolder = currentFolder;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return result;
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Reads package name from package json of the folder.
|
|
209
|
+
*
|
|
210
|
+
* @param baseUri - base uri of the cap project
|
|
211
|
+
* @param relativeUri - relative uri to the resource folder
|
|
212
|
+
* @returns {Promise<string>} - package name
|
|
213
|
+
*/
|
|
214
|
+
function readPackageNameForFolder(baseUri, relativeUri) {
|
|
215
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
216
|
+
let packageName = '';
|
|
217
|
+
try {
|
|
218
|
+
const path = (0, path_1.normalize)(baseUri + '/' + relativeUri + '/' + 'package.json');
|
|
219
|
+
const content = yield (0, file_1.readFile)(path);
|
|
220
|
+
if (content) {
|
|
221
|
+
const parsed = JSON.parse(content);
|
|
222
|
+
packageName = parsed.name;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
catch (e) {
|
|
226
|
+
packageName = '';
|
|
227
|
+
}
|
|
228
|
+
return packageName;
|
|
229
|
+
});
|
|
230
|
+
}
|
|
131
231
|
//# sourceMappingURL=cap.js.map
|
package/dist/project/search.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import type { AllAppResults, FioriArtifactTypes, FoundFioriArtifacts, WorkspaceF
|
|
|
5
5
|
* @param path path of a project file
|
|
6
6
|
* @param sapuxRequired if true, only find sapux projects
|
|
7
7
|
* @param silent if true, then does not throw an error but returns an empty path
|
|
8
|
+
* @returns {*} {Promise<string>} - Project Root
|
|
8
9
|
*/
|
|
9
10
|
export declare function findProjectRoot(path: string, sapuxRequired?: boolean, silent?: boolean): Promise<string>;
|
|
10
11
|
/**
|
package/dist/project/search.js
CHANGED
|
@@ -69,6 +69,7 @@ function wsFoldersToRootPaths(wsFolders) {
|
|
|
69
69
|
* @param path path of a project file
|
|
70
70
|
* @param sapuxRequired if true, only find sapux projects
|
|
71
71
|
* @param silent if true, then does not throw an error but returns an empty path
|
|
72
|
+
* @returns {*} {Promise<string>} - Project Root
|
|
72
73
|
*/
|
|
73
74
|
function findProjectRoot(path, sapuxRequired = true, silent = false) {
|
|
74
75
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -93,7 +94,6 @@ exports.findProjectRoot = findProjectRoot;
|
|
|
93
94
|
/**
|
|
94
95
|
* Find app root and project root from given paths and sapux entry.
|
|
95
96
|
*
|
|
96
|
-
*
|
|
97
97
|
* @param sapux - value of sapux in package.json, either boolean or string array
|
|
98
98
|
* @param path - path where the search started from
|
|
99
99
|
* @param root - root of the app or project, where package.json is located
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sap-ux/project-access",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.0",
|
|
4
4
|
"description": "Library to access SAP Fiori tools projects",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"findit2": "2.2.3",
|
|
28
28
|
"mem-fs": "2.1.0",
|
|
29
29
|
"mem-fs-editor": "9.4.0",
|
|
30
|
-
"@sap-ux/ui5-config": "0.18.
|
|
30
|
+
"@sap-ux/ui5-config": "0.18.2"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/mem-fs": "1.1.2",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
},
|
|
38
38
|
"scripts": {
|
|
39
39
|
"build": "tsc --build",
|
|
40
|
-
"clean": "rimraf dist coverage *.tsbuildinfo",
|
|
40
|
+
"clean": "rimraf --glob dist coverage *.tsbuildinfo",
|
|
41
41
|
"format": "prettier --write '**/*.{js,json,ts,yaml,yml}' --ignore-path ../../.prettierignore",
|
|
42
42
|
"lint": "eslint . --ext .ts",
|
|
43
43
|
"lint:fix": "eslint . --ext .ts --fix",
|