Skip to content

Commit 24a1b3d

Browse files
authored
Merge pull request #21 from cap-js/build-plugin
copy types file during build
2 parents bbad0f9 + beaf837 commit 24a1b3d

File tree

4 files changed

+31
-4
lines changed

4 files changed

+31
-4
lines changed

cds-plugin.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
const cds = require("@sap/cds");
2+
const build = require('@sap/cds-dk/lib/build')
23
const { validateNotificationTypes, readFile } = require("./lib/utils");
34
const { createNotificationTypesMap } = require("./lib/notificationTypes");
45
const { setGlobalLogLevel } = require("@sap-cloud-sdk/util");
56

7+
// register build plugin
8+
build.register('notifications', { impl: '@cap-js/notifications/lib/build', description: 'Notifications build plugin', taskDefaults: { src: cds.env.folders.srv } });
9+
610
cds.once("served", async () => {
711
setGlobalLogLevel("error");
812
const profiles = cds.env.profiles ?? [];
@@ -17,4 +21,4 @@ cds.once("served", async () => {
1721
cds.notifications = { local: { types: notificationTypesMap } };
1822
}
1923
}
20-
});
24+
});

lib/build.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const cds = require('@sap/cds')
2+
const { BuildPlugin } = require('@sap/cds-dk/lib/build')
3+
4+
const { copy, exists, path } = cds.utils
5+
6+
module.exports = class NotificationsBuildPlugin extends BuildPlugin {
7+
8+
static hasTask() {
9+
const notificationTypesFile = cds.env.requires?.notifications?.types;
10+
return notificationTypesFile === undefined ? false : exists(notificationTypesFile);
11+
}
12+
13+
async build() {
14+
if(exists(cds.env.requires.notifications.types)) {
15+
const fileName = path.basename(cds.env.requires.notifications.types);
16+
await copy(cds.env.requires.notifications.types).to(path.join(this.task.dest, fileName));
17+
}
18+
}
19+
}

lib/content-deployment.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@ const cds = require("@sap/cds");
22
const { validateNotificationTypes, readFile } = require("./utils");
33
const { processNotificationTypes } = require("./notificationTypes");
44
const { setGlobalLogLevel } = require("@sap-cloud-sdk/util");
5+
const { basename } = require('path');
56

67
async function deployNotificationTypes() {
78
setGlobalLogLevel("error");
89

910
// read notification types
10-
const notificationTypes = readFile(cds.env?.requires?.notifications?.types);
11+
const filePath = cds.env.requires?.notifications?.types ?? '';
12+
const fileName = basename(filePath);
13+
const notificationTypes = readFile(fileName);
1114

1215
if (validateNotificationTypes(notificationTypes)) {
1316
await processNotificationTypes(notificationTypes);
@@ -18,4 +21,4 @@ deployNotificationTypes();
1821

1922
module.exports = {
2023
deployNotificationTypes
21-
}
24+
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"@sap-cloud-sdk/connectivity": "3.5.0",
1616
"@sap-cloud-sdk/http-client": "3.5.0",
1717
"@sap-cloud-sdk/util": "3.5.0",
18-
"@sap/cds": ">=7",
18+
"@sap/cds": "7.3.0",
19+
"@sap/cds-dk": "7.3.1",
1920
"lodash": "4.17.21"
2021
},
2122
"devDependencies": {

0 commit comments

Comments
 (0)