UNPKG

@sap/cds-dk

Version:

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

114 lines (101 loc) 4.63 kB
const { join } = require('path') const { readProject } = require('../../projectReader') const { merge } = require('../../merge') const { srv4, html5RepoHost, html5Runtime, appDeployer, approuter, mtxSidecar4 } = require('../../registries/mta') const { odataApi } = require('../../registries/xs-app') const { exists } = require('../../../cds').utils const { renderAndCopy } = require('../../template') module.exports = class Html5RepoTemplate extends require('../../plugin') { requires() { const { hasHelm, hasHelmUnifiedRuntime } = readProject() if (hasHelm || hasHelmUnifiedRuntime) 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, apps, appPath, configFile, hasUI5 } = project await merge(__dirname, 'files/package.json.hbs').into(configFile, { project }) if (hasUI5) { for (const { app } of apps) { project.app = app await merge(__dirname, 'files/ui5.yaml.hbs').into(join(appPath, app, 'ui5.yaml'), { project }) } for (const { app } of apps) { project.app = app await merge(__dirname, 'files/ui5-deploy.yaml.hbs').into(join(appPath, app, 'ui5-deploy.yaml'), { project }) } } for (const { app } of apps) { project.app = app await merge(__dirname, 'files/app-package.json.hbs').into(join(appPath, app, 'package.json'), { 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, hasMta, hasMultitenancy, hasWorkzoneStandard, hasHelm, hasHelmUnifiedRuntime, hasApprouter, hasContainerize, apps } = project await Promise.all(apps.map(async ({ app }) => { project.app = app project.hasIndexHtml = exists(join(appPath, app, 'webapp/index.html')) const additions = [odataApi] await merge(__dirname, 'files/xs-app.json.hbs').into(join(appPath, app, 'xs-app.json'), { with: project, additions }) })) if (hasMultitenancy) { await merge({ cds: { requires: { 'html5-runtime':true } } }).into('mtx/sidecar/package.json') } if (hasMta) { const srv = srv4(srvPath) project.apps = apps const appModules = project.apps.map(app => ({ in: 'modules', where: { type: 'html5', path: `${appPath}${app.app}` } })) const additions = [srv, appDeployer, html5RepoHost, ...appModules] const relationships = [{ insert: [html5RepoHost, 'name'], into: [appDeployer, 'requires', 'name'], }] if (hasApprouter || hasWorkzoneStandard || hasMultitenancy) { additions.push(html5Runtime) } if (hasApprouter) { additions.push(approuter) relationships.push({ insert: [html5Runtime, 'name'], into: [approuter, 'requires', 'name'], }) } if (hasMultitenancy) { relationships.push({ insert: [html5Runtime, '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 (hasContainerize) { const additions = [{ in: 'modules', where: { name: `${project.appName}-html5-deployer` } }] await merge(__dirname, '/files/containerize.yaml.hbs').into('containerize.yaml', { with: project, additions }) } if (hasHelm || hasHelmUnifiedRuntime) { await renderAndCopy(join(__dirname, 'files/ui-resources'), 'ui-resources', project) await merge(__dirname, 'files/values.yaml.hbs').into('chart/values.yaml', { with: project }) } } }