@@ -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 ) => logger . error ( err ) )
3024 }
3125
3226 async build ( ) {
@@ -37,15 +31,24 @@ 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 ( / \. [ ^ . ] + $ / , '' ) ,
4134 'openapi:diagram' : options . diagram
4235 } )
4336
44- this . write ( openApi ) . to ( `gen/ docs/${ service . name } .openapi3.json` )
37+ this . write ( openApi ) . to ( `openapi- docs/${ service . name } .openapi3.json` )
4538 } ) )
4639 }
4740 }
4841 }
42+ /**
43+ * Additional constraints can be defined, e.g. generate openapi service specification in production builds only.
44+ * > cds build --production
45+ * > cds build --for node-cf --production
46+ */
47+ // async lookupTasks() {
48+ // if (process.env.NODE_ENV === 'production') {
49+ // return [{ for: this.id }]
50+ // }
51+ // }
4952 } ) ( )
5053 )
5154}
0 commit comments