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