@sap/cds-dk
Version:
Command line client and development toolkit for the SAP Cloud Application Programming Model
70 lines (59 loc) • 1.73 kB
JavaScript
// input: single prepared CSN for a Data Product
// output: array with file names and contents, like
// [ {path: 'Customer.cds', src: '...content...'},
// {path: 'annotations.cds', src: '...content...'},
// {path: 'index.cds', src: '...content...'},
// {path: '_i18n/i18n_de.properties', src: '...content...'},
// ...
// ]
const path = require('node:path')
const { EOL } = require('node:os')
const { compiler: compile } = require ('../../lib/cds')
/**
*
* @param csn
* @param srvName_short
*/
function prepareFiles(csn, srvName_short) {
const {definitions, extensions, i18n} = csn
let files = []
// main cds file
const cdl_main = compile.to.cdl({definitions: definitions})
files.push({
path: srvName_short + '.cds',
src: cdl_main.model
})
// annotations file
if (extensions) {
const using = `using from './${srvName_short}';` + EOL + EOL
const cdl_annos = compile.to.cdl({extensions: extensions})
files.push({
path: 'annotations.cds',
src: using + cdl_annos.model
})
}
// index file
const index_text = `using from './${srvName_short}';` + EOL
+ (extensions ? ('using from \'./annotations\';' + EOL) : '')
files.push({
path: 'index.cds',
src: index_text
})
// text files
for (const langu in i18n) {
const i18n_block = i18n[langu]
let out = ''
for (const key in i18n_block) {
let txt = i18n_block[key]
txt = txt.replace(/'/g, "\\'")
out += key + '=' + txt + EOL
}
files.push({
path: path.join('_i18n', 'i18n_' + langu + '.properties'),
src: out
})
}
return files
}
module.exports = prepareFiles