- single BuildTaskHandler instead of BuildTaskProvider/BuildTaskHandler approach - static build task handler config moved to meta - default build task properties are now returned as name/value pairs using property config - runWith to declare dependencies across build task handlers, ensuring correct dependency graph - optional getTasks method to implement build task specific constraints
29 lines
980 B
JavaScript
29 lines
980 B
JavaScript
/* eslint-disable require-await */
|
|
const cds = require('@sap/cds'), { BuildTaskHandler } = cds.build
|
|
const cdsdk = require('@sap/cds-dk')
|
|
|
|
cds.build.register(class OpenApiHandler extends BuildTaskHandler {
|
|
static get meta() {
|
|
return {
|
|
id: 'openapi',
|
|
runWith: ['node-cf', 'java-cf'],
|
|
config: { src: cds.env.folders.srv.replace(/\/$/, '') }
|
|
}
|
|
}
|
|
async clean() {
|
|
return this.remove('openapi-docs')
|
|
}
|
|
async build() {
|
|
const model = await this.model()
|
|
const { options } = this.task
|
|
|
|
// generate openapi files for all services
|
|
await Promise.all(cds.linked(model).services.map(service => {
|
|
const openApi = cdsdk.compile.to.openapi(model, {
|
|
service: service.name,
|
|
'openapi:diagram': String(options.diagram) === 'true'
|
|
})
|
|
this.write(openApi).to(`openapi-docs/${service.name}.openapi3.json`)
|
|
}))
|
|
}
|
|
}) |