@sap/cds-dk
Version:
Command line client and development toolkit for the SAP Cloud Application Programming Model
42 lines (34 loc) • 1.4 kB
JavaScript
const cds = require('../../../cds')
const { path, exists, rimraf } = cds.utils
const ResourcesTarBuilder = require('./resourcesTarBuilder')
const { FOLDER_GEN } = require('../../constants')
const { normalizePath } = require('../../util')
module.exports = class MtxBuildPlugin extends require('../edmx') {
static get taskDefaults() { return { src: normalizePath(cds.env.folders.srv) } }
static hasTask() {
const isMtxs = cds.env.requires.multitenancy || cds.env.requires.toggles || cds.env.requires['cds.xt.ModelProviderService']
const hasSidecar = exists(path.join(cds.root, 'mtx/sidecar'))
return isMtxs && !hasSidecar && cds.env['project-nature'] === 'nodejs' && !cds.env.extends
}
get requires() {
return ['hana']
}
init() {
super.init()
}
async build() {
// Only create resources TAR, compiled CSN(s) are created by the Nodejs app build task.
const dest = cds.env.build.target !== '.' ? this.task.dest : path.join(this.task.dest, FOLDER_GEN)
const model = await this.model()
if (!model) {
return
}
return new ResourcesTarBuilder(this).createTar(dest, model)
}
async clean() {
// staging build content is deleted by default
if (cds.env.build.target === '.') {
return rimraf(this.task.dest, FOLDER_GEN)
}
}
}