@@ -22,6 +22,7 @@ const Documentation = require('../doclint/check_public_api/Documentation');
22
22
const PROJECT_DIR = path . join ( __dirname , '..' , '..' ) ;
23
23
const fs = require ( 'fs' ) ;
24
24
const { parseOverrides} = require ( './parseOverrides' ) ;
25
+ const exported = require ( './exported.json' ) ;
25
26
const objectDefinitions = [ ] ;
26
27
const handledMethods = new Set ( ) ;
27
28
/** @type {Documentation } */
@@ -64,12 +65,14 @@ let documentation;
64
65
return classBody ( docClassForName ( className ) ) ;
65
66
} ) ;
66
67
const classes = documentation . classesArray . filter ( cls => ! handledClasses . has ( cls . name ) ) ;
67
- const output = `// This file is generated by ${ __filename . substring ( path . join ( __dirname , '..' , '..' ) . length ) }
68
+ let output = `// This file is generated by ${ __filename . substring ( path . join ( __dirname , '..' , '..' ) . length ) }
68
69
${ overrides }
69
70
70
71
${ classes . map ( classDesc => classToString ( classDesc ) ) . join ( '\n' ) }
71
72
${ objectDefinitionsToString ( ) }
72
73
` ;
74
+ for ( const [ key , value ] of Object . entries ( exported ) )
75
+ output = output . replace ( new RegExp ( '\\b' + key + '\\b' , 'g' ) , value ) ;
73
76
fs . writeFileSync ( path . join ( typesDir , 'types.d.ts' ) , output , 'utf8' ) ;
74
77
} ) ( ) . catch ( e => {
75
78
console . error ( e ) ;
@@ -81,7 +84,7 @@ function objectDefinitionsToString() {
81
84
const parts = [ ] ;
82
85
while ( ( definition = objectDefinitions . pop ( ) ) ) {
83
86
const { name, properties} = definition ;
84
- parts . push ( `interface ${ name } {` ) ;
87
+ parts . push ( `${ exported [ name ] ? 'export ' : '' } interface ${ name } {` ) ;
85
88
parts . push ( properties . map ( member => `${ memberJSDOC ( member , ' ' ) } ${ nameForProperty ( member ) } ${ argsFromMember ( member , name ) } : ${ typeToString ( member . type , name , member . name ) } ;` ) . join ( '\n\n' ) ) ;
86
89
parts . push ( '}\n' ) ;
87
90
}
@@ -109,7 +112,7 @@ function classToString(classDesc) {
109
112
}
110
113
111
114
/**
112
- * @param {string } type
115
+ * @param {string } type
113
116
*/
114
117
function argNameForType ( type ) {
115
118
if ( type === 'void' )
@@ -192,8 +195,8 @@ function classBody(classDesc) {
192
195
}
193
196
194
197
/**
195
- * @param {Documentation.Class } classDesc
196
- * @param {string } methodName
198
+ * @param {Documentation.Class } classDesc
199
+ * @param {string } methodName
197
200
*/
198
201
function hasOwnMethod ( classDesc , methodName ) {
199
202
if ( handledMethods . has ( `${ classDesc . name } .${ methodName } ` ) )
@@ -206,7 +209,7 @@ function hasOwnMethod(classDesc, methodName) {
206
209
}
207
210
208
211
/**
209
- * @param {Documentation.Class } classDesc
212
+ * @param {Documentation.Class } classDesc
210
213
*/
211
214
function parentClass ( classDesc ) {
212
215
if ( ! classDesc . extends )
@@ -221,13 +224,6 @@ function writeComment(comment, indent = '') {
221
224
parts . push ( indent + ' */' ) ;
222
225
return parts . join ( '\n' ) ;
223
226
}
224
- function writeComment2 ( comment , indent = '' ) {
225
- const parts = [ ] ;
226
- parts . push ( '/**' ) ;
227
- parts . push ( ...comment . split ( '\n' ) . map ( line => indent + ' * ' + line . replace ( / \* \/ / g, '*\\/' ) ) ) ;
228
- parts . push ( indent + ' */\n' + indent ) ;
229
- return parts . join ( '\n' ) ;
230
- }
231
227
232
228
/**
233
229
* @param {Documentation.Type } type
@@ -373,9 +369,9 @@ function memberJSDOC(member, indent) {
373
369
}
374
370
375
371
/**
376
- * @param {Documentation } mdDoc
377
- * @param {Documentation } jsDoc
378
- * @return {Documentation }
372
+ * @param {Documentation } mdDoc
373
+ * @param {Documentation } jsDoc
374
+ * @return {Documentation }
379
375
*/
380
376
function mergeDocumentation ( mdDoc , jsDoc ) {
381
377
const classes = [ ] ;
0 commit comments