(filePath: string)
| 7 | const reactDocs = require('react-docgen'); |
| 8 | |
| 9 | export default function parse(filePath: string): IMaterialParsedModel[] { |
| 10 | if (!filePath) return []; |
| 11 | const fileContent = loadFile(filePath); |
| 12 | const result = reactDocs.parse( |
| 13 | fileContent, |
| 14 | (ast: any) => { |
| 15 | ast.__path = filePath; |
| 16 | return resolver(ast); |
| 17 | }, |
| 18 | handlers, |
| 19 | { |
| 20 | filename: filePath, |
| 21 | }, |
| 22 | ); |
| 23 | const coms = result.reduce((res: any[], info: any) => { |
| 24 | if (!info || !info.props) return res; |
| 25 | const props = Object.keys(info.props).reduce((acc: any[], name) => { |
| 26 | try { |
| 27 | const item: any = transformItem(name, info.props[name]); |
| 28 | acc.push(item); |
| 29 | } catch (e) { |
| 30 | // TODO |
| 31 | } |
| 32 | return acc; |
| 33 | }, []); |
| 34 | res.push({ |
| 35 | componentName: info.displayName, |
| 36 | props, |
| 37 | meta: info.meta || {}, |
| 38 | }); |
| 39 | return res; |
| 40 | }, []); |
| 41 | return coms; |
| 42 | } |
no test coverage detected
searching dependent graphs…