@@ -8,37 +8,34 @@ const codeceptjsFactory = require('../model/codeceptjs-factory');
8
8
const { methodsOfObject } = require ( 'codeceptjs/lib/utils' ) ;
9
9
10
10
module . exports = ( req , res ) => {
11
+ const { container } = codeceptjsFactory . getInstance ( ) ;
12
+ const docsWebApiFolderPath = path . join ( path . dirname ( require . resolve ( 'codeceptjs' ) ) , '/../docs/webapi' ) ;
13
+ const docFileList = [ ] ;
11
14
try {
12
- const { container } = codeceptjsFactory . getInstance ( ) ;
13
- const docsWebApiFolderPath = path . join ( path . dirname ( require . resolve ( 'codeceptjs' ) ) , '/../docs/webapi' ) ;
14
- const docFileList = [ ] ;
15
15
fs . readdirSync ( docsWebApiFolderPath ) . map ( fileName => {
16
16
docFileList . push ( path . basename ( fileName , '.mustache' ) ) ;
17
17
} ) ;
18
- const helpers = container . helpers ( ) ;
19
- const actions = { } ;
20
- for ( const name in helpers ) {
21
- const helper = helpers [ name ] ;
22
- methodsOfObject ( helper ) . forEach ( ( action ) => {
23
-
24
- if ( docFileList . includes ( action ) ) {
25
- let filePath = path . join ( docsWebApiFolderPath , action + '.mustache' ) ;
26
- let fn = helper [ action ] . toString ( ) . replace ( / \n / g, ' ' ) . replace ( / \{ .* \} / gm, '{}' ) ;
27
- try {
28
- let docData = fs . readFileSync ( filePath , 'utf-8' ) ;
29
- let params = parser . parse ( fn ) ;
30
- actions [ action ] = { params : params , actionDoc : docData } ;
31
- } catch ( err ) {
32
- debug ( 'Error in fetching doc for file content' , fn , err ) ;
33
- }
34
- }
35
-
36
- } ) ;
37
- }
38
-
39
- res . send ( { actions } ) ;
40
18
} catch ( e ) {
41
- debug ( `Could not fetch documentation due to: ${ e . message } ` ) ;
19
+ debug ( `No documentation found due to ${ e . message } ` ) ;
42
20
}
21
+ const helpers = container . helpers ( ) ;
22
+ const actions = { } ;
23
+ for ( const name in helpers ) {
24
+ const helper = helpers [ name ] ;
25
+ methodsOfObject ( helper ) . forEach ( ( action ) => {
43
26
27
+ if ( docFileList . includes ( action ) ) {
28
+ let filePath = path . join ( docsWebApiFolderPath , action + '.mustache' ) ;
29
+ let fn = helper [ action ] . toString ( ) . replace ( / \n / g, ' ' ) . replace ( / \{ .* \} / gm, '{}' ) ;
30
+ try {
31
+ let docData = fs . readFileSync ( filePath , 'utf-8' ) ;
32
+ let params = parser . parse ( fn ) ;
33
+ actions [ action ] = { params : params , actionDoc : docData } ;
34
+ } catch ( err ) {
35
+ debug ( 'Error in fetching doc for file content' , fn , err ) ;
36
+ }
37
+ }
38
+ } ) ;
39
+ }
40
+ res . send ( { actions } ) ;
44
41
} ;
0 commit comments