@sap/cds-dk
Version:
Command line client and development toolkit for the SAP Cloud Application Programming Model
89 lines (74 loc) • 2.81 kB
JavaScript
const cds = require('../../../cds')
const { read, write } = cds.utils
const { readProject } = require('../../projectReader')
const { merge } = require('../../merge')
const { join } = require('path')
const { destination, destinations, 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() {
await merge({ cds: { requires: { workzone: true } } }).into('package.json')
if (cds.cli.options.cdm) {
const project = readProject()
await merge(join(__dirname, 'files/cdm.json.hbs')).into('app/workzone/cdm.json', { project })
}
}
async combine() {
const project = readProject()
const { isJava, hasMta, srvPath, apps, appPath, appName, appUIPaths, hasMultitenancy } = project
await Promise.all(appUIPaths.map(p => {
project.uiApp = p
return merge(__dirname, 'files/manifest.json.hbs').into(join(appPath, p, 'webapp/manifest.json'), { project })
}))
await Promise.all(apps.map(async ({ app }) => {
const additions = [odataApi]
const overwrites = [{
item: [odataApi, 'destination'],
withValue: `${appName}-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 (hasMultitenancy) {
const mtxPackageJson = await read('mtx/sidecar/package.json')
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 (hasMta) {
const srv = srv4(srvPath)
const additions = [srv, destinations, destination, {
in: [destination, 'requires'],
where: { name: 'srv-api' }
}]
const relationships = []
if (hasMultitenancy) {
additions.push(html5RepoHost)
relationships.push({
insert: [html5RepoHost, '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 })
}
}
}