-
Notifications
You must be signed in to change notification settings - Fork 19
/
styleguide.config.js
executable file
·53 lines (51 loc) · 1.43 KB
/
styleguide.config.js
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
43
44
45
46
47
48
49
50
51
52
53
const path = require('path');
const packageJSON = require('./package.json');
const os = require('os');
const fs = require('fs');
// 组件目录
const componentsPath = path.resolve(__dirname, './components/');
const dir = fs.readdirSync(componentsPath);
const dirSet = new Set(dir);
// 删除非组件目录
dirSet.delete('styles');
dirSet.delete('template');
dirSet.delete('utils');
dirSet.delete('index.tsx');
dirSet.delete('Hover');
dirSet.delete('Ripple');
dirSet.delete('Pop');
const componentStr = Array.from(dirSet).join(',');
module.exports = {
title: packageJSON.name,
// 组件目录首字母大写
components: 'components/[A-Z]*/index.tsx',
propsParser: require('react-docgen-typescript').parse,
getComponentPathLine(componentPath) {
let name;
// 提取组件名称
if (os.platform() !== 'win32') {
name = /components\/([A-Z]\w*)\/index\.tsx/.exec(componentPath)[1];
} else {
name = /components\\([A-Z]\w*)\\index\.tsx/.exec(componentPath)[1];
}
return `import { ${name} } from '${packageJSON.name}';`;
},
require: [
path.resolve(__dirname, './components/styles/index.less'),
],
sections: [
{
name: '介绍',
content: 'docs/intro.md'
},
{
name: '通用组件',
components: `components/{${componentStr}}/index.tsx`,
},
{
name: '特效组件',
content: 'docs/effects.md',
components: 'components/{Hover,Ripple}/index.tsx',
},
],
};