@sap-ux/project-access 1.16.3 → 1.17.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.
@@ -13,4 +13,7 @@ export declare const FileName: {
13
13
  readonly Ui5MockYaml: "ui5-mock.yaml";
14
14
  readonly UI5DeployYaml: "ui5-deploy.yaml";
15
15
  };
16
+ export declare const DirName: {
17
+ readonly Changes: "changes";
18
+ };
16
19
  //# sourceMappingURL=constants.d.ts.map
package/dist/constants.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FileName = void 0;
3
+ exports.DirName = exports.FileName = void 0;
4
4
  exports.FileName = {
5
5
  AdaptationConfig: 'config.json',
6
6
  CapJavaApplicationYaml: 'application.yaml',
@@ -16,4 +16,7 @@ exports.FileName = {
16
16
  Ui5MockYaml: 'ui5-mock.yaml',
17
17
  UI5DeployYaml: 'ui5-deploy.yaml'
18
18
  };
19
+ exports.DirName = {
20
+ Changes: 'changes'
21
+ };
19
22
  //# sourceMappingURL=constants.js.map
@@ -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
  *
@@ -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
  *
@@ -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
@@ -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
- export { findAllApps, findCapProjects, findFioriArtifacts, findProjectRoot, getAppRootFromWebappPath, getAppProgrammingLanguage, getAppType, getCapCustomPaths, getCapEnvironment, getCapModelAndServices, getCapProjectType, getCdsFiles, getCdsRoots, getCdsServices, getMtaPath, getNodeModulesPath, getProjectType, getWebappPath, isCapJavaProject, isCapNodeJsProject, loadModuleFromProject, readCapServiceMetadataEdmx, readUi5Yaml } from './project';
3
2
  export { getFilePaths } from './file';
3
+ export { createApplicationAccess, createProjectAccess, findAllApps, findCapProjects, findFioriArtifacts, findProjectRoot, getAppRootFromWebappPath, getAppProgrammingLanguage, getAppType, getCapCustomPaths, getCapEnvironment, getCapModelAndServices, getCapProjectType, getCdsFiles, getCdsRoots, getCdsServices, getCapI18nFolderNames, 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,10 +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.getFilePaths = exports.readUi5Yaml = exports.readCapServiceMetadataEdmx = exports.loadModuleFromProject = exports.isCapNodeJsProject = exports.isCapJavaProject = exports.getWebappPath = exports.getProjectType = exports.getNodeModulesPath = exports.getMtaPath = 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.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.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
+ var file_1 = require("./file");
21
+ Object.defineProperty(exports, "getFilePaths", { enumerable: true, get: function () { return file_1.getFilePaths; } });
20
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; } });
21
25
  Object.defineProperty(exports, "findAllApps", { enumerable: true, get: function () { return project_1.findAllApps; } });
22
26
  Object.defineProperty(exports, "findCapProjects", { enumerable: true, get: function () { return project_1.findCapProjects; } });
23
27
  Object.defineProperty(exports, "findFioriArtifacts", { enumerable: true, get: function () { return project_1.findFioriArtifacts; } });
@@ -32,8 +36,10 @@ Object.defineProperty(exports, "getCapProjectType", { enumerable: true, get: fun
32
36
  Object.defineProperty(exports, "getCdsFiles", { enumerable: true, get: function () { return project_1.getCdsFiles; } });
33
37
  Object.defineProperty(exports, "getCdsRoots", { enumerable: true, get: function () { return project_1.getCdsRoots; } });
34
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; } });
35
40
  Object.defineProperty(exports, "getMtaPath", { enumerable: true, get: function () { return project_1.getMtaPath; } });
36
41
  Object.defineProperty(exports, "getNodeModulesPath", { enumerable: true, get: function () { return project_1.getNodeModulesPath; } });
42
+ Object.defineProperty(exports, "getProject", { enumerable: true, get: function () { return project_1.getProject; } });
37
43
  Object.defineProperty(exports, "getProjectType", { enumerable: true, get: function () { return project_1.getProjectType; } });
38
44
  Object.defineProperty(exports, "getWebappPath", { enumerable: true, get: function () { return project_1.getWebappPath; } });
39
45
  Object.defineProperty(exports, "isCapJavaProject", { enumerable: true, get: function () { return project_1.isCapJavaProject; } });
@@ -41,7 +47,5 @@ Object.defineProperty(exports, "isCapNodeJsProject", { enumerable: true, get: fu
41
47
  Object.defineProperty(exports, "loadModuleFromProject", { enumerable: true, get: function () { return project_1.loadModuleFromProject; } });
42
48
  Object.defineProperty(exports, "readCapServiceMetadataEdmx", { enumerable: true, get: function () { return project_1.readCapServiceMetadataEdmx; } });
43
49
  Object.defineProperty(exports, "readUi5Yaml", { enumerable: true, get: function () { return project_1.readUi5Yaml; } });
44
- var file_1 = require("./file");
45
- Object.defineProperty(exports, "getFilePaths", { enumerable: true, get: function () { return file_1.getFilePaths; } });
46
50
  __exportStar(require("./types"), exports);
47
51
  //# sourceMappingURL=index.js.map
@@ -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
@@ -0,0 +1,18 @@
1
+ import type { I18nPropertiesPaths, Manifest } from '../../types';
2
+ /**
3
+ * Return absolute paths to i18n.properties files from manifest.
4
+ *
5
+ * @param manifestPath - path to manifest.json; used to parse manifest.json if not provided as second argument and to resolve absolute paths
6
+ * @param manifest - optionally, parsed content of manifest.json, pass to avoid reading it again.
7
+ * @returns - absolute paths to i18n.properties
8
+ */
9
+ export declare function getI18nPropertiesPaths(manifestPath: string, manifest?: Manifest): Promise<I18nPropertiesPaths>;
10
+ /**
11
+ * Return paths to i18n.properties files from manifest,
12
+ * relative to the manifest.json.
13
+ *
14
+ * @param manifest - parsed content of manifest.json
15
+ * @returns - paths to i18n.properties files from sap.app and models
16
+ */
17
+ export declare function getRelativeI18nPropertiesPaths(manifest: Manifest): I18nPropertiesPaths;
18
+ //# sourceMappingURL=i18n.d.ts.map
@@ -0,0 +1,127 @@
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.getRelativeI18nPropertiesPaths = exports.getI18nPropertiesPaths = void 0;
13
+ const path_1 = require("path");
14
+ const file_1 = require("../../file");
15
+ /**
16
+ * Return absolute paths to i18n.properties files from manifest.
17
+ *
18
+ * @param manifestPath - path to manifest.json; used to parse manifest.json if not provided as second argument and to resolve absolute paths
19
+ * @param manifest - optionally, parsed content of manifest.json, pass to avoid reading it again.
20
+ * @returns - absolute paths to i18n.properties
21
+ */
22
+ function getI18nPropertiesPaths(manifestPath, manifest) {
23
+ return __awaiter(this, void 0, void 0, function* () {
24
+ const parsedManifest = manifest !== null && manifest !== void 0 ? manifest : (yield (0, file_1.readJSON)(manifestPath));
25
+ const manifestFolder = (0, path_1.dirname)(manifestPath);
26
+ const relativeI18nPropertiesPaths = getRelativeI18nPropertiesPaths(parsedManifest);
27
+ const i18nPropertiesPaths = {
28
+ 'sap.app': (0, path_1.join)(manifestFolder, relativeI18nPropertiesPaths['sap.app']),
29
+ models: {}
30
+ };
31
+ for (const modelKey in relativeI18nPropertiesPaths.models) {
32
+ i18nPropertiesPaths.models[modelKey] = {
33
+ path: (0, path_1.join)(manifestFolder, relativeI18nPropertiesPaths.models[modelKey].path)
34
+ };
35
+ }
36
+ return i18nPropertiesPaths;
37
+ });
38
+ }
39
+ exports.getI18nPropertiesPaths = getI18nPropertiesPaths;
40
+ /**
41
+ * Return paths to i18n.properties files from manifest,
42
+ * relative to the manifest.json.
43
+ *
44
+ * @param manifest - parsed content of manifest.json
45
+ * @returns - paths to i18n.properties files from sap.app and models
46
+ */
47
+ function getRelativeI18nPropertiesPaths(manifest) {
48
+ return {
49
+ 'sap.app': getI18nAppPath(manifest),
50
+ models: getI18nModelPaths(manifest)
51
+ };
52
+ }
53
+ exports.getRelativeI18nPropertiesPaths = getRelativeI18nPropertiesPaths;
54
+ /**
55
+ * Get the i18n path from sap.app.i18n part of the manifest.
56
+ *
57
+ * 1. from `sap.app.i18n` if `i18n` is string
58
+ * 2. from `sap.app.bundleName` as `bundleName` wins over `bundleUrl`
59
+ * 3. from `sap.app.bundleUrl`
60
+ * 4. default which is `'i18n/i18n.properties'`
61
+ *
62
+ * @param manifest - parsed content of manifest.json
63
+ * @returns - path to i18n.properties file
64
+ */
65
+ function getI18nAppPath(manifest) {
66
+ var _a, _b;
67
+ const defaultPath = (0, path_1.join)('i18n/i18n.properties');
68
+ if (typeof ((_a = manifest === null || manifest === void 0 ? void 0 : manifest['sap.app']) === null || _a === void 0 ? void 0 : _a.i18n) === 'string') {
69
+ return (0, path_1.join)(manifest['sap.app'].i18n);
70
+ }
71
+ if (typeof ((_b = manifest === null || manifest === void 0 ? void 0 : manifest['sap.app']) === null || _b === void 0 ? void 0 : _b.i18n) === 'object') {
72
+ // bundleName wins over `bundleUrl`
73
+ if ('bundleName' in manifest['sap.app'].i18n) {
74
+ // module name is in dot notation
75
+ const withoutAppId = manifest['sap.app'].i18n.bundleName.replace(manifest['sap.app'].id, '');
76
+ const i18nPath = `${(0, path_1.join)(...withoutAppId.split('.'))}.properties`;
77
+ return (0, path_1.join)(i18nPath);
78
+ }
79
+ if ('bundleUrl' in manifest['sap.app'].i18n) {
80
+ return (0, path_1.join)(manifest['sap.app'].i18n.bundleUrl);
81
+ }
82
+ }
83
+ // default
84
+ return defaultPath;
85
+ }
86
+ /**
87
+ * Get the i18n path from UI5 resource models declared in sap.ui5.models part of the manifest.
88
+ * By default the model used for internationalization in the UI is 'i18n'. For
89
+ * internationalization of annotations the model is '@18n'.
90
+ *
91
+ * for For `sap.ui5` namespace
92
+ * 1. from `sap.ui5.models.{resource model key}.bundleName` as `bundleName` wins over `bundleUrl`
93
+ * 2. from `sap.ui5.models.{resource model key}.bundleUrl`
94
+ * 3. from `sap.ui5.models.{resource model key}.uri`
95
+ *
96
+ * @param manifest - parsed content of manifest.json
97
+ * @returns - paths to i18n.properties file from models
98
+ */
99
+ function getI18nModelPaths(manifest) {
100
+ var _a, _b;
101
+ const result = {};
102
+ const models = (_b = (_a = manifest === null || manifest === void 0 ? void 0 : manifest['sap.ui5']) === null || _a === void 0 ? void 0 : _a.models) !== null && _b !== void 0 ? _b : {};
103
+ const resourceModelKeys = Object.keys(models).filter((key) => models[key].type === 'sap.ui.model.resource.ResourceModel');
104
+ for (const modelKey of resourceModelKeys) {
105
+ const i18nModel = models[modelKey];
106
+ // settings wins over `uri`
107
+ if (i18nModel.settings) {
108
+ // bundleName wins over `bundleUrl`
109
+ if (i18nModel.settings.bundleName) {
110
+ // module name is in dot notation
111
+ const withoutAppId = i18nModel.settings.bundleName.replace(manifest['sap.app'].id, '');
112
+ const i18nPath = `${(0, path_1.join)(...withoutAppId.split('.'))}.properties`;
113
+ result[modelKey] = { path: (0, path_1.join)(i18nPath) };
114
+ continue;
115
+ }
116
+ if (i18nModel.settings.bundleUrl) {
117
+ result[modelKey] = { path: (0, path_1.join)(i18nModel.settings.bundleUrl) };
118
+ continue;
119
+ }
120
+ }
121
+ if (i18nModel.uri) {
122
+ result[modelKey] = { path: (0, path_1.join)(i18nModel.uri) };
123
+ }
124
+ }
125
+ return result;
126
+ }
127
+ //# sourceMappingURL=i18n.js.map
@@ -0,0 +1,4 @@
1
+ export { getI18nPropertiesPaths } from './i18n';
2
+ export { getCapI18nFolderNames, getI18nBundles } from './read';
3
+ export { createManifestI18nEntries, createUI5I18nEntries, createAnnotationI18nEntries, createCapI18nEntries } from './write';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createCapI18nEntries = exports.createAnnotationI18nEntries = exports.createUI5I18nEntries = exports.createManifestI18nEntries = exports.getI18nBundles = exports.getCapI18nFolderNames = exports.getI18nPropertiesPaths = void 0;
4
+ var i18n_1 = require("./i18n");
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; } });
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