diff --git a/fiori/test/build/build-task.js b/fiori/test/build/build-task.js new file mode 100644 index 00000000..7b0a2d79 --- /dev/null +++ b/fiori/test/build/build-task.js @@ -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 (srv => { + const edmx = cds.compile(csn).to.edmx({service:srv.name}) + return this.write(edmx).to(`{srv}/src/main/resources/${srv.name}.edmx`) + })) + } + +} diff --git a/fiori/test/build/sap-cds.js b/fiori/test/build/sap-cds.js new file mode 100644 index 00000000..642228f7 --- /dev/null +++ b/fiori/test/build/sap-cds.js @@ -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 + } +}) diff --git a/fiori/test/build/test.js b/fiori/test/build/test.js new file mode 100644 index 00000000..d1ba3519 --- /dev/null +++ b/fiori/test/build/test.js @@ -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)