@@ -14,34 +14,43 @@ function updateFileWithAppEventDocs(filePath, appEventsDetails) {
14
14
appEventsDetails . forEach ( ( details ) => {
15
15
const { lineNumber } = details ;
16
16
// lines is 0-indexed while lineNumber refers to file line number which is 1-indexed
17
- const startPos = lineNumber - 1 ;
18
- const indentation = lines [ startPos ] . length - lines [ startPos ] . trimStart ( ) . length ;
17
+ const startPos = lineNumber - 1 ;
18
+ const indentation =
19
+ lines [ startPos ] . length - lines [ startPos ] . trimStart ( ) . length ;
19
20
const docString = createDocumentation ( details , indentation ) ; // TODO: this should be a separate script
20
21
lines . splice ( startPos , 0 , docString ) ;
21
22
} ) ;
22
23
23
- fs . writeFileSync ( filePath , lines . join ( '\n' ) , ' utf8' ) ;
24
+ fs . writeFileSync ( filePath , lines . join ( "\n" ) , " utf8" ) ;
24
25
}
25
26
26
- function createDocumentation ( details , indentation = 0 ) {
27
- const { eventId, args, comments } = details ;
28
- if ( ! eventId && ! comments && args . length === 0 ) { return null ; }
27
+ function createDocumentation ( details , indentation = 0 ) {
28
+ const { eventId, args, description } = details ;
29
+ if ( ! eventId && ! description && args . length === 0 ) {
30
+ return null ;
31
+ }
29
32
30
33
const createArgDoc = ( arg ) => {
31
34
const argTemplate = ( argName , argType , argDesc ) => {
32
35
const templatedDesc = argDesc ? ` - ${ argDesc } ` : "" ;
33
36
return ` * @arg {${ argType } } ${ argName } ${ templatedDesc } ` ;
34
37
} ;
35
38
36
- if ( arg . argType === ' object' ) {
39
+ if ( arg . argType === " object" ) {
37
40
const objectArgName = `objectArg${ arg . argPosition } ` ;
38
41
const initialObjDoc = ` * @arg {object} ${ objectArgName } ` ;
39
42
return [
40
43
initialObjDoc ,
41
44
...arg . argValue
42
- . map ( ( nestedArg ) => argTemplate ( `${ objectArgName } .${ nestedArg . key } ` , nestedArg . valueType , nestedArg . description ) )
43
- . map ( ( part ) => `${ ' ' . repeat ( indentation ) } ${ part } ` )
44
- ] . join ( '\n' ) ;
45
+ . map ( ( nestedArg ) =>
46
+ argTemplate (
47
+ `${ objectArgName } .${ nestedArg . key } ` ,
48
+ nestedArg . valueType ,
49
+ nestedArg . description
50
+ )
51
+ )
52
+ . map ( ( part ) => `${ " " . repeat ( indentation ) } ${ part } ` ) ,
53
+ ] . join ( "\n" ) ;
45
54
}
46
55
47
56
return argTemplate ( arg . argValue , arg . argType , arg . description ) ;
@@ -50,19 +59,20 @@ function createDocumentation(details, indentation=0) {
50
59
const argsStrings = args
51
60
. sort ( ( a , b ) => a . argPosition - b . argPosition )
52
61
. map ( ( arg ) => createArgDoc ( arg ) ) ;
62
+ const descString = description ? ` * ${ description } \n *` : ` *` ;
53
63
54
64
return [
55
65
`/**` ,
56
66
` * ${ eventId } appEvent` ,
57
- ` *` ,
67
+ descString ,
58
68
` * @event ${ eventId } ` ,
59
69
...argsStrings ,
60
- ` */`
61
- ] . map ( ( part ) => `${ ' ' . repeat ( indentation ) } ${ part } ` )
62
- . join ( '\n' ) ;
70
+ ` */` ,
71
+ ]
72
+ . map ( ( part ) => `${ " " . repeat ( indentation ) } ${ part } ` )
73
+ . join ( "\n" ) ;
63
74
}
64
75
65
-
66
76
( async ( ) => {
67
77
if ( process . argv . length != 2 ) {
68
78
console . log (
@@ -71,7 +81,6 @@ function createDocumentation(details, indentation=0) {
71
81
process . exit ( 1 ) ;
72
82
}
73
83
74
-
75
84
const appEventsDetailsFilePath = path . join (
76
85
"." ,
77
86
"lib" ,
0 commit comments