@sap-ux/odata-service-writer 0.24.0 → 0.24.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -1
- package/dist/updates.d.ts +1 -1
- package/dist/updates.js +59 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -219,7 +219,7 @@ async function generate(basePath, service, fs) {
|
|
|
219
219
|
// Prepare template folder for manifest and xml updates
|
|
220
220
|
const templateRoot = (0, path_1.join)(__dirname, '../templates');
|
|
221
221
|
// Update manifest.json
|
|
222
|
-
(0, updates_1.updateManifest)(basePath, service, fs, templateRoot);
|
|
222
|
+
await (0, updates_1.updateManifest)(basePath, service, fs, templateRoot);
|
|
223
223
|
// Dont extend backend and mockserver middlewares if service type is CDS
|
|
224
224
|
if (isServiceTypeEdmx) {
|
|
225
225
|
await writeEDMXServiceFiles(fs, basePath, paths, templateRoot, service);
|
package/dist/updates.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ import type { OdataService, CdsAnnotationsInfo, EdmxAnnotationsInfo } from './ty
|
|
|
8
8
|
* @param fs - the memfs editor instance
|
|
9
9
|
* @param templateRoot - root folder contain the ejs templates
|
|
10
10
|
*/
|
|
11
|
-
export declare function updateManifest(basePath: string, service: OdataService, fs: Editor, templateRoot: string): void
|
|
11
|
+
export declare function updateManifest(basePath: string, service: OdataService, fs: Editor, templateRoot: string): Promise<void>;
|
|
12
12
|
/**
|
|
13
13
|
* Writes annotation XML files for EDMX service annotations.
|
|
14
14
|
*
|
package/dist/updates.js
CHANGED
|
@@ -13,6 +13,58 @@ const i18n_1 = require("./i18n");
|
|
|
13
13
|
const semver_1 = __importDefault(require("semver"));
|
|
14
14
|
const prettify_xml_1 = __importDefault(require("prettify-xml"));
|
|
15
15
|
const project_access_1 = require("@sap-ux/project-access");
|
|
16
|
+
/**
|
|
17
|
+
* Modifies service in manifest.json and service files in a way that is supported by multiple services.
|
|
18
|
+
* If service files are defined in 'localService' folder then those files are moved to respective service folder and service configuration URI are modified in manifest.json.
|
|
19
|
+
*
|
|
20
|
+
* @param {string} webappPath - the webapp path of an existing UI5 application
|
|
21
|
+
* @param {string} dataSourceKey - dataSource key in manifest.json
|
|
22
|
+
* @param {Manifest} dataSource - dataSource configuration from manifest.json
|
|
23
|
+
* @param {Editor} fs - the memfs editor instance
|
|
24
|
+
*/
|
|
25
|
+
function updateExistingService(webappPath, dataSourceKey, dataSource, fs) {
|
|
26
|
+
const settings = dataSource.settings;
|
|
27
|
+
if (settings) {
|
|
28
|
+
// "localService/metadata.xml"
|
|
29
|
+
const localUri = settings.localUri;
|
|
30
|
+
// -> ["localService", "metadata.xml"]
|
|
31
|
+
const localUriParts = localUri ? localUri.split('/') : undefined;
|
|
32
|
+
if (localUriParts && localUriParts[0] === project_access_1.DirName.LocalService && localUriParts.length === 2) {
|
|
33
|
+
const localFileName = localUriParts[localUriParts.length - 1];
|
|
34
|
+
settings.localUri = `${project_access_1.DirName.LocalService}/${dataSourceKey}/${localFileName}`;
|
|
35
|
+
// move related files to service folder
|
|
36
|
+
const fromFilePath = (0, path_1.join)(webappPath, localUriParts.join(path_1.sep));
|
|
37
|
+
const toFilePath = (0, path_1.join)(webappPath, project_access_1.DirName.LocalService, dataSourceKey, localFileName);
|
|
38
|
+
if (fs.exists(fromFilePath)) {
|
|
39
|
+
fs.move(fromFilePath, toFilePath);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Modifies services in manifest.json and services files in a way that is supported by multiple services.
|
|
46
|
+
*
|
|
47
|
+
* @param {string} webappPath - the webapp path of an existing UI5 application
|
|
48
|
+
* @param {Manifest} manifest - the manifest.json of the application
|
|
49
|
+
* @param {Editor} fs - the memfs editor instance
|
|
50
|
+
*/
|
|
51
|
+
async function updateExistingServices(webappPath, manifest, fs) {
|
|
52
|
+
const dataSources = manifest?.['sap.app']?.dataSources;
|
|
53
|
+
for (const dataSourceKey in dataSources) {
|
|
54
|
+
const dataSource = dataSources[dataSourceKey];
|
|
55
|
+
if (dataSource.type === 'OData') {
|
|
56
|
+
updateExistingService(webappPath, dataSourceKey, dataSource, fs);
|
|
57
|
+
const annotations = dataSource.settings?.annotations;
|
|
58
|
+
if (annotations) {
|
|
59
|
+
annotations.forEach((annotationName) => {
|
|
60
|
+
const annotationDataSource = dataSources[annotationName];
|
|
61
|
+
updateExistingService(webappPath, dataSourceKey, annotationDataSource, fs);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
fs.writeJSON((0, path_1.join)(webappPath, 'manifest.json'), manifest);
|
|
67
|
+
}
|
|
16
68
|
/**
|
|
17
69
|
* Internal function that updates the manifest.json based on the given service configuration.
|
|
18
70
|
*
|
|
@@ -21,18 +73,22 @@ const project_access_1 = require("@sap-ux/project-access");
|
|
|
21
73
|
* @param fs - the memfs editor instance
|
|
22
74
|
* @param templateRoot - root folder contain the ejs templates
|
|
23
75
|
*/
|
|
24
|
-
function updateManifest(basePath, service, fs, templateRoot) {
|
|
25
|
-
const
|
|
76
|
+
async function updateManifest(basePath, service, fs, templateRoot) {
|
|
77
|
+
const webappPath = await (0, project_access_1.getWebappPath)(basePath, fs);
|
|
78
|
+
const manifestPath = (0, path_1.join)(webappPath, 'manifest.json');
|
|
26
79
|
// Get component app id
|
|
27
80
|
const manifest = fs.readJSON(manifestPath);
|
|
28
81
|
const appProp = 'sap.app';
|
|
29
82
|
const appid = manifest?.[appProp]?.id;
|
|
83
|
+
// Check and update existing services
|
|
84
|
+
await updateExistingServices(webappPath, manifest, fs);
|
|
85
|
+
const modifiedManifest = fs.readJSON(manifestPath);
|
|
30
86
|
// Throw if required property is not found manifest.json
|
|
31
87
|
if (!appid) {
|
|
32
88
|
throw new Error((0, i18n_1.t)('error.requiredProjectPropertyNotFound', { property: `'${appProp}'.id`, path: manifestPath }));
|
|
33
89
|
}
|
|
34
90
|
const manifestJsonExt = fs.read((0, path_1.join)(templateRoot, 'extend', `manifest.json`));
|
|
35
|
-
const manifestSettings = Object.assign(service, getModelSettings((0, project_access_1.getMinimumUI5Version)(
|
|
91
|
+
const manifestSettings = Object.assign(service, getModelSettings((0, project_access_1.getMinimumUI5Version)(modifiedManifest)));
|
|
36
92
|
// If the service object includes ejs options, for example 'client' (see: https://ejs.co/#docs),
|
|
37
93
|
// resulting in unexpected behaviour and problems when webpacking. Passing an empty options object prevents this.
|
|
38
94
|
fs.extendJSON(manifestPath, JSON.parse((0, ejs_1.render)(manifestJsonExt, manifestSettings, {})));
|
package/package.json
CHANGED