Skip to content

Commit

Permalink
lookupTasks becomes optional
Browse files Browse the repository at this point in the history
- change output dir
  • Loading branch information
LotharBender committed Nov 24, 2021
1 parent 8b0f601 commit 69126b9
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions cds-plugin-openapi/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const path = require("path")
const fs = require("fs")
const cds = require('@sap/cds'), { BuildTaskProvider, BuildTaskHandler } = cds.build
const cdsdk = require('@sap/cds-dk')
const { path4 } = cds.serve
const logger = cds.log("build")

module.exports.activate = () => {
Expand All @@ -18,15 +17,10 @@ module.exports.activate = () => {
applyTaskDefaults(task) {
task.src = task.src || cds.env.folders.srv.replace(/\/$/, '')
}
async lookupTasks() {
if (process.env.NODE_ENV === 'production') {
return [{ for: this.id }]
}
}
get handler() {
return class extends BuildTaskHandler {
async clean() {
fs.rm(path.join(this.task.dest, "gen/docs"), { recursive: true, force: true }, (err) => logger.error(err))
fs.rm(path.join(this.task.dest, "openapi-docs"), { recursive: true, force: true }, (err) => err ? logger.error(err) : '')
}

async build() {
Expand All @@ -37,15 +31,23 @@ module.exports.activate = () => {
await Promise.all(cds.linked(model).services.map(service => {
const openApi = cdsdk.compile.to.openapi(model, {
service: service.name,
'openapi:url': path4(service).replace(/\.[^.]+$/, ''),
'openapi:diagram': options.diagram
'openapi:diagram': String(options.diagram) === 'true'
})

this.write(openApi).to(`gen/docs/${service.name}.openapi3.json`)
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 }]
// }
// }
})()
)
}

0 comments on commit 69126b9

Please sign in to comment.