forked from alibaba/lowcode-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
42 lines (40 loc) · 1.06 KB
/
index.ts
File metadata and controls
42 lines (40 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { transformItem } from '../transform';
import { IMaterialParsedModel } from '../../types';
import { loadFile } from '../../utils';
import resolver from './resolver';
import handlers from './handlers';
const reactDocs = require('react-docgen');
export default function parse(filePath: string): IMaterialParsedModel[] {
if (!filePath) return [];
const fileContent = loadFile(filePath);
const result = reactDocs.parse(
fileContent,
(ast: any) => {
ast.__path = filePath;
return resolver(ast);
},
handlers,
{
filename: filePath,
},
);
const coms = result.reduce((res: any[], info: any) => {
if (!info || !info.props) return res;
const props = Object.keys(info.props).reduce((acc: any[], name) => {
try {
const item: any = transformItem(name, info.props[name]);
acc.push(item);
} catch (e) {
// TODO
}
return acc;
}, []);
res.push({
componentName: info.displayName,
props,
meta: info.meta || {},
});
return res;
}, []);
return coms;
}