-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathstyleguide.config.js
146 lines (137 loc) · 3.8 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
const fs = require('fs')
const path = require('path')
const pck = require('./package')
const yml = require('./styleguide/yml')
const webpackConfig = require('./webpack.config.js')
// 移除压缩代码,es6代码压缩存在兼容问题。ps:懒的替换压缩插件,干掉好了
webpackConfig.optimization = {}
module.exports = {
title: '移动端 - 组件',
serverPort: 6060,
styleguideDir: 'site',
ignore: [
'components/style',
'components/tools',
'components/**/Example.tsx'
],
/**
* 文档提示参数可为数组,但实际打包编译存在错误提示,但不影响使用
* https://react-styleguidist.js.org/docs/configuration.html#assetsdir
* assetsDir: ['./styleguide', './site']
* */
assetsDir: process.env.RUN_ENV === 'DOC' ? './styleguide' : ['./styleguide', 'site'],
// components: ['components/**/*.{js,jsx,ts,tsx}'],
moduleAliases: {
[pck.name]: __dirname
},
require: [
path.join(__dirname, 'styleguide/style/index.scss'),
path.join(__dirname, 'components/style/index.scss')
],
template: {
favicon: 'https://sayll.com/images/favicon.ico',
head: {
scripts: [],
links: [
// { rel: 'stylesheet', href: ''}
]
}
},
pagePerSection: true,
sections: [
{
name: '介绍',
content: 'docs/Introduction.md'
},
{
name: '快速上手',
content: 'docs/GetStarted.md'
},
// {
// name: '扫描演示',
// usageMode: 'hide',
// exampleMode: 'hide',
// content: 'docs/Mobile.md'
// },
...Object.keys(yml).map(key => ({
name: key,
usageMode: 'collapse',
exampleMode: 'collapse',
components: yml[key].map(component => `components/${component}/[A-Z]*.tsx`),
sectionDepth: 2
}))
],
styleguideComponents: { // 改写布局
// Usage: path.join(__dirname, 'styleguide/components/Usage')
},
ribbon: {
url: 'https://github.com/rc-mobile/rcm-mobile',
text: '查看源码'
},
// https://react-styleguidist.js.org/docs/configuration.html#theme
theme: {
color: {
link: '#59b4aa',
linkHover: '#009688',
codeBackground: '#f8fbfb',
sidebarBackground: '#fefefe',
border: '#e6f0ee'
}
},
resolver: require('react-docgen').resolver.findAllComponentDefinitions,
propsParser: (filePath, source, resolver, handlers) => {
const result = require('react-docgen-typescript').withCustomConfig(
'./tsconfig.json',
{
propFilter: {
skipPropsWithoutDoc: true
}
}
).parse(filePath, source, resolver, handlers)
return result.map(component => {
const { props } = component
const mappedProps = Object.values(props).reduce((previous, prop) => {
const { name } = prop
if (!!~name.indexOf('aria-')) return previous
return {
...previous,
[name]: {
...prop,
type: {
name: prop.type.name.replace('| undefined', '')
}
}
}
}, {})
return {
...component,
props: mappedProps
}
})
},
/**
* 展示源码
* https://react-styleguidist.js.org/docs/cookbook.html#how-to-display-the-source-code-of-any-file
* */
updateExample(props, exampleFilePath) {
const { settings, lang } = props
if (typeof settings.file === 'string') {
const filepath = path.resolve(exampleFilePath, settings.file)
settings.static = true
delete settings.file
return {
content: fs.readFileSync(filepath, 'utf8'),
settings,
lang
}
}
return props
},
// 优化文档中的组件名
getComponentPathLine(componentPath) {
const name = path.basename(componentPath, '.tsx')
return `import { ${name} } from '${pck.name}';`
},
// webpack配置
webpackConfig
}