Compare commits
2 Commits
next
...
build-task
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d073403010 | ||
|
|
2552269cec |
14
fiori/test/build/build-task.js
Normal file
14
fiori/test/build/build-task.js
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
const cds = require ('./sap-cds')
|
||||||
|
|
||||||
|
module.exports = class extends cds.build.Task {
|
||||||
|
|
||||||
|
async build ({src='*'}) {
|
||||||
|
this.log (`Generating edmx output for '${src}'...`)
|
||||||
|
const csn = await this.model(src)
|
||||||
|
return Promise.all (csn.services.map (({name:service}) => {
|
||||||
|
const edmx = cds.compile(csn).to.edmx({service})
|
||||||
|
return this.write(edmx).to(`{srv}/src/main/resources/${service}.edmx`)
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
51
fiori/test/build/sap-cds.js
Normal file
51
fiori/test/build/sap-cds.js
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
const cds = require ('@sap/cds/lib')
|
||||||
|
const path = require('path')
|
||||||
|
const cwd = process.cwd()
|
||||||
|
|
||||||
|
const _resolve = (root,file) => path.resolve (cwd, root, file.replace(/{(app|db|srv)}\/?/g, (_,folder) => cds.env.folders[folder]))
|
||||||
|
const _local = (file) => path.relative (cwd,file)
|
||||||
|
|
||||||
|
|
||||||
|
class BuildTask {
|
||||||
|
|
||||||
|
async build (options) {}
|
||||||
|
async clean (options) {}
|
||||||
|
|
||||||
|
async model(src='*') {
|
||||||
|
return cds.linked (await cds.load(src))
|
||||||
|
}
|
||||||
|
|
||||||
|
log(...args) { return console.log(...args) }
|
||||||
|
warn(...args) { return console.warn(...args) }
|
||||||
|
error(...args) { return console.error(...args) }
|
||||||
|
|
||||||
|
write(x) {
|
||||||
|
if (typeof x === 'object') x = JSON.stringify(x,null,' ')
|
||||||
|
return { to: async (dst)=>{
|
||||||
|
const file = _resolve (this.options.dest, dst)
|
||||||
|
await cds.utils.mkdirp (path.dirname (file))
|
||||||
|
await cds.utils.promises.writeFile (file,x)
|
||||||
|
console.log ('> wrote:', _local(file))
|
||||||
|
return file
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
|
||||||
|
copy(x) {
|
||||||
|
return { to: async (dst) => {} }
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
module.exports = Object.assign (cds, {
|
||||||
|
build: {
|
||||||
|
run (tasks, _options) {
|
||||||
|
const options = { dest:'gen', ..._options }
|
||||||
|
return Promise.all(tasks.map (async each => {
|
||||||
|
const task = Object.assign (new each, {options})
|
||||||
|
await task.build (options)
|
||||||
|
}))
|
||||||
|
},
|
||||||
|
Task: BuildTask
|
||||||
|
}
|
||||||
|
})
|
||||||
5
fiori/test/build/test.js
Normal file
5
fiori/test/build/test.js
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
const cds = require ('./sap-cds')
|
||||||
|
const task = require('./build-task')
|
||||||
|
|
||||||
|
cds.build.run ([task], {src:process.argv[2]})
|
||||||
|
.catch(console.error)
|
||||||
Reference in New Issue
Block a user