UNPKG

@sap/cds-dk

Version:

Command line client and development toolkit for the SAP Cloud Application Programming Model

77 lines (66 loc) 2.38 kB
const cds = require('../../../cds') const { read, yaml: YAML } = cds.utils const { readProject } = require('../../projectReader') const { merge } = require('../../merge') const { srv4, enterpriseMessaging } = require('../../registries/mta') module.exports = class EnterpriseMessagingTemplate extends require('../../plugin') { static help() { return 'messaging via SAP Enterprise Messaging' } options() { return { 'cloudevents': { type: 'boolean', short: 'c', help: 'Use CloudEvents formatting.', } } } async canRun() { const { isJava } = readProject() if (isJava) throw `'cds add enterprise-messaging' is not available for Java yet` return true } static hasInProduction(env) { return env.requires?.messaging?.kind === 'enterprise-messaging-http' } async run() { const project = readProject() const { configFile, isNodejs } = project if (isNodejs) { project.cloudevents = cds.cli.options.cloudevents await merge(__dirname, 'files/package.json.hbs').into(configFile, { with: project }) } await merge(__dirname, 'files/event-mesh.json.hbs').into('event-mesh.json', { project }) } async combine() { const project = readProject() const { hasXsuaa, hasHelm, hasHelmUnifiedRuntime, hasMta, srvPath, appName } = project if (hasMta) { const srv = srv4(srvPath) await merge(__dirname, 'files/mta.yaml.hbs').into('mta.yaml', { project, additions: [srv, enterpriseMessaging], relationships: [{ insert: [enterpriseMessaging, 'name'], into: [srv, 'requires', 'name'] }] }) } if (hasXsuaa) { if (hasMta) { project['em-service-name'] = YAML.parse(await read('mta.yaml'))?.resources?.find(r => r?.parameters?.service === 'enterprise-messaging')?.name } else { project['em-service-name'] = `${appName}-messaging` } await merge(__dirname, 'files/xs-security.json.hbs').into('xs-security.json', { project, additions: [{ in: 'scopes', where: { name: '$XSAPPNAME.emcallback' }}, { in: 'scopes', where: { name: '$XSAPPNAME.emmanagement' }}] }) } if (hasHelm || hasHelmUnifiedRuntime) { await merge(__dirname, 'files', 'values.yaml').into('chart/values.yaml') } } }