adopt latest custom build task changes
- 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
This commit is contained in:
@@ -1,53 +1,29 @@
|
||||
/* eslint-disable require-await */
|
||||
const path = require("path")
|
||||
const fs = require("fs")
|
||||
const cds = require('@sap/cds'), { BuildTaskProvider, BuildTaskHandler } = cds.build
|
||||
const cds = require('@sap/cds'), { BuildTaskHandler } = cds.build
|
||||
const cdsdk = require('@sap/cds-dk')
|
||||
const logger = cds.log("build")
|
||||
|
||||
// module.exports.activate = () => {
|
||||
cds.build.registerProvider(
|
||||
new (class extends BuildTaskProvider {
|
||||
get id() {
|
||||
return 'openapi'
|
||||
}
|
||||
get dependents() {
|
||||
return ['node-cf', 'java-cf']
|
||||
}
|
||||
applyDefaults(task) {
|
||||
task.src = task.src || cds.env.folders.srv.replace(/\/$/, '')
|
||||
}
|
||||
get handler() {
|
||||
return class extends BuildTaskHandler {
|
||||
async clean() {
|
||||
fs.rm(path.join(this.task.dest, "openapi-docs"), { recursive: true, force: true }, (err) => err ? logger.error(err) : '')
|
||||
}
|
||||
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
|
||||
|
||||
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`)
|
||||
}))
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Additional constraints can be defined, e.g. generate openapi service specification in production builds only.
|
||||
* > cds build --production
|
||||
* > cds build --for node-cf --production
|
||||
*/
|
||||
// async lookupTasks() {
|
||||
// if (process.env.NODE_ENV === 'production') {
|
||||
// return [{ for: this.id }]
|
||||
// }
|
||||
// }
|
||||
})()
|
||||
)
|
||||
// }
|
||||
// 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`)
|
||||
}))
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user