Skip to content

Commit

Permalink
Streamlined boostrapping
Browse files Browse the repository at this point in the history
  • Loading branch information
danjoa committed Dec 15, 2023
1 parent 25c0f3c commit df8ebb3
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions cds-plugin.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
const cds = require("@sap/cds");
const build = require('@sap/cds-dk/lib/build')
const { validateNotificationTypes, readFile } = require("./lib/utils");
const { createNotificationTypesMap } = require("./lib/notificationTypes");
const { setGlobalLogLevel } = require("@sap-cloud-sdk/util");
const cds = require("@sap/cds/lib");

// register build plugin
build.register('notifications', { impl: '@cap-js/notifications/lib/build', description: 'Notifications build plugin', taskDefaults: { src: cds.env.folders.srv } });
if (cds.cli.command === "build") {
// register build plugin
const build = require('@sap/cds-dk/lib/build')
build.register('notifications', {
impl: '@cap-js/notifications/lib/build',
description: 'Notifications build plugin',
taskDefaults: { src: cds.env.folders.srv }
})
}

cds.once("served", async () => {
setGlobalLogLevel("error");
const profiles = cds.env.profiles ?? [];
const production = profiles.includes("production");
else cds.once("served", async () => {
const { validateNotificationTypes, readFile } = require("./lib/utils");
const { createNotificationTypesMap } = require("./lib/notificationTypes");
const production = cds.env.profiles?.includes("production");

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

if (validateNotificationTypes(notificationTypes)) {
if (!production) {
const notificationTypesMap = createNotificationTypesMap(notificationTypes, true);
cds.notifications = { local: { types: notificationTypesMap } };
}
}
});

require("@sap-cloud-sdk/util").setGlobalLogLevel("error")
})

0 comments on commit df8ebb3

Please sign in to comment.