1- const jsdoc2md = require ( "jsdoc-to-markdown" ) ;
2- const fs = require ( "fs" ) ;
3- const path = require ( "path" ) ;
4- const prettier = require ( "prettier" ) ;
5- const publicClassFiles = [
6- "amplitude-client.js" ,
7- "amplitude.js" ,
8- "identify.js" ,
9- "revenue.js" ,
10- ] ;
11- const publicTypedefFiles = [ "options.js" ] ;
12- const srcDir = path . join ( __dirname , "../" , "src" ) ;
13- const outputDir = path . join ( __dirname , "docs" ) ;
1+ const jsdoc2md = require ( 'jsdoc-to-markdown' ) ;
2+ const fs = require ( 'fs' ) ;
3+ const path = require ( 'path' ) ;
4+ const prettier = require ( 'prettier' ) ;
5+ const publicClassFiles = [ 'amplitude-client.js' , 'amplitude.js' , 'identify.js' , 'revenue.js' ] ;
6+ const publicTypedefFiles = [ 'options.js' ] ;
7+ const srcDir = path . join ( __dirname , '../' , 'src' ) ;
8+ const outputDir = path . join ( __dirname , 'docs' ) ;
149
1510function generateTypedefMarkdown ( inputFile ) {
1611 const inputFilePath = path . join ( srcDir , inputFile ) ;
1712 const data = jsdoc2md . getTemplateDataSync ( { files : inputFilePath } ) ;
18- const name = data . find ( ( e ) => e . kind === "typedef" ) . name ;
19- const filteredData = data . filter ( ( e ) => e . kind === "typedef" ) ;
20- const outputFilePath = path . join ( outputDir , `${ name } .md` ) ;
21- const markdownOutput = filteredData
22- . map ( ( item ) => documentOptionsFile ( item ) )
23- . join ( "\n" ) ;
24- fs . writeFileSync (
25- path . join ( outputDir , `${ name } .md` ) ,
26- prettier . format ( markdownOutput , { parser : "mdx" } )
27- ) ;
13+ const name = data . find ( ( e ) => e . kind === 'typedef' ) . name ;
14+ const filteredData = data . filter ( ( e ) => e . kind === 'typedef' ) ;
15+
16+ const markdownOutput = filteredData . map ( ( item ) => documentOptionsFile ( item ) ) . join ( '\n' ) ;
17+ fs . writeFileSync ( path . join ( outputDir , `${ name } .md` ) , prettier . format ( markdownOutput , { parser : 'mdx' } ) ) ;
2818}
2919
3020function generateClassMarkdown ( inputFile ) {
3121 const inputFilePath = path . join ( srcDir , inputFile ) ;
3222 const data = jsdoc2md . getTemplateDataSync ( { files : inputFilePath } ) ;
33- const className = data . find ( ( e ) => e . kind === " class" ) . name ;
23+ const className = data . find ( ( e ) => e . kind === ' class' ) . name ;
3424 const filteredData = data . filter (
35- ( e ) =>
36- e . kind === "constructor" ||
37- ( e . access === "public" && ( e . kind === "function" || e . kind === "member" ) )
38- ) ;
39- const outputFilePath = path . join ( outputDir , `${ className } .md` ) ;
40-
41- const markdownOutput = filteredData
42- . map ( ( item ) => documentClassFile ( item ) )
43- . join ( "\n" ) ;
44- fs . writeFileSync (
45- path . join ( outputDir , `${ className } .md` ) ,
46- prettier . format ( markdownOutput , { parser : "mdx" } )
25+ ( e ) => e . kind === 'constructor' || ( e . access === 'public' && ( e . kind === 'function' || e . kind === 'member' ) ) ,
4726 ) ;
27+
28+ const markdownOutput = filteredData . map ( ( item ) => documentClassFile ( item ) ) . join ( '\n' ) ;
29+ fs . writeFileSync ( path . join ( outputDir , `${ className } .md` ) , prettier . format ( markdownOutput , { parser : 'mdx' } ) ) ;
4830}
4931
5032function documentOptionsFile ( data ) {
5133 return `${ documentHeader ( data ) }
52-
34+
5335 ${ data . description }
5436
5537Option | Type | Description | Default
@@ -63,25 +45,25 @@ function documentOptionsProperties(data) {
6345 return data . properties
6446 . map (
6547 ( prop ) =>
66- `${ prop . name || "" } | ${ data . properties [ 0 ] . type . names . join ( "|" ) } | ${
67- prop . defaultvalue || ""
68- } | ${ prop . description || "" } `
48+ `${ prop . name || '' } | ${ data . properties [ 0 ] . type . names . join ( '|' ) } | ${ prop . defaultvalue || '' } | ${
49+ prop . description || ''
50+ } ` ,
6951 )
70- . join ( "\n" ) ;
52+ . join ( '\n' ) ;
7153}
7254
7355function documentClassFile ( data ) {
7456 return `${ documentHeader ( data ) }
7557
76- ${ data . examples ? documentExamples ( data ) : "" }
58+ ${ data . examples ? documentExamples ( data ) : '' }
7759
78- ${ data . description || "" }
60+ ${ data . description || '' }
7961
80- ${ data . deprecated ? documentDeprecated ( data ) : "" }
62+ ${ data . deprecated ? documentDeprecated ( data ) : '' }
8163
82- ${ data . params ? documentParams ( data ) : "" }
64+ ${ data . params ? documentParams ( data ) : '' }
8365
84- ${ data . returns ? documentReturn ( data ) : "" }
66+ ${ data . returns ? documentReturn ( data ) : '' }
8567` ;
8668}
8769
@@ -106,18 +88,18 @@ function documentDeprecated(data) {
10688
10789function documentParams ( data ) {
10890 const params = data . params . map (
109- ( param ) => `- \`${ param . name } \` (\`${ param . type . names . join ( "|" ) } \`)
91+ ( param ) => `- \`${ param . name } \` (\`${ param . type . names . join ( '|' ) } \`)
11092${ param . description }
111- `
93+ ` ,
11294 ) ;
11395 return `### Parameters
114- ${ params . join ( "\n" ) }
96+ ${ params . join ( '\n' ) }
11597` ;
11698}
11799
118100function documentReturn ( data ) {
119101 return `### Return Value
120- - (\`${ data . returns [ 0 ] . type . names . join ( "|" ) } \`)
102+ - (\`${ data . returns [ 0 ] . type . names . join ( '|' ) } \`)
121103${ data . returns [ 0 ] . description }
122104` ;
123105}
@@ -135,4 +117,3 @@ for (const file of publicClassFiles) {
135117for ( const file of publicTypedefFiles ) {
136118 generateTypedefMarkdown ( file ) ;
137119}
138-
0 commit comments