Skip to content

Commit 6a2982a

Browse files
committed
Plugins
1 parent 52bba90 commit 6a2982a

File tree

9 files changed

+93
-85
lines changed

9 files changed

+93
-85
lines changed

.cdsrc.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"use strict";
2+
3+
const config = require("./config.json");
4+
const { merge } = require("./src/util/helper");
5+
6+
module.exports = {
7+
cds: merge(
8+
...[...config.plugins, config.paths.base].map((module) => {
9+
return require(`${module}/package.json`).cds;
10+
}),
11+
),
12+
};

bin/commands/init.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,6 @@ Examples:
189189
json.websockets = { enabled: true };
190190
});
191191

192-
// Install @cap-js-community packages
193-
shelljs.exec(
194-
`npm install --save @cap-js-community/event-queue @cap-js-community/websocket @cap-js-community/feature-toggle-library`,
195-
{ silent: true },
196-
);
197-
198192
return true;
199193
} catch (err) {
200194
console.error("Project initialization failed: ", err.message);

bin/features/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
const fs = require("fs");
55
const path = require("path");
66

7-
const config = require("../config");
7+
const config = require("../config.json");
88

99
module.exports = () => {
1010
try {

cds-plugin.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,14 @@ const { StatusCodes, getReasonPhrase } = require("http-status-codes");
1212
const toggles = require("@cap-js-community/feature-toggle-library");
1313
const { config: eventQueueConfig } = require("@cap-js-community/event-queue");
1414

15-
const { mergeDeep, toObject } = require("./src/util/helper");
15+
const { merge, toObject } = require("./src/util/helper");
1616

17-
const config = mergeDeep(require("./config"), cds.env.requires?.["sap-afc-sdk"]?.config ?? {});
17+
const config = merge(require("./config.json"), cds.env.requires?.["sap-afc-sdk"]?.config ?? {});
18+
19+
// Plugins
20+
for (const plugin of config.plugins) {
21+
require(`${plugin}/cds-plugin`);
22+
}
1823

1924
const SERVER_SUFFIX = "srv";
2025
const APPROUTER_SUFFIX = "approuter";
@@ -139,7 +144,7 @@ function serveBroker() {
139144
let brokerConfig = toObject(cds.env.requires?.["sap-afc-sdk"]?.broker);
140145
const brokerPath = path.join(cds.root, config.paths.broker);
141146
try {
142-
brokerConfig = mergeDeep(require(brokerPath), brokerConfig);
147+
brokerConfig = merge(require(brokerPath), brokerConfig);
143148
} catch (err) {
144149
if (Object.keys(brokerConfig).length === 0) {
145150
cds.log("/broker").info(`broker.json not found at '${brokerPath}'. Call 'afc add broker'`);
@@ -260,7 +265,7 @@ function serveMergedAppConfig(packageRoot, uiPath) {
260265
inbound.resolutionResult.url = `${uiPath}/${inbound.resolutionResult.url}`;
261266
}
262267
}
263-
const mergedFioriSandboxConfig = mergeDeep(packageFioriSandboxConfig, projectFioriSandboxConfig);
268+
const mergedFioriSandboxConfig = merge(packageFioriSandboxConfig, projectFioriSandboxConfig);
264269
res.send(mergedFioriSandboxConfig);
265270
});
266271
}
@@ -414,7 +419,7 @@ function outboxServices() {
414419
}
415420

416421
function handleFeatureToggles() {
417-
// event-queue
422+
// Event-Queue
418423
for (const name in config.toggles.eventQueue) {
419424
const toggle = config.toggles.eventQueue[name];
420425
eventQueueConfig[name] = toggles.getFeatureValue(toggle);

config.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"paths": {
3+
"base": "./",
34
"broker": "./srv/broker.json",
45
"catalog": "./srv/catalog.json",
56
"launchpad": "launchpad.html",
@@ -27,5 +28,10 @@
2728
},
2829
"endpoints": {
2930
"authentication": "https://authentication.sap.hana.ondemand.com"
30-
}
31+
},
32+
"plugins": [
33+
"@cap-js-community/event-queue",
34+
"@cap-js-community/feature-toggle-library",
35+
"@cap-js-community/websocket"
36+
]
3137
}

0 commit comments

Comments
 (0)