11import { writeFileSync } from 'fs' ;
22import spec from '../src/reference/v8.json' with { type : 'json' } ;
33import { supportsPropertyExpression , supportsZoomExpression } from '../src/util/properties' ;
4+ import { formatJSON } from './util' ;
5+
6+ function jsDocComment ( property ) {
7+ const lines = [ ] ;
8+ if ( property . doc ) {
9+ lines . push ( ...property . doc . split ( '\n' ) ) ;
10+ }
11+ if ( property . default ) {
12+ if ( lines . length ) {
13+ lines . push ( '' ) ;
14+ }
15+ lines . push ( ...jsDocBlock ( 'default' , property . default ) . split ( '\n' ) ) ;
16+ }
17+ if ( property . example ) {
18+ if ( lines . length ) {
19+ lines . push ( '' ) ;
20+ }
21+ lines . push ( ...jsDocBlock ( 'example' , property . example ) . split ( '\n' ) ) ;
22+ }
23+
24+ if ( ! lines . length ) {
25+ return undefined ;
26+ }
27+ return [
28+ '/**' ,
29+ ...lines . map ( line => ` * ${ line } ` ) ,
30+ ' */' ,
31+ ] . join ( '\n' ) ;
32+ }
33+
34+ function jsDocBlock ( tag , value ) {
35+ return `@${ tag }
36+ \`\`\`json
37+ ${ formatJSON ( value ) }
38+ \`\`\`` ;
39+ }
440
541function unionType ( values ) {
642 if ( Array . isArray ( values ) ) {
@@ -64,7 +100,9 @@ function propertyType(property) {
64100}
65101
66102function propertyDeclaration ( key , property ) {
67- return `"${ key } "${ property . required ? '' : '?' } : ${ propertyType ( property ) } ` ;
103+ const jsDoc = jsDocComment ( property ) ;
104+ const declaration = `"${ key } "${ property . required ? '' : '?' } : ${ propertyType ( property ) } ` ;
105+ return jsDoc ? [ jsDoc , declaration ] . join ( '\n' ) : declaration ;
68106}
69107
70108function transitionPropertyDeclaration ( key ) {
@@ -86,7 +124,12 @@ ${Object.keys(properties)
86124 }
87125 return declarations ;
88126 } )
89- . map ( declaration => ` ${ indent } ${ declaration } ` )
127+ . map ( declaration => {
128+ return declaration
129+ . split ( '\n' )
130+ . map ( line => ` ${ indent } ${ line } ` )
131+ . join ( '\n' ) ;
132+ } )
90133 . join ( ',\n' ) }
91134${ indent } }`;
92135}
0 commit comments