UNPKG

@sap/cds-dk

Version:

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

109 lines (95 loc) 3.73 kB
const cds = require('../../../cds') const { read, write, exists } = cds.utils const { readProject } = require('../../projectReader') const { merge } = require('../../merge') const { join } = require('path') const { destination, destinations, xsuaa, srv4, html5RepoHost, mtxSidecar4 } = require('../../registries/mta') const { odataApi } = require('../../registries/xs-app') module.exports = class extends require('../../plugin') { options() { return { 'cdm': { describe: 'Add Common Data Model', type: 'boolean' } } } static help() { return 'SAP BTP Work Zone, Standard Edition' } requires() { return ['html5-repo', 'destination'] } static hasInProduction(env) { return !!env.requires?.workzone || cds.cli.options.add?.has('workzone-standard') } async run() { const project = readProject() const conf = project.isJava ? { requires: { workzone: true }} : { cds: { requires: { workzone: true } } } await merge(conf).into(project.configFile) if (cds.cli.options.cdm) { await merge(join(__dirname, 'files/cdm.json.hbs')).into('app/workzone/cdm.json', { project }) } } async combine() { const project = readProject() const { isJava, addMta, hasMta, srvPath, apps, appPath, appUIPaths, addMultitenancy, addXsuaa, strippedAppName } = project await Promise.all(appUIPaths.map(async p => { project.uiApp = p const manifestPath = join(appPath, p, 'webapp/manifest.json') const manifest = exists(manifestPath) ? await read(manifestPath) : {} if (!manifest['sap.app']?.crossNavigation?.inbounds) { return merge(__dirname, 'files/manifest.json.hbs').into(join(appPath, p, 'webapp/manifest.json'), { project }) } else { return merge({ 'sap.cloud': { public: true, service: `${strippedAppName}.service` }}).into(join(appPath, p, 'webapp/manifest.json'), { project }) } })) await Promise.all(apps.map(async ({ app }) => { const additions = [odataApi] const overwrites = [{ item: [odataApi, 'destination'], withValue: `srv-api` }] project.app = app await merge(__dirname, 'files/xs-app.json.hbs').into(join(appPath, app, 'xs-app.json'), { with: project, additions, overwrites }) })) if (addMultitenancy) { const mtxPackageJson = await read('mtx/sidecar/package.json') mtxPackageJson.cds ??= {} mtxPackageJson.cds.requires ??= {} mtxPackageJson.cds.requires['html5-host'] = true delete mtxPackageJson.cds.requires['html5-repo'] // delete mtxPackageJson.cds.requires['html5-runtime'] // delete mtxPackageJson.cds.requires['destinations'] await write('mtx/sidecar/package.json', mtxPackageJson, { spaces: 2 }) } if (addMta || (addMultitenancy || addXsuaa) && hasMta) { const srv = srv4(srvPath) const additions = [srv, destinations, destination, { in: [destination, 'requires'], where: { name: 'srv-api' } }] const relationships = [] if (addMultitenancy) { relationships.push({ insert: [html5RepoHost, 'name'], into: [mtxSidecar4(isJava ? 'mtx/sidecar' : 'gen/mtx/sidecar'), 'requires', 'name'] }) } if (addXsuaa) { relationships.push({ insert: [xsuaa], into: [destinations, 'requires'] }) additions.push({ in: [destinations, 'parameters.content.instance.destinations' ], where: { Authentication: 'OAuth2UserTokenExchange' } }) } await merge(__dirname, 'files/mta.yaml.hbs').into('mta.yaml', { with: project, additions, relationships }) } } }