@sap/cds-dk
Version:
Command line client and development toolkit for the SAP Cloud Application Programming Model
129 lines (114 loc) • 5.38 kB
JavaScript
const { join } = require('path')
const { readProject } = require('../../projectReader')
const { merge } = require('../../merge')
const { srv4, html5RepoHost, html5Runtime, xsuaa, appDeployer, approuter, mtxSidecar4 } = require('../../registries/mta')
const { odataApi, html5RepoApi } = require('../../registries/xs-app')
const { exists } = require('../../../cds').utils
const { renderAndCopy } = require('../../template')
module.exports = class Html5RepoTemplate extends require('../../plugin') {
requires() {
const { hasKyma } = readProject()
if (hasKyma) return ['destination']
}
static help() {
return 'SAP BTP HTML5 Application Repository'
}
static hasInProduction(env) {
return !!env.requires['html5-repo'] || !!env.requires['html5-runtime'] || !!env.requires['html5-host']
}
async run() {
const project = readProject()
const { appUIPaths, appPath, configFile } = project
await merge(__dirname, 'files/package.json.hbs').into(configFile, { project })
// app deployer requires a manifest.json
await Promise.all(appUIPaths.map(p =>
merge(__dirname, 'files/manifest.json')
.into(join(appPath, p, 'webapp/manifest.json'), { project })
))
}
async combine() {
const project = readProject()
const {
isJava, srvPath, appPath, apps,
hasApprouter, hasMta, addMta, hasKyma, hasXsuaa, hasMultitenancy, hasUI5,
addSample, addApprouter, addContainerize, addKyma, addHelm, addHelmUnifiedRuntime, addMultitenancy, addWorkzoneStandard, addXsuaa, addIas
} = project
await Promise.all(apps.map(async ({ app }) => {
project.app = app
project.hasIndexHtml = exists(join(appPath, app, 'webapp/index.html'))
const additions = [odataApi, html5RepoApi]
await merge(__dirname, 'files/xs-app.json.hbs').into(join(appPath, app, 'xs-app.json'), { with: project, additions })
await merge(__dirname, 'files/app-package.json.hbs').into(join(appPath, app, 'package.json'), { project })
}))
if (hasUI5) {
for (const { app } of apps) {
project.app = app
await merge(__dirname, 'files/app-package.json.hbs').into(join(appPath, app, 'package.json'), { project })
}
for (const { app } of apps) {
project.app = app
await merge(__dirname, 'files/ui5.yaml.hbs').into(join(appPath, app, 'ui5.yaml'), { project })
}
}
if (addMultitenancy) {
await merge({ cds: { requires: { 'html5-repo': true } } }).into('mtx/sidecar/package.json')
}
const affected = addXsuaa || addApprouter || addWorkzoneStandard || addMultitenancy || addSample || addIas
if (addMta || affected && hasMta) {
const srv = srv4(srvPath)
project.apps = apps
const relationships = [{
insert: [html5RepoHost, 'name'],
into: [appDeployer, 'requires', 'name'],
}]
const appModules = []
for (const { app } of project.apps) {
const html5App = { in: 'modules', where: { type: 'html5', path: `${appPath}${app}` } }
relationships.push({
insert: [html5App],
into: [appDeployer, 'build-parameters.requires'],
})
}
if (hasApprouter) {
relationships.push({
insert: [html5Runtime, 'name'],
into: [approuter, 'requires', 'name'],
})
}
if (hasMultitenancy) {
relationships.push({
insert: [html5Runtime, 'name'],
into: [isJava ? srv : mtxSidecar4('gen/mtx/sidecar'), 'requires', 'name']
})
relationships.push({
insert: [html5RepoHost, 'name'],
into: [isJava ? srv : mtxSidecar4('gen/mtx/sidecar'), 'requires', 'name']
})
}
if (hasXsuaa) {
relationships.push({
insert: [xsuaa, 'name'],
into: [appDeployer, 'requires']
})
}
await merge(__dirname, 'files/mta.yaml.hbs').into('mta.yaml', {
with: project,
additions: [srv, appDeployer, html5RepoHost, ...appModules],
relationships
})
}
// cds10: change to if (addKyma)
// needed because of adding kyma to cli options in case of helm
if (addContainerize || (addKyma && !addHelm && !addHelmUnifiedRuntime)) {
const additions = [{
in: 'modules',
where: { name: `${project.appName}-html5-deployer` }
}]
await merge(__dirname, '/files/containerize.yaml.hbs').into('containerize.yaml', { with: project, additions })
}
if (addKyma || affected && hasKyma) {
await renderAndCopy(join(__dirname, 'files/html5-deployer.package.json.hbs'), 'app/html5-deployer/package.json', project)
await merge(__dirname, 'files/values.yaml.hbs').into('chart/values.yaml', { with: project })
}
}
}