@@ -3,7 +3,6 @@ const path = require("path")
33const fs = require ( "fs" )
44const cds = require ( '@sap/cds' ) , { BuildTaskProvider, BuildTaskHandler } = cds . build
55const cdsdk = require ( '@sap/cds-dk' )
6- const { path4 } = cds . serve
76const logger = cds . log ( "build" )
87
98module . exports . activate = ( ) => {
@@ -18,15 +17,10 @@ module.exports.activate = () => {
1817 applyTaskDefaults ( task ) {
1918 task . src = task . src || cds . env . folders . srv . replace ( / \/ $ / , '' )
2019 }
21- async lookupTasks ( ) {
22- if ( process . env . NODE_ENV === 'production' ) {
23- return [ { for : this . id } ]
24- }
25- }
2620 get handler ( ) {
2721 return class extends BuildTaskHandler {
2822 async clean ( ) {
29- fs . rm ( path . join ( this . task . dest , "gen/ docs" ) , { recursive : true , force : true } , ( err ) => logger . error ( err ) )
23+ fs . rm ( path . join ( this . task . dest , "openapi- docs" ) , { recursive : true , force : true } , ( err ) => err ? logger . error ( err ) : '' )
3024 }
3125
3226 async build ( ) {
@@ -37,15 +31,23 @@ module.exports.activate = () => {
3731 await Promise . all ( cds . linked ( model ) . services . map ( service => {
3832 const openApi = cdsdk . compile . to . openapi ( model , {
3933 service : service . name ,
40- 'openapi:url' : path4 ( service ) . replace ( / \. [ ^ . ] + $ / , '' ) ,
41- 'openapi:diagram' : options . diagram
34+ 'openapi:diagram' : String ( options . diagram ) === 'true'
4235 } )
43-
44- this . write ( openApi ) . to ( `gen/docs/${ service . name } .openapi3.json` )
36+ this . write ( openApi ) . to ( `openapi-docs/${ service . name } .openapi3.json` )
4537 } ) )
4638 }
4739 }
4840 }
41+ /**
42+ * Additional constraints can be defined, e.g. generate openapi service specification in production builds only.
43+ * > cds build --production
44+ * > cds build --for node-cf --production
45+ */
46+ // async lookupTasks() {
47+ // if (process.env.NODE_ENV === 'production') {
48+ // return [{ for: this.id }]
49+ // }
50+ // }
4951 } ) ( )
5052 )
5153}
0 commit comments