import { JSDocTag , Project , PropertySignature } from 'ts-morph' ; import { ComponentDoc , PropDescriptor } from 'vue-docgen-api' ; const project = new Project ( ) ; const formatterTags = ( jsDocsTags ) => { const tags = { } ; jsDocsTags . forEach ( ( tag ) => { const tagName = tag . getTagName ( ) ; tags [ tagName ] = [ { title : tagName , description : tag . getCommentText ( ) , } , ] ; } ) ; return tags ; } ; const formatterProps = ( properties ) => { const props = [ ] ; properties . forEach ( ( p ) => { const jsDocs = p . getJsDocs ( ) [ 0 ] ; if ( ! jsDocs ) { return ; } props . push ( { name : p . getName ( ) , type : { name : p . getTypeNode ( ) ?. getText ( ) || '' , } , description : jsDocs . getDescription ( ) , tags : formatterTags ( jsDocs . getTags ( ) ) , } ) ; } ) ; return props ; } ; export default ( filePath ) => { project . addSourceFileAtPath ( filePath ) ; const sourceFile = project . getSourceFile ( filePath ) ; const componentDocList = [ ] ; if ( sourceFile ) { const interfaces = sourceFile . getInterfaces ( ) ; interfaces . forEach ( ( interfaceDeclaration ) => { const properties = interfaceDeclaration . getProperties ( ) ; const componentDoc = { displayName : interfaceDeclaration . getName ( ) , exportName : interfaceDeclaration . getName ( ) , props : formatterProps ( properties ) , } ; if ( componentDoc . props . length ) { componentDocList . push ( componentDoc ) ; } } ) ; } return componentDocList ; } ;