@@ -8,37 +8,34 @@ const codeceptjsFactory = require('../model/codeceptjs-factory');
88const { methodsOfObject } = require ( 'codeceptjs/lib/utils' ) ;
99
1010module . exports = ( req , res ) => {
11+ const { container } = codeceptjsFactory . getInstance ( ) ;
12+ const docsWebApiFolderPath = path . join ( path . dirname ( require . resolve ( 'codeceptjs' ) ) , '/../docs/webapi' ) ;
13+ const docFileList = [ ] ;
1114 try {
12- const { container } = codeceptjsFactory . getInstance ( ) ;
13- const docsWebApiFolderPath = path . join ( path . dirname ( require . resolve ( 'codeceptjs' ) ) , '/../docs/webapi' ) ;
14- const docFileList = [ ] ;
1515 fs . readdirSync ( docsWebApiFolderPath ) . map ( fileName => {
1616 docFileList . push ( path . basename ( fileName , '.mustache' ) ) ;
1717 } ) ;
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 } ) ;
4018 } catch ( e ) {
41- debug ( `Could not fetch documentation due to: ${ e . message } ` ) ;
19+ debug ( `No documentation found due to ${ e . message } ` ) ;
4220 }
21+ const helpers = container . helpers ( ) ;
22+ const actions = { } ;
23+ for ( const name in helpers ) {
24+ const helper = helpers [ name ] ;
25+ methodsOfObject ( helper ) . forEach ( ( action ) => {
4326
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 } ) ;
4441} ;
0 commit comments