From df8ebb3550d6e3ddb9a47ea420114c0d0a018261 Mon Sep 17 00:00:00 2001 From: Daniel Hutzel Date: Fri, 15 Dec 2023 10:13:07 +0100 Subject: [PATCH] Streamlined boostrapping --- cds-plugin.js | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/cds-plugin.js b/cds-plugin.js index d247fed..1580b8f 100644 --- a/cds-plugin.js +++ b/cds-plugin.js @@ -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 } }; } } -}); \ No newline at end of file + + require("@sap-cloud-sdk/util").setGlobalLogLevel("error") +})