@sap-ux/project-access 1.17.4 → 1.17.6
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/constants.d.ts +1 -0
- package/dist/constants.js +1 -0
- package/dist/project/access.js +1 -1
- package/dist/project/i18n/read.d.ts +1 -1
- package/dist/project/i18n/read.js +36 -6
- package/dist/project/search.js +30 -5
- package/dist/types/access/index.d.ts +76 -0
- package/dist/types/cap/index.d.ts +6 -0
- package/dist/types/find/index.d.ts +6 -2
- package/dist/types/i18n/index.d.ts +4 -0
- package/package.json +1 -1
package/dist/constants.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export declare const FileName: {
|
|
|
2
2
|
readonly AdaptationConfig: "config.json";
|
|
3
3
|
readonly CapJavaApplicationYaml: "application.yaml";
|
|
4
4
|
readonly ExtConfigJson: ".extconfig.json";
|
|
5
|
+
readonly Library: ".library";
|
|
5
6
|
readonly Manifest: "manifest.json";
|
|
6
7
|
readonly ManifestAppDescrVar: "manifest.appdescr_variant";
|
|
7
8
|
readonly MtaYaml: "mta.yaml";
|
package/dist/constants.js
CHANGED
package/dist/project/access.js
CHANGED
|
@@ -125,7 +125,7 @@ class ApplicationAccessImp {
|
|
|
125
125
|
/**
|
|
126
126
|
* For a given app in project, retrieves i18n bundles for 'sap.app' namespace,`models` of `sap.ui5` namespace and service for cap services.
|
|
127
127
|
*
|
|
128
|
-
* @returns i18n bundles or exception
|
|
128
|
+
* @returns i18n bundles or exception captured in optional errors object
|
|
129
129
|
*/
|
|
130
130
|
getI18nBundles() {
|
|
131
131
|
return (0, i18n_1.getI18nBundles)(this.project.root, this.app.i18n, this.project.projectType, this.fs);
|
|
@@ -9,7 +9,7 @@ import type { Editor } from 'mem-fs-editor';
|
|
|
9
9
|
* @param fs optional `mem-fs-editor` instance. If provided, `mem-fs-editor` api is used instead of `fs` of node.
|
|
10
10
|
* In case of CAP project, some CDS APIs are used internally which depends on `fs` of node and not `mem-fs-editor`.
|
|
11
11
|
* When calling this function, adding or removing a CDS file in memory or changing CDS configuration will not be considered until present on real file system.
|
|
12
|
-
* @returns i18n bundles or exception
|
|
12
|
+
* @returns i18n bundles or exception captured in optional errors object
|
|
13
13
|
*/
|
|
14
14
|
export declare function getI18nBundles(root: string, i18nPropertiesPaths: I18nPropertiesPaths, projectType?: ProjectType, fs?: Editor): Promise<I18nBundles>;
|
|
15
15
|
/**
|
|
@@ -12,6 +12,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.getCapI18nFolderNames = exports.getI18nBundles = void 0;
|
|
13
13
|
const i18n_1 = require("@sap-ux/i18n");
|
|
14
14
|
const __1 = require("..");
|
|
15
|
+
/**
|
|
16
|
+
* Add error to optional errors object.
|
|
17
|
+
*
|
|
18
|
+
* @param result i18n bundles
|
|
19
|
+
* @param key key to associate with the error
|
|
20
|
+
* @param error error to add
|
|
21
|
+
*/
|
|
22
|
+
function addToErrors(result, key, error) {
|
|
23
|
+
if (!result.errors) {
|
|
24
|
+
result.errors = {};
|
|
25
|
+
}
|
|
26
|
+
result.errors[key] = error;
|
|
27
|
+
}
|
|
15
28
|
/**
|
|
16
29
|
* For a given app in project, retrieves i18n bundles for 'sap.app' namespace,`models` of `sap.ui5` namespace and service for cap services.
|
|
17
30
|
*
|
|
@@ -21,7 +34,7 @@ const __1 = require("..");
|
|
|
21
34
|
* @param fs optional `mem-fs-editor` instance. If provided, `mem-fs-editor` api is used instead of `fs` of node.
|
|
22
35
|
* In case of CAP project, some CDS APIs are used internally which depends on `fs` of node and not `mem-fs-editor`.
|
|
23
36
|
* When calling this function, adding or removing a CDS file in memory or changing CDS configuration will not be considered until present on real file system.
|
|
24
|
-
* @returns i18n bundles or exception
|
|
37
|
+
* @returns i18n bundles or exception captured in optional errors object
|
|
25
38
|
*/
|
|
26
39
|
function getI18nBundles(root, i18nPropertiesPaths, projectType, fs) {
|
|
27
40
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -30,14 +43,31 @@ function getI18nBundles(root, i18nPropertiesPaths, projectType, fs) {
|
|
|
30
43
|
models: {},
|
|
31
44
|
service: {}
|
|
32
45
|
};
|
|
33
|
-
|
|
46
|
+
try {
|
|
47
|
+
result['sap.app'] = yield (0, i18n_1.getPropertiesI18nBundle)(i18nPropertiesPaths['sap.app'], fs);
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
addToErrors(result, 'sap.app', error);
|
|
51
|
+
}
|
|
34
52
|
for (const key of Object.keys(i18nPropertiesPaths.models)) {
|
|
35
|
-
|
|
53
|
+
try {
|
|
54
|
+
result.models[key] = yield (0, i18n_1.getPropertiesI18nBundle)(i18nPropertiesPaths.models[key].path, fs);
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
// add models key with empty model
|
|
58
|
+
result.models[key] = {};
|
|
59
|
+
addToErrors(result, `models.${key}`, error);
|
|
60
|
+
}
|
|
36
61
|
}
|
|
37
62
|
if (projectType === 'CAPNodejs') {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
63
|
+
try {
|
|
64
|
+
const env = yield (0, __1.getCapEnvironment)(root);
|
|
65
|
+
const cdsFiles = yield (0, __1.getCdsFiles)(root, true);
|
|
66
|
+
result.service = yield (0, i18n_1.getCapI18nBundle)(root, env, cdsFiles, fs);
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
addToErrors(result, 'service', error);
|
|
70
|
+
}
|
|
41
71
|
}
|
|
42
72
|
return result;
|
|
43
73
|
});
|
package/dist/project/search.js
CHANGED
|
@@ -23,10 +23,10 @@ const ui5_config_1 = require("./ui5-config");
|
|
|
23
23
|
* functions.
|
|
24
24
|
*/
|
|
25
25
|
const filterFileMap = {
|
|
26
|
-
applications: constants_1.FileName.Manifest,
|
|
27
|
-
adaptations: constants_1.FileName.ManifestAppDescrVar,
|
|
28
|
-
extensions: constants_1.FileName.ExtConfigJson,
|
|
29
|
-
libraries: constants_1.FileName.Manifest
|
|
26
|
+
applications: [constants_1.FileName.Manifest],
|
|
27
|
+
adaptations: [constants_1.FileName.ManifestAppDescrVar],
|
|
28
|
+
extensions: [constants_1.FileName.ExtConfigJson],
|
|
29
|
+
libraries: [constants_1.FileName.Library, constants_1.FileName.Manifest]
|
|
30
30
|
};
|
|
31
31
|
/**
|
|
32
32
|
* Default folders to exclude from search.
|
|
@@ -337,6 +337,30 @@ function filterExtensions(pathMap) {
|
|
|
337
337
|
return results;
|
|
338
338
|
});
|
|
339
339
|
}
|
|
340
|
+
/**
|
|
341
|
+
* Find and filter libraries with only a `.library` and no `manifest.json`.
|
|
342
|
+
*
|
|
343
|
+
* @param pathMap - path to files
|
|
344
|
+
* @param manifestPaths - paths to manifest.json files
|
|
345
|
+
* @returns - results as array of found .library projects.
|
|
346
|
+
*/
|
|
347
|
+
function filterDotLibraries(pathMap, manifestPaths) {
|
|
348
|
+
var _a;
|
|
349
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
350
|
+
const dotLibraries = [];
|
|
351
|
+
const dotLibraryPaths = Object.keys(pathMap)
|
|
352
|
+
.filter((path) => (0, path_1.basename)(path) === constants_1.FileName.Library)
|
|
353
|
+
.map((path) => (0, path_1.dirname)(path))
|
|
354
|
+
.filter((path) => !manifestPaths.map((manifestPath) => (0, path_1.dirname)(manifestPath)).includes(path));
|
|
355
|
+
if (dotLibraryPaths) {
|
|
356
|
+
for (const libraryPath of dotLibraryPaths) {
|
|
357
|
+
const projectRoot = (0, path_1.dirname)((_a = (yield (0, file_1.findFileUp)(constants_1.FileName.Package, (0, path_1.dirname)(libraryPath)))) !== null && _a !== void 0 ? _a : libraryPath);
|
|
358
|
+
dotLibraries.push({ projectRoot, libraryPath });
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
return dotLibraries;
|
|
362
|
+
});
|
|
363
|
+
}
|
|
340
364
|
/**
|
|
341
365
|
* Filter extensions projects from a list of files.
|
|
342
366
|
*
|
|
@@ -348,6 +372,7 @@ function filterLibraries(pathMap) {
|
|
|
348
372
|
return __awaiter(this, void 0, void 0, function* () {
|
|
349
373
|
const results = [];
|
|
350
374
|
const manifestPaths = Object.keys(pathMap).filter((path) => (0, path_1.basename)(path) === constants_1.FileName.Manifest);
|
|
375
|
+
results.push(...(yield filterDotLibraries(pathMap, manifestPaths)));
|
|
351
376
|
for (const manifestPath of manifestPaths) {
|
|
352
377
|
try {
|
|
353
378
|
(_a = pathMap[manifestPath]) !== null && _a !== void 0 ? _a : (pathMap[manifestPath] = yield (0, file_1.readJSON)(manifestPath));
|
|
@@ -377,7 +402,7 @@ function getFilterFileNames(artifacts) {
|
|
|
377
402
|
const uniqueFilterFiles = new Set();
|
|
378
403
|
for (const artifact of artifacts) {
|
|
379
404
|
if (filterFileMap[artifact]) {
|
|
380
|
-
|
|
405
|
+
filterFileMap[artifact].forEach((artifactFile) => uniqueFilterFiles.add(artifactFile));
|
|
381
406
|
}
|
|
382
407
|
}
|
|
383
408
|
return Array.from(uniqueFilterFiles);
|
|
@@ -8,13 +8,89 @@ interface BaseAccess {
|
|
|
8
8
|
}
|
|
9
9
|
export interface ApplicationAccess extends BaseAccess {
|
|
10
10
|
readonly app: ApplicationStructure;
|
|
11
|
+
/**
|
|
12
|
+
* Maintains new translation entries in an existing i18n file or in a new i18n properties file if it does not exist.
|
|
13
|
+
*
|
|
14
|
+
* @param newEntries - translation entries to write in the `.properties` file
|
|
15
|
+
* @returns - boolean or exception
|
|
16
|
+
* @description It also update `manifest.json` file if `@i18n` entry is missing from `"sap.ui5":{"models": {}}`
|
|
17
|
+
* as
|
|
18
|
+
* ```JSON
|
|
19
|
+
* {
|
|
20
|
+
* "sap.ui5": {
|
|
21
|
+
* "models": {
|
|
22
|
+
* "@i18n": {
|
|
23
|
+
* "type": "sap.ui.model.resource.ResourceModel",
|
|
24
|
+
* "uri": "i18n/i18n.properties"
|
|
25
|
+
* }
|
|
26
|
+
* }
|
|
27
|
+
* }
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
11
31
|
createAnnotationI18nEntries(newEntries: NewI18nEntry[]): Promise<boolean>;
|
|
32
|
+
/**
|
|
33
|
+
* Maintains new translation entries in an existing i18n file or in a new i18n properties file if it does not exist.
|
|
34
|
+
*
|
|
35
|
+
* @param newEntries - translation entries to write in the `.properties` file
|
|
36
|
+
* @param modelKey - i18n model key. Default key is `i18n`
|
|
37
|
+
* @returns boolean or exception
|
|
38
|
+
* @description It also update `manifest.json` file if `<modelKey>` entry is missing from `"sap.ui5":{"models": {}}`
|
|
39
|
+
* as
|
|
40
|
+
* ```JSON
|
|
41
|
+
* {
|
|
42
|
+
* "sap.ui5": {
|
|
43
|
+
* "models": {
|
|
44
|
+
* "<modelKey>": {
|
|
45
|
+
* "type": "sap.ui.model.resource.ResourceModel",
|
|
46
|
+
* "uri": "i18n/i18n.properties"
|
|
47
|
+
* }
|
|
48
|
+
* }
|
|
49
|
+
* }
|
|
50
|
+
* }
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
12
53
|
createUI5I18nEntries(newEntries: NewI18nEntry[], modelKey?: string): Promise<boolean>;
|
|
54
|
+
/**
|
|
55
|
+
* Maintains new translation entries in an existing i18n file or in a new i18n properties file if it does not exist.
|
|
56
|
+
*
|
|
57
|
+
* @param newEntries translation entries to write in the `.properties` file
|
|
58
|
+
* @returns boolean or exception
|
|
59
|
+
* @description If `i18n` entry is missing from `"sap.app":{}`, default `i18n/i18n.properties` is used. Update of `manifest.json` file is not needed.
|
|
60
|
+
*/
|
|
13
61
|
createManifestI18nEntries(newEntries: NewI18nEntry[]): Promise<boolean>;
|
|
62
|
+
/**
|
|
63
|
+
* Maintains new translation entries in CAP i18n files.
|
|
64
|
+
*
|
|
65
|
+
* @param filePath file in which the translation entry will be used.
|
|
66
|
+
* @param newI18nEntries translation entries to write in the i18n file.
|
|
67
|
+
* @returns boolean or exception
|
|
68
|
+
*/
|
|
14
69
|
createCapI18nEntries(filePath: string, newI18nEntries: NewI18nEntry[]): Promise<boolean>;
|
|
70
|
+
/**
|
|
71
|
+
* Return the application id of this app, which is the relative path from the project root
|
|
72
|
+
* to the app root.
|
|
73
|
+
*
|
|
74
|
+
* @returns - Application root path
|
|
75
|
+
*/
|
|
15
76
|
getAppId(): string;
|
|
77
|
+
/**
|
|
78
|
+
* Return the absolute application root path.
|
|
79
|
+
*
|
|
80
|
+
* @returns - Application root path
|
|
81
|
+
*/
|
|
16
82
|
getAppRoot(): string;
|
|
83
|
+
/**
|
|
84
|
+
* For a given app in project, retrieves i18n bundles for 'sap.app' namespace,`models` of `sap.ui5` namespace and service for cap services.
|
|
85
|
+
*
|
|
86
|
+
* @returns i18n bundles or exception
|
|
87
|
+
*/
|
|
17
88
|
getI18nBundles(): Promise<I18nBundles>;
|
|
89
|
+
/**
|
|
90
|
+
* Return absolute paths to i18n.properties files from manifest.
|
|
91
|
+
*
|
|
92
|
+
* @returns absolute paths to i18n.properties
|
|
93
|
+
*/
|
|
18
94
|
getI18nPropertiesPaths(): Promise<I18nPropertiesPaths>;
|
|
19
95
|
}
|
|
20
96
|
export interface ProjectAccess extends BaseAccess {
|
|
@@ -129,6 +129,12 @@ interface Entity extends Struct {
|
|
|
129
129
|
};
|
|
130
130
|
}
|
|
131
131
|
interface LinkedDefinition {
|
|
132
|
+
/**
|
|
133
|
+
* Checks if the definition is of the specified kind or has the 'Association' or 'Composition' kind.
|
|
134
|
+
*
|
|
135
|
+
* @param {kind | 'Association' | 'Composition'} kind - The kind to check for.
|
|
136
|
+
* @returns {boolean} - True if the definition is of the specified kind or has the 'Association' or 'Composition' kind, false otherwise.
|
|
137
|
+
*/
|
|
132
138
|
is(kind: kind | 'Association' | 'Composition'): boolean;
|
|
133
139
|
name: string;
|
|
134
140
|
}
|
|
@@ -70,12 +70,16 @@ export interface LibraryResults {
|
|
|
70
70
|
/**
|
|
71
71
|
* Path to the manifest.json of the library.
|
|
72
72
|
*/
|
|
73
|
-
manifestPath
|
|
73
|
+
manifestPath?: string;
|
|
74
74
|
/**
|
|
75
75
|
* Parsed content of the manifest.json to avoid multiple reads when working with
|
|
76
76
|
* the search results.
|
|
77
77
|
*/
|
|
78
|
-
manifest
|
|
78
|
+
manifest?: Manifest;
|
|
79
|
+
/**
|
|
80
|
+
* Path to the .library file of the library, if existing.
|
|
81
|
+
*/
|
|
82
|
+
libraryPath?: string;
|
|
79
83
|
}
|
|
80
84
|
export interface FoundFioriArtifacts {
|
|
81
85
|
applications?: AllAppResults[];
|