UNPKG

@sap/cds-dk

Version:

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

89 lines (75 loc) 2.67 kB
const cds = require('../../../cds') const { path } = cds.utils const { readProject } = require('../../projectReader') const { merge } = require('../../merge') const { srv4, portal, portalDeployer, xsuaa, html5RepoHost, appDeployer, approuter, mtxSidecar4 } = require('../../registries/mta') const { renderAndCopy } = require('../../template') module.exports = class PortalTemplate extends require('../../plugin') { static help() { return 'SAP BTP Portal Service' } requires() { return ['html5-repo', 'approuter'] } static hasInProduction(env) { return !!env.requires?.portal } async run() { const project = readProject() const { configFile } = project await merge(__dirname, 'files/package.json.hbs').into(configFile, { project }) project.literal = () => text => text await renderAndCopy(path.join(__dirname, 'files/portal-site'), 'app/portal/portal-site', project) } async combine() { const project = readProject() const { isJava, hasMta, srvPath, hasHtml5Repo, hasXsuaa, hasApprouter, hasMultitenancy, hasHelm, hasHelmUnifiedRuntime } = project if (hasMultitenancy) { await merge(__dirname, 'files/package.sidecar.json').into('mtx/sidecar/package.json') } if (hasMta) { const srv = srv4(srvPath) const additions = [srv, portal, appDeployer, portalDeployer] const relationships = [{ insert: [portal, 'name'], into: [portalDeployer, 'requires', 'name'] }, { insert: [appDeployer, 'name'], into: [portalDeployer, 'requires', 'name'] }] if (hasXsuaa) { additions.push(xsuaa) relationships.push({ insert: [xsuaa, 'name'], into: [portalDeployer, 'requires', 'name'] }) } if (hasHtml5Repo) { additions.push(html5RepoHost) relationships.push({ insert: [html5RepoHost, 'name'], into: [portalDeployer, 'requires', 'name'] }) } if (hasApprouter) { additions.push(approuter) relationships.push({ insert: [portal, 'name'], into: [approuter, 'requires', 'name'] }) } if (hasMultitenancy) { relationships.push({ insert: [portal, 'name'], into: [mtxSidecar4(isJava ? 'mtx/sidecar' : 'gen/mtx/sidecar'), 'requires', 'name'] }) } await merge(__dirname, 'files/mta.yaml.hbs').into('mta.yaml', { with: project, additions, relationships }) } if (hasHelm || hasHelmUnifiedRuntime) { await merge(__dirname, 'files/values.yaml.hbs').into('chart/values.yaml', { with: project }) } } }