@@ -3,7 +3,6 @@ const path = require("path")
3
3
const fs = require ( "fs" )
4
4
const cds = require ( '@sap/cds' ) , { BuildTaskProvider, BuildTaskHandler } = cds . build
5
5
const cdsdk = require ( '@sap/cds-dk' )
6
- const { path4 } = cds . serve
7
6
const logger = cds . log ( "build" )
8
7
9
8
module . exports . activate = ( ) => {
@@ -18,15 +17,10 @@ module.exports.activate = () => {
18
17
applyTaskDefaults ( task ) {
19
18
task . src = task . src || cds . env . folders . srv . replace ( / \/ $ / , '' )
20
19
}
21
- async lookupTasks ( ) {
22
- if ( process . env . NODE_ENV === 'production' ) {
23
- return [ { for : this . id } ]
24
- }
25
- }
26
20
get handler ( ) {
27
21
return class extends BuildTaskHandler {
28
22
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 ) )
30
24
}
31
25
32
26
async build ( ) {
@@ -37,15 +31,24 @@ module.exports.activate = () => {
37
31
await Promise . all ( cds . linked ( model ) . services . map ( service => {
38
32
const openApi = cdsdk . compile . to . openapi ( model , {
39
33
service : service . name ,
40
- 'openapi:url' : path4 ( service ) . replace ( / \. [ ^ . ] + $ / , '' ) ,
41
34
'openapi:diagram' : options . diagram
42
35
} )
43
36
44
- this . write ( openApi ) . to ( `gen/ docs/${ service . name } .openapi3.json` )
37
+ this . write ( openApi ) . to ( `openapi- docs/${ service . name } .openapi3.json` )
45
38
} ) )
46
39
}
47
40
}
48
41
}
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
+ // }
49
52
} ) ( )
50
53
)
51
54
}
0 commit comments