@sap-ux/project-access 1.17.0 → 1.17.2
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-access.d.ts +9 -0
- package/dist/file/file-access.js +18 -1
- package/dist/file/index.d.ts +1 -1
- package/dist/file/index.js +2 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +4 -1
- package/dist/project/access.d.ts +20 -0
- package/dist/project/access.js +270 -0
- package/dist/project/i18n/index.d.ts +2 -0
- package/dist/project/i18n/index.js +9 -1
- package/dist/project/i18n/read.d.ts +22 -0
- package/dist/project/i18n/read.js +59 -0
- package/dist/project/i18n/write.d.ts +78 -0
- package/dist/project/i18n/write.js +160 -0
- package/dist/project/index.d.ts +2 -1
- package/dist/project/index.js +5 -1
- package/dist/project/module-loader.js +1 -2
- package/dist/types/access/index.d.ts +25 -0
- package/dist/types/access/index.js +3 -0
- package/dist/types/i18n/index.d.ts +18 -0
- package/dist/types/i18n/index.js +3 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.js +2 -0
- package/package.json +3 -2
|
@@ -15,6 +15,15 @@ export declare function readFile(path: string, memFs?: Editor): Promise<string>;
|
|
|
15
15
|
* @returns - file content as object of type T
|
|
16
16
|
*/
|
|
17
17
|
export declare function readJSON<T>(path: string, memFs?: Editor): Promise<T>;
|
|
18
|
+
/**
|
|
19
|
+
* Read file asynchronously. Throws error if file does not exist.
|
|
20
|
+
*
|
|
21
|
+
* @param path - path to file
|
|
22
|
+
* @param content - content to write to a file
|
|
23
|
+
* @param memFs - optional mem-fs-editor instance
|
|
24
|
+
* @returns - file content as string
|
|
25
|
+
*/
|
|
26
|
+
export declare function writeFile(path: string, content: string, memFs?: Editor): Promise<string | void>;
|
|
18
27
|
/**
|
|
19
28
|
* Checks if the provided file exists in the file system.
|
|
20
29
|
*
|
package/dist/file/file-access.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.fileExists = exports.readJSON = exports.readFile = void 0;
|
|
12
|
+
exports.fileExists = exports.writeFile = exports.readJSON = exports.readFile = void 0;
|
|
13
13
|
const fs_1 = require("fs");
|
|
14
14
|
/**
|
|
15
15
|
* Read file asynchronously. Throws error if file does not exist.
|
|
@@ -47,6 +47,23 @@ function readJSON(path, memFs) {
|
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
49
|
exports.readJSON = readJSON;
|
|
50
|
+
/**
|
|
51
|
+
* Read file asynchronously. Throws error if file does not exist.
|
|
52
|
+
*
|
|
53
|
+
* @param path - path to file
|
|
54
|
+
* @param content - content to write to a file
|
|
55
|
+
* @param memFs - optional mem-fs-editor instance
|
|
56
|
+
* @returns - file content as string
|
|
57
|
+
*/
|
|
58
|
+
function writeFile(path, content, memFs) {
|
|
59
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
if (memFs) {
|
|
61
|
+
return memFs.write(path, content);
|
|
62
|
+
}
|
|
63
|
+
return fs_1.promises.writeFile(path, content, { encoding: 'utf8' });
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
exports.writeFile = writeFile;
|
|
50
67
|
/**
|
|
51
68
|
* Checks if the provided file exists in the file system.
|
|
52
69
|
*
|
package/dist/file/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { fileExists, readFile, readJSON } from './file-access';
|
|
1
|
+
export { fileExists, readFile, readJSON, writeFile } from './file-access';
|
|
2
2
|
export { findBy, findFiles, findFilesByExtension, findFileUp, getFilePaths } from './file-search';
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/file/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getFilePaths = exports.findFileUp = exports.findFilesByExtension = exports.findFiles = exports.findBy = exports.readJSON = exports.readFile = exports.fileExists = void 0;
|
|
3
|
+
exports.getFilePaths = exports.findFileUp = exports.findFilesByExtension = exports.findFiles = exports.findBy = exports.writeFile = exports.readJSON = exports.readFile = exports.fileExists = void 0;
|
|
4
4
|
var file_access_1 = require("./file-access");
|
|
5
5
|
Object.defineProperty(exports, "fileExists", { enumerable: true, get: function () { return file_access_1.fileExists; } });
|
|
6
6
|
Object.defineProperty(exports, "readFile", { enumerable: true, get: function () { return file_access_1.readFile; } });
|
|
7
7
|
Object.defineProperty(exports, "readJSON", { enumerable: true, get: function () { return file_access_1.readJSON; } });
|
|
8
|
+
Object.defineProperty(exports, "writeFile", { enumerable: true, get: function () { return file_access_1.writeFile; } });
|
|
8
9
|
var file_search_1 = require("./file-search");
|
|
9
10
|
Object.defineProperty(exports, "findBy", { enumerable: true, get: function () { return file_search_1.findBy; } });
|
|
10
11
|
Object.defineProperty(exports, "findFiles", { enumerable: true, get: function () { return file_search_1.findFiles; } });
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { FileName } from './constants';
|
|
2
2
|
export { getFilePaths } from './file';
|
|
3
|
-
export { findAllApps, findCapProjects, findFioriArtifacts, findProjectRoot, getAppRootFromWebappPath, getAppProgrammingLanguage, getAppType, getCapCustomPaths, getCapEnvironment, getCapModelAndServices, getCapProjectType, getCdsFiles, getCdsRoots, getCdsServices, getI18nPropertiesPaths, getMtaPath, getNodeModulesPath, getProject, getProjectType, getWebappPath, isCapJavaProject, isCapNodeJsProject, loadModuleFromProject, readCapServiceMetadataEdmx, readUi5Yaml } from './project';
|
|
3
|
+
export { createApplicationAccess, createProjectAccess, findAllApps, findCapProjects, findFioriArtifacts, findProjectRoot, getAppRootFromWebappPath, getAppProgrammingLanguage, getAppType, getCapCustomPaths, getCapEnvironment, getCapModelAndServices, getCapProjectType, getCdsFiles, getCdsRoots, getCdsServices, getCapI18nFolderNames, getI18nPropertiesPaths, getMtaPath, getNodeModulesPath, getProject, getProjectType, getWebappPath, isCapJavaProject, isCapNodeJsProject, loadModuleFromProject, readCapServiceMetadataEdmx, readUi5Yaml } from './project';
|
|
4
4
|
export * from './types';
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -14,12 +14,14 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.readUi5Yaml = exports.readCapServiceMetadataEdmx = exports.loadModuleFromProject = exports.isCapNodeJsProject = exports.isCapJavaProject = exports.getWebappPath = exports.getProjectType = exports.getProject = exports.getNodeModulesPath = exports.getMtaPath = exports.getI18nPropertiesPaths = exports.getCdsServices = exports.getCdsRoots = exports.getCdsFiles = exports.getCapProjectType = exports.getCapModelAndServices = exports.getCapEnvironment = exports.getCapCustomPaths = exports.getAppType = exports.getAppProgrammingLanguage = exports.getAppRootFromWebappPath = exports.findProjectRoot = exports.findFioriArtifacts = exports.findCapProjects = exports.findAllApps = exports.getFilePaths = exports.FileName = void 0;
|
|
17
|
+
exports.readUi5Yaml = exports.readCapServiceMetadataEdmx = exports.loadModuleFromProject = exports.isCapNodeJsProject = exports.isCapJavaProject = exports.getWebappPath = exports.getProjectType = exports.getProject = exports.getNodeModulesPath = exports.getMtaPath = exports.getI18nPropertiesPaths = exports.getCapI18nFolderNames = exports.getCdsServices = exports.getCdsRoots = exports.getCdsFiles = exports.getCapProjectType = exports.getCapModelAndServices = exports.getCapEnvironment = exports.getCapCustomPaths = exports.getAppType = exports.getAppProgrammingLanguage = exports.getAppRootFromWebappPath = exports.findProjectRoot = exports.findFioriArtifacts = exports.findCapProjects = exports.findAllApps = exports.createProjectAccess = exports.createApplicationAccess = exports.getFilePaths = exports.FileName = void 0;
|
|
18
18
|
var constants_1 = require("./constants");
|
|
19
19
|
Object.defineProperty(exports, "FileName", { enumerable: true, get: function () { return constants_1.FileName; } });
|
|
20
20
|
var file_1 = require("./file");
|
|
21
21
|
Object.defineProperty(exports, "getFilePaths", { enumerable: true, get: function () { return file_1.getFilePaths; } });
|
|
22
22
|
var project_1 = require("./project");
|
|
23
|
+
Object.defineProperty(exports, "createApplicationAccess", { enumerable: true, get: function () { return project_1.createApplicationAccess; } });
|
|
24
|
+
Object.defineProperty(exports, "createProjectAccess", { enumerable: true, get: function () { return project_1.createProjectAccess; } });
|
|
23
25
|
Object.defineProperty(exports, "findAllApps", { enumerable: true, get: function () { return project_1.findAllApps; } });
|
|
24
26
|
Object.defineProperty(exports, "findCapProjects", { enumerable: true, get: function () { return project_1.findCapProjects; } });
|
|
25
27
|
Object.defineProperty(exports, "findFioriArtifacts", { enumerable: true, get: function () { return project_1.findFioriArtifacts; } });
|
|
@@ -34,6 +36,7 @@ Object.defineProperty(exports, "getCapProjectType", { enumerable: true, get: fun
|
|
|
34
36
|
Object.defineProperty(exports, "getCdsFiles", { enumerable: true, get: function () { return project_1.getCdsFiles; } });
|
|
35
37
|
Object.defineProperty(exports, "getCdsRoots", { enumerable: true, get: function () { return project_1.getCdsRoots; } });
|
|
36
38
|
Object.defineProperty(exports, "getCdsServices", { enumerable: true, get: function () { return project_1.getCdsServices; } });
|
|
39
|
+
Object.defineProperty(exports, "getCapI18nFolderNames", { enumerable: true, get: function () { return project_1.getCapI18nFolderNames; } });
|
|
37
40
|
Object.defineProperty(exports, "getI18nPropertiesPaths", { enumerable: true, get: function () { return project_1.getI18nPropertiesPaths; } });
|
|
38
41
|
Object.defineProperty(exports, "getMtaPath", { enumerable: true, get: function () { return project_1.getMtaPath; } });
|
|
39
42
|
Object.defineProperty(exports, "getNodeModulesPath", { enumerable: true, get: function () { return project_1.getNodeModulesPath; } });
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ApplicationAccess, ProjectAccess } from '../types';
|
|
2
|
+
import type { Editor } from 'mem-fs-editor';
|
|
3
|
+
/**
|
|
4
|
+
* Create an instance of ApplicationAccess that contains information about the application, like paths and services.
|
|
5
|
+
*
|
|
6
|
+
* @param appRoot - Application root path
|
|
7
|
+
* @param fs optional `mem-fs-editor` instance. If provided, `mem-fs-editor` api is used instead of `fs` of node.
|
|
8
|
+
* In case of CAP project, some CDS APIs are used internally which depends on `fs` of node and not `mem-fs-editor`.
|
|
9
|
+
* 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.
|
|
10
|
+
* @returns - Instance of ApplicationAccess that contains information about the application, like paths and services
|
|
11
|
+
*/
|
|
12
|
+
export declare function createApplicationAccess(appRoot: string, fs?: Editor): Promise<ApplicationAccess>;
|
|
13
|
+
/**
|
|
14
|
+
* Create an instance of ProjectAccess that contains information about the project, like applications, paths, services.
|
|
15
|
+
*
|
|
16
|
+
* @param root - Project root path
|
|
17
|
+
* @returns - Instance of ProjectAccess that contains information about the project
|
|
18
|
+
*/
|
|
19
|
+
export declare function createProjectAccess(root: string): Promise<ProjectAccess>;
|
|
20
|
+
//# sourceMappingURL=access.d.ts.map
|
|
@@ -0,0 +1,270 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.createProjectAccess = exports.createApplicationAccess = void 0;
|
|
13
|
+
const path_1 = require("path");
|
|
14
|
+
const i18n_1 = require("./i18n");
|
|
15
|
+
const info_1 = require("./info");
|
|
16
|
+
const search_1 = require("./search");
|
|
17
|
+
/**
|
|
18
|
+
*
|
|
19
|
+
*/
|
|
20
|
+
class ApplicationAccessImp {
|
|
21
|
+
/**
|
|
22
|
+
* Constructor for ApplicationAccess.
|
|
23
|
+
*
|
|
24
|
+
* @param _project - Project structure
|
|
25
|
+
* @param appId - Application ID
|
|
26
|
+
* @param fs optional `mem-fs-editor` instance.
|
|
27
|
+
*/
|
|
28
|
+
constructor(_project, appId, fs) {
|
|
29
|
+
this._project = _project;
|
|
30
|
+
this.appId = appId;
|
|
31
|
+
this.fs = fs;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Returns the application structure.
|
|
35
|
+
*
|
|
36
|
+
* @returns ApplicationStructure
|
|
37
|
+
*/
|
|
38
|
+
get app() {
|
|
39
|
+
return this.project.apps[this.appId];
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Maintains new translation entries in an existing i18n file or in a new i18n properties file if it does not exist.
|
|
43
|
+
*
|
|
44
|
+
* @param newEntries - translation entries to write in the `.properties` file
|
|
45
|
+
* @returns - boolean or exception
|
|
46
|
+
* @description It also update `manifest.json` file if `@i18n` entry is missing from `"sap.ui5":{"models": {}}`
|
|
47
|
+
* as
|
|
48
|
+
* ```JSON
|
|
49
|
+
* {
|
|
50
|
+
* "sap.ui5": {
|
|
51
|
+
* "models": {
|
|
52
|
+
* "@i18n": {
|
|
53
|
+
* "type": "sap.ui.model.resource.ResourceModel",
|
|
54
|
+
* "uri": "i18n/i18n.properties"
|
|
55
|
+
* }
|
|
56
|
+
* }
|
|
57
|
+
* }
|
|
58
|
+
* }
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
createAnnotationI18nEntries(newEntries) {
|
|
62
|
+
return (0, i18n_1.createAnnotationI18nEntries)(this.project.root, this.app.manifest, this.app.i18n, newEntries, this.fs);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Maintains new translation entries in an existing i18n file or in a new i18n properties file if it does not exist.
|
|
66
|
+
*
|
|
67
|
+
* @param newEntries - translation entries to write in the `.properties` file
|
|
68
|
+
* @param modelKey - i18n model key. Default key is `i18n`
|
|
69
|
+
* @returns boolean or exception
|
|
70
|
+
* @description It also update `manifest.json` file if `<modelKey>` entry is missing from `"sap.ui5":{"models": {}}`
|
|
71
|
+
* as
|
|
72
|
+
* ```JSON
|
|
73
|
+
* {
|
|
74
|
+
* "sap.ui5": {
|
|
75
|
+
* "models": {
|
|
76
|
+
* "<modelKey>": {
|
|
77
|
+
* "type": "sap.ui.model.resource.ResourceModel",
|
|
78
|
+
* "uri": "i18n/i18n.properties"
|
|
79
|
+
* }
|
|
80
|
+
* }
|
|
81
|
+
* }
|
|
82
|
+
* }
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
createUI5I18nEntries(newEntries, modelKey = 'i18n') {
|
|
86
|
+
return (0, i18n_1.createUI5I18nEntries)(this.project.root, this.app.manifest, this.app.i18n, newEntries, modelKey, this.fs);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Maintains new translation entries in an existing i18n file or in a new i18n properties file if it does not exist.
|
|
90
|
+
*
|
|
91
|
+
* @param newEntries translation entries to write in the `.properties` file
|
|
92
|
+
* @returns boolean or exception
|
|
93
|
+
* @description If `i18n` entry is missing from `"sap.app":{}`, default `i18n/i18n.properties` is used. Update of `manifest.json` file is not needed.
|
|
94
|
+
*/
|
|
95
|
+
createManifestI18nEntries(newEntries) {
|
|
96
|
+
return (0, i18n_1.createManifestI18nEntries)(this.project.root, this.app.i18n, newEntries, this.fs);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Maintains new translation entries in CAP i18n files.
|
|
100
|
+
*
|
|
101
|
+
* @param filePath file in which the translation entry will be used.
|
|
102
|
+
* @param newI18nEntries translation entries to write in the i18n file.
|
|
103
|
+
* @returns boolean or exception
|
|
104
|
+
*/
|
|
105
|
+
createCapI18nEntries(filePath, newI18nEntries) {
|
|
106
|
+
return (0, i18n_1.createCapI18nEntries)(this.project.root, filePath, newI18nEntries, this.fs);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Return the application id of this app, which is the relative path from the project root
|
|
110
|
+
* to the app root.
|
|
111
|
+
*
|
|
112
|
+
* @returns - Application root path
|
|
113
|
+
*/
|
|
114
|
+
getAppId() {
|
|
115
|
+
return this.appId;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Return the absolute application root path.
|
|
119
|
+
*
|
|
120
|
+
* @returns - Application root path
|
|
121
|
+
*/
|
|
122
|
+
getAppRoot() {
|
|
123
|
+
return this.app.appRoot;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
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
|
+
*
|
|
128
|
+
* @returns i18n bundles or exception
|
|
129
|
+
*/
|
|
130
|
+
getI18nBundles() {
|
|
131
|
+
return (0, i18n_1.getI18nBundles)(this.project.root, this.app.i18n, this.project.projectType, this.fs);
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Return absolute paths to i18n.properties files from manifest.
|
|
135
|
+
*
|
|
136
|
+
* @returns absolute paths to i18n.properties
|
|
137
|
+
*/
|
|
138
|
+
getI18nPropertiesPaths() {
|
|
139
|
+
return (0, i18n_1.getI18nPropertiesPaths)(this.app.manifest);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Project structure.
|
|
143
|
+
*
|
|
144
|
+
* @returns - Project structure
|
|
145
|
+
*/
|
|
146
|
+
get project() {
|
|
147
|
+
return this._project;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Project type.
|
|
151
|
+
*
|
|
152
|
+
* @returns - Project type, like EDMXBackend, CAPJava, or CAPNodejs
|
|
153
|
+
*/
|
|
154
|
+
get projectType() {
|
|
155
|
+
return this.project.projectType;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Project root path.
|
|
159
|
+
*
|
|
160
|
+
* @returns - Project root path
|
|
161
|
+
*/
|
|
162
|
+
get root() {
|
|
163
|
+
return this.project.root;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Class that implements ProjectAccess interface.
|
|
168
|
+
* It can be used to retrieve information about the project, like applications, paths, services.
|
|
169
|
+
*/
|
|
170
|
+
class ProjectAccessImp {
|
|
171
|
+
/**
|
|
172
|
+
* Constructor for ProjectAccess.
|
|
173
|
+
*
|
|
174
|
+
* @param _project - Project structure
|
|
175
|
+
*/
|
|
176
|
+
constructor(_project) {
|
|
177
|
+
this._project = _project;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Returns list of application IDs.
|
|
181
|
+
*
|
|
182
|
+
* @returns - array of application IDs. For single application projects it will return ['']
|
|
183
|
+
*/
|
|
184
|
+
getApplicationIds() {
|
|
185
|
+
return Object.keys(this._project.apps);
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Returns an instance of an application for a given application ID. The contains information about the application, like paths and services.
|
|
189
|
+
*
|
|
190
|
+
* @param appId - application ID
|
|
191
|
+
* @returns - Instance of ApplicationAccess that contains information about the application, like paths and services
|
|
192
|
+
*/
|
|
193
|
+
getApplication(appId) {
|
|
194
|
+
if (!this.project.apps[appId]) {
|
|
195
|
+
throw new Error(`Could not find app with id ${appId}`);
|
|
196
|
+
}
|
|
197
|
+
return new ApplicationAccessImp(this.project, appId);
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Project structure.
|
|
201
|
+
*
|
|
202
|
+
* @returns - Project structure
|
|
203
|
+
*/
|
|
204
|
+
get project() {
|
|
205
|
+
return this._project;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Project type.
|
|
209
|
+
*
|
|
210
|
+
* @returns - Project type, like EDMXBackend, CAPJava, or CAPNodejs
|
|
211
|
+
*/
|
|
212
|
+
get projectType() {
|
|
213
|
+
return this.project.projectType;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Project root path.
|
|
217
|
+
*
|
|
218
|
+
* @returns - Project root path
|
|
219
|
+
*/
|
|
220
|
+
get root() {
|
|
221
|
+
return this.project.root;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Create an instance of ApplicationAccess that contains information about the application, like paths and services.
|
|
226
|
+
*
|
|
227
|
+
* @param appRoot - Application root path
|
|
228
|
+
* @param fs optional `mem-fs-editor` instance. If provided, `mem-fs-editor` api is used instead of `fs` of node.
|
|
229
|
+
* In case of CAP project, some CDS APIs are used internally which depends on `fs` of node and not `mem-fs-editor`.
|
|
230
|
+
* 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.
|
|
231
|
+
* @returns - Instance of ApplicationAccess that contains information about the application, like paths and services
|
|
232
|
+
*/
|
|
233
|
+
function createApplicationAccess(appRoot, fs) {
|
|
234
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
235
|
+
try {
|
|
236
|
+
const apps = yield (0, search_1.findAllApps)([appRoot]);
|
|
237
|
+
const app = apps.find((app) => app.appRoot === appRoot);
|
|
238
|
+
if (!app) {
|
|
239
|
+
throw new Error(`Could not find app with root ${appRoot}`);
|
|
240
|
+
}
|
|
241
|
+
const project = yield (0, info_1.getProject)(app.projectRoot);
|
|
242
|
+
const appId = (0, path_1.relative)(project.root, appRoot);
|
|
243
|
+
return new ApplicationAccessImp(project, appId, fs);
|
|
244
|
+
}
|
|
245
|
+
catch (error) {
|
|
246
|
+
throw Error(`Error when creating application access for ${appRoot}: ${error}`);
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
exports.createApplicationAccess = createApplicationAccess;
|
|
251
|
+
/**
|
|
252
|
+
* Create an instance of ProjectAccess that contains information about the project, like applications, paths, services.
|
|
253
|
+
*
|
|
254
|
+
* @param root - Project root path
|
|
255
|
+
* @returns - Instance of ProjectAccess that contains information about the project
|
|
256
|
+
*/
|
|
257
|
+
function createProjectAccess(root) {
|
|
258
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
259
|
+
try {
|
|
260
|
+
const project = yield (0, info_1.getProject)(root);
|
|
261
|
+
const projectAccess = new ProjectAccessImp(project);
|
|
262
|
+
return projectAccess;
|
|
263
|
+
}
|
|
264
|
+
catch (error) {
|
|
265
|
+
throw Error(`Error when creating project access for ${root}: ${error}`);
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
exports.createProjectAccess = createProjectAccess;
|
|
270
|
+
//# sourceMappingURL=access.js.map
|
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
export { getI18nPropertiesPaths } from './i18n';
|
|
2
|
+
export { getCapI18nFolderNames, getI18nBundles } from './read';
|
|
3
|
+
export { createManifestI18nEntries, createUI5I18nEntries, createAnnotationI18nEntries, createCapI18nEntries } from './write';
|
|
2
4
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getI18nPropertiesPaths = void 0;
|
|
3
|
+
exports.createCapI18nEntries = exports.createAnnotationI18nEntries = exports.createUI5I18nEntries = exports.createManifestI18nEntries = exports.getI18nBundles = exports.getCapI18nFolderNames = exports.getI18nPropertiesPaths = void 0;
|
|
4
4
|
var i18n_1 = require("./i18n");
|
|
5
5
|
Object.defineProperty(exports, "getI18nPropertiesPaths", { enumerable: true, get: function () { return i18n_1.getI18nPropertiesPaths; } });
|
|
6
|
+
var read_1 = require("./read");
|
|
7
|
+
Object.defineProperty(exports, "getCapI18nFolderNames", { enumerable: true, get: function () { return read_1.getCapI18nFolderNames; } });
|
|
8
|
+
Object.defineProperty(exports, "getI18nBundles", { enumerable: true, get: function () { return read_1.getI18nBundles; } });
|
|
9
|
+
var write_1 = require("./write");
|
|
10
|
+
Object.defineProperty(exports, "createManifestI18nEntries", { enumerable: true, get: function () { return write_1.createManifestI18nEntries; } });
|
|
11
|
+
Object.defineProperty(exports, "createUI5I18nEntries", { enumerable: true, get: function () { return write_1.createUI5I18nEntries; } });
|
|
12
|
+
Object.defineProperty(exports, "createAnnotationI18nEntries", { enumerable: true, get: function () { return write_1.createAnnotationI18nEntries; } });
|
|
13
|
+
Object.defineProperty(exports, "createCapI18nEntries", { enumerable: true, get: function () { return write_1.createCapI18nEntries; } });
|
|
6
14
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { I18nBundles, I18nPropertiesPaths, ProjectType } from '../../types';
|
|
2
|
+
import type { Editor } from 'mem-fs-editor';
|
|
3
|
+
/**
|
|
4
|
+
* For a given app in project, retrieves i18n bundles for 'sap.app' namespace,`models` of `sap.ui5` namespace and service for cap services.
|
|
5
|
+
*
|
|
6
|
+
* @param root project root
|
|
7
|
+
* @param i18nPropertiesPaths paths to `.properties` file`
|
|
8
|
+
* @param projectType optional type of project
|
|
9
|
+
* @param fs optional `mem-fs-editor` instance. If provided, `mem-fs-editor` api is used instead of `fs` of node.
|
|
10
|
+
* In case of CAP project, some CDS APIs are used internally which depends on `fs` of node and not `mem-fs-editor`.
|
|
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
|
|
13
|
+
*/
|
|
14
|
+
export declare function getI18nBundles(root: string, i18nPropertiesPaths: I18nPropertiesPaths, projectType?: ProjectType, fs?: Editor): Promise<I18nBundles>;
|
|
15
|
+
/**
|
|
16
|
+
* Retrieves a list of potential folder names for i18n files.
|
|
17
|
+
*
|
|
18
|
+
* @param root Project root.
|
|
19
|
+
* @returns ii18n folder names
|
|
20
|
+
*/
|
|
21
|
+
export declare function getCapI18nFolderNames(root: string): Promise<string[]>;
|
|
22
|
+
//# sourceMappingURL=read.d.ts.map
|
|
@@ -0,0 +1,59 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.getCapI18nFolderNames = exports.getI18nBundles = void 0;
|
|
13
|
+
const i18n_1 = require("@sap-ux/i18n");
|
|
14
|
+
const __1 = require("..");
|
|
15
|
+
/**
|
|
16
|
+
* For a given app in project, retrieves i18n bundles for 'sap.app' namespace,`models` of `sap.ui5` namespace and service for cap services.
|
|
17
|
+
*
|
|
18
|
+
* @param root project root
|
|
19
|
+
* @param i18nPropertiesPaths paths to `.properties` file`
|
|
20
|
+
* @param projectType optional type of project
|
|
21
|
+
* @param fs optional `mem-fs-editor` instance. If provided, `mem-fs-editor` api is used instead of `fs` of node.
|
|
22
|
+
* In case of CAP project, some CDS APIs are used internally which depends on `fs` of node and not `mem-fs-editor`.
|
|
23
|
+
* 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
|
|
25
|
+
*/
|
|
26
|
+
function getI18nBundles(root, i18nPropertiesPaths, projectType, fs) {
|
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
const result = {
|
|
29
|
+
'sap.app': {},
|
|
30
|
+
models: {},
|
|
31
|
+
service: {}
|
|
32
|
+
};
|
|
33
|
+
result['sap.app'] = yield (0, i18n_1.getPropertiesI18nBundle)(i18nPropertiesPaths['sap.app'], fs);
|
|
34
|
+
for (const key of Object.keys(i18nPropertiesPaths.models)) {
|
|
35
|
+
result.models[key] = yield (0, i18n_1.getPropertiesI18nBundle)(i18nPropertiesPaths.models[key].path, fs);
|
|
36
|
+
}
|
|
37
|
+
if (projectType === 'CAPNodejs') {
|
|
38
|
+
const env = yield (0, __1.getCapEnvironment)(root);
|
|
39
|
+
const cdsFiles = yield (0, __1.getCdsFiles)(root, true);
|
|
40
|
+
result.service = yield (0, i18n_1.getCapI18nBundle)(root, env, cdsFiles, fs);
|
|
41
|
+
}
|
|
42
|
+
return result;
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
exports.getI18nBundles = getI18nBundles;
|
|
46
|
+
/**
|
|
47
|
+
* Retrieves a list of potential folder names for i18n files.
|
|
48
|
+
*
|
|
49
|
+
* @param root Project root.
|
|
50
|
+
* @returns ii18n folder names
|
|
51
|
+
*/
|
|
52
|
+
function getCapI18nFolderNames(root) {
|
|
53
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
const environment = yield (0, __1.getCapEnvironment)(root);
|
|
55
|
+
return (0, i18n_1.getI18nFolderNames)(environment);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
exports.getCapI18nFolderNames = getCapI18nFolderNames;
|
|
59
|
+
//# sourceMappingURL=read.js.map
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { NewI18nEntry } from '@sap-ux/i18n';
|
|
2
|
+
import type { I18nPropertiesPaths } from '../../types';
|
|
3
|
+
import type { Editor } from 'mem-fs-editor';
|
|
4
|
+
/**
|
|
5
|
+
* Maintains new translation entries in CAP i18n files.
|
|
6
|
+
*
|
|
7
|
+
* @param root project root.
|
|
8
|
+
* @param filePath file in which the translation entry will be used.
|
|
9
|
+
* @param newI18nEntries translation entries to write in the i18n file.
|
|
10
|
+
* @param fs optional `mem-fs-editor` instance. If provided, `mem-fs-editor` api is used instead of `fs` of node
|
|
11
|
+
* In case of CAP project, some CDS APIs are used internally which depends on `fs` of node and not `mem-fs-editor`.
|
|
12
|
+
* 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.
|
|
13
|
+
* @returns boolean or exception
|
|
14
|
+
*/
|
|
15
|
+
export declare function createCapI18nEntries(root: string, filePath: string, newI18nEntries: NewI18nEntry[], fs?: Editor): Promise<boolean>;
|
|
16
|
+
/**
|
|
17
|
+
* Maintains new translation entries in an existing i18n file or in a new i18n properties file if it does not exist.
|
|
18
|
+
*
|
|
19
|
+
* @param root project root
|
|
20
|
+
* @param manifestPath absolute path to `manifest.json` file
|
|
21
|
+
* @param i18nPropertiesPaths paths to `.properties` file`
|
|
22
|
+
* @param newEntries translation entries to write in the `.properties` file
|
|
23
|
+
* @param modelKey i18n model key
|
|
24
|
+
* @param fs optional `mem-fs-editor` instance. If provided, `mem-fs-editor` api is used instead of `fs` of node
|
|
25
|
+
* @returns boolean or exception
|
|
26
|
+
* @description It also update `manifest.json` file if `<modelKey>` entry is missing from `"sap.ui5":{"models": {}}`
|
|
27
|
+
* as
|
|
28
|
+
* ```JSON
|
|
29
|
+
* {
|
|
30
|
+
* "sap.ui5": {
|
|
31
|
+
* "models": {
|
|
32
|
+
* "<modelKey>": {
|
|
33
|
+
* "type": "sap.ui.model.resource.ResourceModel",
|
|
34
|
+
* "uri": "i18n/i18n.properties"
|
|
35
|
+
* }
|
|
36
|
+
* }
|
|
37
|
+
* }
|
|
38
|
+
* }
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export declare function createUI5I18nEntries(root: string, manifestPath: string, i18nPropertiesPaths: I18nPropertiesPaths, newEntries: NewI18nEntry[], modelKey: string, fs?: Editor): Promise<boolean>;
|
|
42
|
+
/**
|
|
43
|
+
* Maintains new translation entries in an existing i18n file or in a new i18n properties file if it does not exist.
|
|
44
|
+
*
|
|
45
|
+
* @param root project root
|
|
46
|
+
* @param manifestPath absolute path to `manifest.json` file
|
|
47
|
+
* @param i18nPropertiesPaths paths to `.properties` file`
|
|
48
|
+
* @param newEntries translation entries to write in the `.properties` file
|
|
49
|
+
* @param fs optional `mem-fs-editor` instance. If provided, `mem-fs-editor` api is used instead of `fs` of node
|
|
50
|
+
* @returns boolean or exception
|
|
51
|
+
* @description It also update `manifest.json` file if `@i18n` entry is missing from `"sap.ui5":{"models": {}}`
|
|
52
|
+
* as
|
|
53
|
+
* ```JSON
|
|
54
|
+
* {
|
|
55
|
+
* "sap.ui5": {
|
|
56
|
+
* "models": {
|
|
57
|
+
* "@i18n": {
|
|
58
|
+
* "type": "sap.ui.model.resource.ResourceModel",
|
|
59
|
+
* "uri": "i18n/i18n.properties"
|
|
60
|
+
* }
|
|
61
|
+
* }
|
|
62
|
+
* }
|
|
63
|
+
* }
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
export declare function createAnnotationI18nEntries(root: string, manifestPath: string, i18nPropertiesPaths: I18nPropertiesPaths, newEntries: NewI18nEntry[], fs?: Editor): Promise<boolean>;
|
|
67
|
+
/**
|
|
68
|
+
* Maintains new translation entries in an existing i18n file or in a new i18n properties file if it does not exist.
|
|
69
|
+
*
|
|
70
|
+
* @param root project root
|
|
71
|
+
* @param i18nPropertiesPaths paths to `.properties` file`
|
|
72
|
+
* @param newEntries translation entries to write in the `.properties` file
|
|
73
|
+
* @param fs optional `mem-fs-editor` instance. If provided, `mem-fs-editor` api is used instead of `fs` of node
|
|
74
|
+
* @returns boolean or exception
|
|
75
|
+
* @description If `i18n` entry is missing from `"sap.app":{}`, default `i18n/i18n.properties` is used. Update of `manifest.json` file is not needed.
|
|
76
|
+
*/
|
|
77
|
+
export declare function createManifestI18nEntries(root: string, i18nPropertiesPaths: I18nPropertiesPaths, newEntries: NewI18nEntry[], fs?: Editor): Promise<boolean>;
|
|
78
|
+
//# sourceMappingURL=write.d.ts.map
|
|
@@ -0,0 +1,160 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.createManifestI18nEntries = exports.createAnnotationI18nEntries = exports.createUI5I18nEntries = exports.createCapI18nEntries = void 0;
|
|
13
|
+
const i18n_1 = require("@sap-ux/i18n");
|
|
14
|
+
const __1 = require("..");
|
|
15
|
+
const path_1 = require("path");
|
|
16
|
+
const file_1 = require("../../file");
|
|
17
|
+
const promises_1 = require("fs/promises");
|
|
18
|
+
/**
|
|
19
|
+
* Maintains new translation entries in CAP i18n files.
|
|
20
|
+
*
|
|
21
|
+
* @param root project root.
|
|
22
|
+
* @param filePath file in which the translation entry will be used.
|
|
23
|
+
* @param newI18nEntries translation entries to write in the i18n file.
|
|
24
|
+
* @param fs optional `mem-fs-editor` instance. If provided, `mem-fs-editor` api is used instead of `fs` of node
|
|
25
|
+
* In case of CAP project, some CDS APIs are used internally which depends on `fs` of node and not `mem-fs-editor`.
|
|
26
|
+
* 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.
|
|
27
|
+
* @returns boolean or exception
|
|
28
|
+
*/
|
|
29
|
+
function createCapI18nEntries(root, filePath, newI18nEntries, fs) {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
const env = yield (0, __1.getCapEnvironment)(root);
|
|
32
|
+
return (0, i18n_1.createCapI18nEntries)(root, filePath, newI18nEntries, env, fs);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
exports.createCapI18nEntries = createCapI18nEntries;
|
|
36
|
+
/**
|
|
37
|
+
* Maintains new translation entries in an existing i18n file or in a new i18n properties file if it does not exist for given model key.
|
|
38
|
+
*
|
|
39
|
+
* @param root project root
|
|
40
|
+
* @param manifestPath absolute path to `manifest.json` file
|
|
41
|
+
* @param i18nPropertiesPaths paths to `.properties` file`
|
|
42
|
+
* @param newEntries translation entries to write in the `.properties` file
|
|
43
|
+
* @param modelKey i18n model key,
|
|
44
|
+
* @param fs optional `mem-fs-editor` instance. If provided, `mem-fs-editor` api is used instead of `fs` of node
|
|
45
|
+
* @returns boolean or exception
|
|
46
|
+
*/
|
|
47
|
+
function createUI5I18nEntriesBase(root, manifestPath, i18nPropertiesPaths, newEntries, modelKey, fs) {
|
|
48
|
+
var _a, _b;
|
|
49
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
const defaultPath = 'i18n/i18n.properties';
|
|
51
|
+
const i18nFilePath = (_a = i18nPropertiesPaths.models[modelKey]) === null || _a === void 0 ? void 0 : _a.path;
|
|
52
|
+
if (i18nFilePath) {
|
|
53
|
+
// ensure folder for i18n exists
|
|
54
|
+
const dirPath = (0, path_1.dirname)(i18nFilePath);
|
|
55
|
+
if (!fs) {
|
|
56
|
+
// create directory when mem-fs-editor is not provided. when mem-fs-editor is provided, directory is created on using `.commit()` API
|
|
57
|
+
yield (0, promises_1.mkdir)(dirPath, { recursive: true });
|
|
58
|
+
}
|
|
59
|
+
return (0, i18n_1.createPropertiesI18nEntries)(i18nFilePath, newEntries, root, fs);
|
|
60
|
+
}
|
|
61
|
+
// update manifest.json entry
|
|
62
|
+
const manifest = yield (0, file_1.readJSON)(manifestPath);
|
|
63
|
+
const models = Object.assign({}, (_b = manifest['sap.ui5']) === null || _b === void 0 ? void 0 : _b.models);
|
|
64
|
+
models[modelKey] = { type: 'sap.ui.model.resource.ResourceModel', uri: defaultPath };
|
|
65
|
+
const newContent = Object.assign(Object.assign({}, manifest), { 'sap.ui5': Object.assign(Object.assign({}, manifest['sap.ui5']), { models }) });
|
|
66
|
+
yield (0, file_1.writeFile)(manifestPath, JSON.stringify(newContent, undefined, 4), fs);
|
|
67
|
+
// make sure i18n folder exists
|
|
68
|
+
const dirPath = (0, path_1.dirname)(defaultPath);
|
|
69
|
+
if (!fs) {
|
|
70
|
+
// create directory when mem-fs-editor is not provided. when mem-fs-editor is provided, directory is created on using `.commit()` API
|
|
71
|
+
yield (0, promises_1.mkdir)((0, path_1.join)(root, dirPath), { recursive: true });
|
|
72
|
+
}
|
|
73
|
+
return (0, i18n_1.createPropertiesI18nEntries)((0, path_1.join)(root, defaultPath), newEntries, root, fs);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Maintains new translation entries in an existing i18n file or in a new i18n properties file if it does not exist.
|
|
78
|
+
*
|
|
79
|
+
* @param root project root
|
|
80
|
+
* @param manifestPath absolute path to `manifest.json` file
|
|
81
|
+
* @param i18nPropertiesPaths paths to `.properties` file`
|
|
82
|
+
* @param newEntries translation entries to write in the `.properties` file
|
|
83
|
+
* @param modelKey i18n model key
|
|
84
|
+
* @param fs optional `mem-fs-editor` instance. If provided, `mem-fs-editor` api is used instead of `fs` of node
|
|
85
|
+
* @returns boolean or exception
|
|
86
|
+
* @description It also update `manifest.json` file if `<modelKey>` entry is missing from `"sap.ui5":{"models": {}}`
|
|
87
|
+
* as
|
|
88
|
+
* ```JSON
|
|
89
|
+
* {
|
|
90
|
+
* "sap.ui5": {
|
|
91
|
+
* "models": {
|
|
92
|
+
* "<modelKey>": {
|
|
93
|
+
* "type": "sap.ui.model.resource.ResourceModel",
|
|
94
|
+
* "uri": "i18n/i18n.properties"
|
|
95
|
+
* }
|
|
96
|
+
* }
|
|
97
|
+
* }
|
|
98
|
+
* }
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
function createUI5I18nEntries(root, manifestPath, i18nPropertiesPaths, newEntries, modelKey, fs) {
|
|
102
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
103
|
+
return createUI5I18nEntriesBase(root, manifestPath, i18nPropertiesPaths, newEntries, modelKey, fs);
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
exports.createUI5I18nEntries = createUI5I18nEntries;
|
|
107
|
+
/**
|
|
108
|
+
* Maintains new translation entries in an existing i18n file or in a new i18n properties file if it does not exist.
|
|
109
|
+
*
|
|
110
|
+
* @param root project root
|
|
111
|
+
* @param manifestPath absolute path to `manifest.json` file
|
|
112
|
+
* @param i18nPropertiesPaths paths to `.properties` file`
|
|
113
|
+
* @param newEntries translation entries to write in the `.properties` file
|
|
114
|
+
* @param fs optional `mem-fs-editor` instance. If provided, `mem-fs-editor` api is used instead of `fs` of node
|
|
115
|
+
* @returns boolean or exception
|
|
116
|
+
* @description It also update `manifest.json` file if `@i18n` entry is missing from `"sap.ui5":{"models": {}}`
|
|
117
|
+
* as
|
|
118
|
+
* ```JSON
|
|
119
|
+
* {
|
|
120
|
+
* "sap.ui5": {
|
|
121
|
+
* "models": {
|
|
122
|
+
* "@i18n": {
|
|
123
|
+
* "type": "sap.ui.model.resource.ResourceModel",
|
|
124
|
+
* "uri": "i18n/i18n.properties"
|
|
125
|
+
* }
|
|
126
|
+
* }
|
|
127
|
+
* }
|
|
128
|
+
* }
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
function createAnnotationI18nEntries(root, manifestPath, i18nPropertiesPaths, newEntries, fs) {
|
|
132
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
133
|
+
return createUI5I18nEntriesBase(root, manifestPath, i18nPropertiesPaths, newEntries, '@i18n', fs);
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
exports.createAnnotationI18nEntries = createAnnotationI18nEntries;
|
|
137
|
+
/**
|
|
138
|
+
* Maintains new translation entries in an existing i18n file or in a new i18n properties file if it does not exist.
|
|
139
|
+
*
|
|
140
|
+
* @param root project root
|
|
141
|
+
* @param i18nPropertiesPaths paths to `.properties` file`
|
|
142
|
+
* @param newEntries translation entries to write in the `.properties` file
|
|
143
|
+
* @param fs optional `mem-fs-editor` instance. If provided, `mem-fs-editor` api is used instead of `fs` of node
|
|
144
|
+
* @returns boolean or exception
|
|
145
|
+
* @description If `i18n` entry is missing from `"sap.app":{}`, default `i18n/i18n.properties` is used. Update of `manifest.json` file is not needed.
|
|
146
|
+
*/
|
|
147
|
+
function createManifestI18nEntries(root, i18nPropertiesPaths, newEntries, fs) {
|
|
148
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
149
|
+
const i18nFilePath = i18nPropertiesPaths['sap.app'];
|
|
150
|
+
// make sure i18n folder exists
|
|
151
|
+
const dirPath = (0, path_1.dirname)(i18nFilePath);
|
|
152
|
+
if (!fs) {
|
|
153
|
+
// create directory when mem-fs-editor is not provided. when mem-fs-editor is provided, directory is created on using `.commit()` API
|
|
154
|
+
yield (0, promises_1.mkdir)(dirPath, { recursive: true });
|
|
155
|
+
}
|
|
156
|
+
return (0, i18n_1.createPropertiesI18nEntries)(i18nFilePath, newEntries, root, fs);
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
exports.createManifestI18nEntries = createManifestI18nEntries;
|
|
160
|
+
//# sourceMappingURL=write.js.map
|
package/dist/project/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
export { getCapCustomPaths, getCapModelAndServices, getCapProjectType, getCdsFiles, getCdsRoots, getCdsServices, isCapJavaProject, isCapNodeJsProject, getCapEnvironment, readCapServiceMetadataEdmx } from './cap';
|
|
2
2
|
export { getNodeModulesPath } from './dependencies';
|
|
3
|
-
export { getI18nPropertiesPaths } from './i18n';
|
|
3
|
+
export { getCapI18nFolderNames, getI18nPropertiesPaths } from './i18n';
|
|
4
4
|
export { getAppProgrammingLanguage, getAppType, getProject, getProjectType } from './info';
|
|
5
5
|
export { loadModuleFromProject } from './module-loader';
|
|
6
6
|
export { findAllApps, findCapProjects, findFioriArtifacts, findProjectRoot, getAppRootFromWebappPath } from './search';
|
|
7
7
|
export { getWebappPath, readUi5Yaml } from './ui5-config';
|
|
8
8
|
export { getMtaPath } from './mta';
|
|
9
|
+
export { createApplicationAccess, createProjectAccess } from './access';
|
|
9
10
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/project/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getMtaPath = exports.readUi5Yaml = exports.getWebappPath = exports.getAppRootFromWebappPath = exports.findProjectRoot = exports.findFioriArtifacts = exports.findCapProjects = exports.findAllApps = exports.loadModuleFromProject = exports.getProjectType = exports.getProject = exports.getAppType = exports.getAppProgrammingLanguage = exports.getI18nPropertiesPaths = exports.getNodeModulesPath = exports.readCapServiceMetadataEdmx = exports.getCapEnvironment = exports.isCapNodeJsProject = exports.isCapJavaProject = exports.getCdsServices = exports.getCdsRoots = exports.getCdsFiles = exports.getCapProjectType = exports.getCapModelAndServices = exports.getCapCustomPaths = void 0;
|
|
3
|
+
exports.createProjectAccess = exports.createApplicationAccess = exports.getMtaPath = exports.readUi5Yaml = exports.getWebappPath = exports.getAppRootFromWebappPath = exports.findProjectRoot = exports.findFioriArtifacts = exports.findCapProjects = exports.findAllApps = exports.loadModuleFromProject = exports.getProjectType = exports.getProject = exports.getAppType = exports.getAppProgrammingLanguage = exports.getI18nPropertiesPaths = exports.getCapI18nFolderNames = exports.getNodeModulesPath = exports.readCapServiceMetadataEdmx = exports.getCapEnvironment = exports.isCapNodeJsProject = exports.isCapJavaProject = exports.getCdsServices = exports.getCdsRoots = exports.getCdsFiles = exports.getCapProjectType = exports.getCapModelAndServices = exports.getCapCustomPaths = void 0;
|
|
4
4
|
var cap_1 = require("./cap");
|
|
5
5
|
Object.defineProperty(exports, "getCapCustomPaths", { enumerable: true, get: function () { return cap_1.getCapCustomPaths; } });
|
|
6
6
|
Object.defineProperty(exports, "getCapModelAndServices", { enumerable: true, get: function () { return cap_1.getCapModelAndServices; } });
|
|
@@ -15,6 +15,7 @@ Object.defineProperty(exports, "readCapServiceMetadataEdmx", { enumerable: true,
|
|
|
15
15
|
var dependencies_1 = require("./dependencies");
|
|
16
16
|
Object.defineProperty(exports, "getNodeModulesPath", { enumerable: true, get: function () { return dependencies_1.getNodeModulesPath; } });
|
|
17
17
|
var i18n_1 = require("./i18n");
|
|
18
|
+
Object.defineProperty(exports, "getCapI18nFolderNames", { enumerable: true, get: function () { return i18n_1.getCapI18nFolderNames; } });
|
|
18
19
|
Object.defineProperty(exports, "getI18nPropertiesPaths", { enumerable: true, get: function () { return i18n_1.getI18nPropertiesPaths; } });
|
|
19
20
|
var info_1 = require("./info");
|
|
20
21
|
Object.defineProperty(exports, "getAppProgrammingLanguage", { enumerable: true, get: function () { return info_1.getAppProgrammingLanguage; } });
|
|
@@ -34,4 +35,7 @@ Object.defineProperty(exports, "getWebappPath", { enumerable: true, get: functio
|
|
|
34
35
|
Object.defineProperty(exports, "readUi5Yaml", { enumerable: true, get: function () { return ui5_config_1.readUi5Yaml; } });
|
|
35
36
|
var mta_1 = require("./mta");
|
|
36
37
|
Object.defineProperty(exports, "getMtaPath", { enumerable: true, get: function () { return mta_1.getMtaPath; } });
|
|
38
|
+
var access_1 = require("./access");
|
|
39
|
+
Object.defineProperty(exports, "createApplicationAccess", { enumerable: true, get: function () { return access_1.createApplicationAccess; } });
|
|
40
|
+
Object.defineProperty(exports, "createProjectAccess", { enumerable: true, get: function () { return access_1.createProjectAccess; } });
|
|
37
41
|
//# sourceMappingURL=index.js.map
|
|
@@ -49,14 +49,13 @@ const dependencies_1 = require("./dependencies");
|
|
|
49
49
|
*/
|
|
50
50
|
function loadModuleFromProject(projectRoot, moduleName) {
|
|
51
51
|
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
-
var _a;
|
|
53
52
|
let module;
|
|
54
53
|
try {
|
|
55
54
|
if (!(0, dependencies_1.getNodeModulesPath)(projectRoot, moduleName)) {
|
|
56
55
|
throw Error('Path to module not found.');
|
|
57
56
|
}
|
|
58
57
|
const modulePath = require.resolve(moduleName, { paths: [projectRoot] });
|
|
59
|
-
module = (yield
|
|
58
|
+
module = (yield Promise.resolve(`${modulePath}`).then(s => __importStar(require(s))));
|
|
60
59
|
}
|
|
61
60
|
catch (error) {
|
|
62
61
|
throw Error(`Module '${moduleName}' not installed in project '${projectRoot}'.\n${error.toString()}`);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { I18nBundles } from '../i18n';
|
|
2
|
+
import type { NewI18nEntry } from '@sap-ux/i18n';
|
|
3
|
+
import type { ApplicationStructure, I18nPropertiesPaths, Project, ProjectType } from '../info';
|
|
4
|
+
interface BaseAccess {
|
|
5
|
+
readonly project: Project;
|
|
6
|
+
readonly root: string;
|
|
7
|
+
readonly projectType: ProjectType;
|
|
8
|
+
}
|
|
9
|
+
export interface ApplicationAccess extends BaseAccess {
|
|
10
|
+
readonly app: ApplicationStructure;
|
|
11
|
+
createAnnotationI18nEntries(newEntries: NewI18nEntry[]): Promise<boolean>;
|
|
12
|
+
createUI5I18nEntries(newEntries: NewI18nEntry[], modelKey?: string): Promise<boolean>;
|
|
13
|
+
createManifestI18nEntries(newEntries: NewI18nEntry[]): Promise<boolean>;
|
|
14
|
+
createCapI18nEntries(filePath: string, newI18nEntries: NewI18nEntry[]): Promise<boolean>;
|
|
15
|
+
getAppId(): string;
|
|
16
|
+
getAppRoot(): string;
|
|
17
|
+
getI18nBundles(): Promise<I18nBundles>;
|
|
18
|
+
getI18nPropertiesPaths(): Promise<I18nPropertiesPaths>;
|
|
19
|
+
}
|
|
20
|
+
export interface ProjectAccess extends BaseAccess {
|
|
21
|
+
getApplicationIds: () => string[];
|
|
22
|
+
getApplication: (appId: string) => ApplicationAccess;
|
|
23
|
+
}
|
|
24
|
+
export {};
|
|
25
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { I18nBundle } from '@sap-ux/i18n';
|
|
2
|
+
export interface I18nBundles {
|
|
3
|
+
/**
|
|
4
|
+
* i18n bundle for `i18n` of `"sap.app"` namespace in `manifest.json` file
|
|
5
|
+
*/
|
|
6
|
+
'sap.app': I18nBundle;
|
|
7
|
+
/**
|
|
8
|
+
* i18n bundle for `models` entry of `sap.ui5` namespace in `manifest.json` file with type `sap.ui.model.resource.ResourceModel`
|
|
9
|
+
*/
|
|
10
|
+
models: {
|
|
11
|
+
[modelKey: string]: I18nBundle;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* i18n bundle for cap services
|
|
15
|
+
*/
|
|
16
|
+
service: I18nBundle;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/types/index.d.ts
CHANGED
package/dist/types/index.js
CHANGED
|
@@ -14,7 +14,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./access"), exports);
|
|
17
18
|
__exportStar(require("./cap"), exports);
|
|
19
|
+
__exportStar(require("./i18n"), exports);
|
|
18
20
|
__exportStar(require("./find"), exports);
|
|
19
21
|
__exportStar(require("./info"), exports);
|
|
20
22
|
__exportStar(require("./package"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sap-ux/project-access",
|
|
3
|
-
"version": "1.17.
|
|
3
|
+
"version": "1.17.2",
|
|
4
4
|
"description": "Library to access SAP Fiori tools projects",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -27,6 +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/i18n": "0.0.3",
|
|
30
31
|
"@sap-ux/ui5-config": "0.21.0"
|
|
31
32
|
},
|
|
32
33
|
"devDependencies": {
|
|
@@ -34,7 +35,7 @@
|
|
|
34
35
|
"@types/mem-fs-editor": "7.0.1",
|
|
35
36
|
"@ui5/manifest": "1.61.0",
|
|
36
37
|
"vscode-uri": "3.0.7",
|
|
37
|
-
"@sap-ux/logger": "0.
|
|
38
|
+
"@sap-ux/logger": "0.5.0"
|
|
38
39
|
},
|
|
39
40
|
"scripts": {
|
|
40
41
|
"build": "tsc --build",
|