Skip to content

Commit b1fb6c3

Browse files
Deploy Notification Types within a CF Task (#14)
* Deploy Notification Types within a CF Task * Fix comments * remove not needed dev dependency
1 parent cd22abf commit b1fb6c3

File tree

5 files changed

+30
-8
lines changed

5 files changed

+30
-8
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ yarn-debug.log*
66
yarn-error.log*
77
lerna-debug.log*
88
.pnpm-debug.log*
9+
package-lock.json
910

1011
# Diagnostic reports (https://nodejs.org/api/report.html)
1112
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

.prettierrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"tabWidth": 2,
3+
"useTabs": false,
4+
"printWidth": 150
5+
}

cds-plugin.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
const cds = require("@sap/cds");
22
const { validateNotificationTypes, readFile } = require("./lib/utils");
3-
const { createNotificationTypesMap, processNotificationTypes} = require("./lib/notificationTypes");
3+
const { createNotificationTypesMap } = require("./lib/notificationTypes");
44
const { setGlobalLogLevel } = require("@sap-cloud-sdk/util");
55

66
cds.once("served", async () => {
77
setGlobalLogLevel("error");
88
const profiles = cds.env.profiles ?? [];
9-
const production = profiles.includes('production');
9+
const production = profiles.includes("production");
1010

1111
// read notification types
1212
const notificationTypes = readFile(cds.env.requires?.notifications?.types);
1313

14-
if(validateNotificationTypes(notificationTypes)) {
15-
if (production) {
16-
await processNotificationTypes(notificationTypes);
17-
} else {
14+
if (validateNotificationTypes(notificationTypes)) {
15+
if (!production) {
1816
const notificationTypesMap = createNotificationTypesMap(notificationTypes, true);
19-
cds.notifications = { local: { types: notificationTypesMap }};
17+
cds.notifications = { local: { types: notificationTypesMap } };
2018
}
2119
}
2220
});

lib/content-deployment.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const cds = require("@sap/cds");
2+
const { validateNotificationTypes, readFile } = require("./utils");
3+
const { createNotificationTypesMap, processNotificationTypes } = require("./notificationTypes");
4+
const { setGlobalLogLevel } = require("@sap-cloud-sdk/util");
5+
6+
async function deployNotificationTypes() {
7+
setGlobalLogLevel("error");
8+
9+
// read notification types
10+
const notificationTypes = readFile(cds.env.requires?.notifications?.types);
11+
12+
if (validateNotificationTypes(notificationTypes)) {
13+
await processNotificationTypes(notificationTypes);
14+
}
15+
}
16+
17+
deployNotificationTypes();

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
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",
1819
"lodash": "4.17.21"
1920
},
2021
"devDependencies": {
@@ -46,4 +47,4 @@
4647
}
4748
}
4849
}
49-
}
50+
}

0 commit comments

Comments
 (0)