@sap/cds-dk
Version:
Command line client and development toolkit for the SAP Cloud Application Programming Model
42 lines (37 loc) • 1.58 kB
JavaScript
const cds = require('../../../cds')
const { path, exists, tar } = cds.utils
const { BUILD_TASK_HANA } = require('../../constants')
const { WARNING } = require('../internal')
module.exports = class ResourcesTarBuilder {
constructor(plugin) {
this._plugin = plugin
}
get plugin() { return this._plugin }
async createTar(dest, model) {
let root = getHanaTenantDbTask(this.plugin)?.dest
let resources
if (root) {
const items = ['src', 'cfg', 'undeploy.json', '.hdiignore']
resources = items.map(item => path.join(root, item)).filter(exists)
} else {
root = cds.root
resources = Object.keys(await cds.deploy.resources(model))
}
if (resources.length === 0) {
this.plugin.pushMessage("No deployment resources found - skip resources.tgz", WARNING)
return
}
const tarFile = path.join(dest, "resources.tgz")
await tar.czfd(tarFile, root, resources)
this.plugin.pushFile(tarFile)
}
}
function getHanaTenantDbTask({ task, context: { tasks } }) {
const hanaTasks = tasks.filter(task => task.for === BUILD_TASK_HANA)
if (hanaTasks.length === 1) return hanaTasks[0]
return hanaTasks.find(({ src }) => {
if (!src) return true // an existing second shared db always requires src to be set
const srcFolder = path.isAbsolute(src) ? path.relative(cds.root, src) : src
return task.options?.model?.includes(srcFolder) || srcFolder === cds.env.folders.db.replace('/', '')
})
}