22
33'use strict'
44
5- const fs = require ( 'node:fs' ) . promises
6- const path = require ( 'node:path' )
7- const globby = require ( 'globby' )
8- const docgen = require ( 'react-docgen-typescript' )
5+ import { globby } from 'globby'
6+ import { writeFile } from 'node:fs/promises'
7+ import path from 'node:path'
8+ import { fileURLToPath } from 'node:url'
9+ import { parse } from 'react-docgen-typescript'
10+
11+ const __dirname = path . dirname ( fileURLToPath ( import . meta. url ) )
912
1013const GLOB = [
1114 '**/src/**/*.tsx' ,
@@ -79,9 +82,9 @@ async function createMdx(file, filename, name, props) {
7982 const deprecated = value . tags . deprecated ? ` **_Deprecated ${ value . tags . deprecated } +_**` : ''
8083 const description = value . description || '-'
8184 const type = value . type
82- ? ( value . type . name . includes ( 'ReactElement' )
85+ ? value . type . name . includes ( 'ReactElement' )
8386 ? 'ReactElement'
84- : value . type . name )
87+ : value . type . name
8588 : ''
8689 const defaultValue = value . defaultValue
8790 ? value . defaultValue . value . replace ( 'undefined' , '-' )
@@ -97,13 +100,11 @@ async function createMdx(file, filename, name, props) {
97100 index ++
98101 }
99102
100- await fs
101- . writeFile ( `content/api/${ filename } .api.mdx` , content , {
102- encoding : 'utf8' ,
103- } )
104- . then ( ( ) => {
105- console . log ( `File created: ${ filename } .api.mdx` )
106- } )
103+ await writeFile ( `content/api/${ filename } .api.mdx` , content , {
104+ encoding : 'utf8' ,
105+ } ) . then ( ( ) => {
106+ console . log ( `File created: ${ filename } .api.mdx` )
107+ } )
107108}
108109
109110async function main ( ) {
@@ -113,7 +114,8 @@ async function main() {
113114 await Promise . all (
114115 files . map ( ( file ) => {
115116 console . log ( file )
116- const props = docgen . parse ( file , options )
117+ // const props = docgen.parse(file, options)
118+ const props = parse ( file , options )
117119 if ( props && typeof props [ 0 ] !== 'undefined' ) {
118120 const filename = path . basename ( file , '.tsx' )
119121 createMdx ( file , filename , props [ 0 ] . displayName , props [ 0 ] . props )
0 commit comments