forked from alfa-laboratory/arui-feather
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstyleguide.config.js
125 lines (104 loc) · 4.15 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
/* eslint strict: [0, "global"] */
/* eslint import/no-extraneous-dependencies: 0 */
'use strict';
const path = require('path');
const { lstatSync, readdirSync } = require('fs');
const merge = require('webpack-merge');
const reactDoc = require('library-utils/react-doc');
const upperCamelCase = require('uppercamelcase');
const WEBPACK_BASE_TEMPLATE = require('./webpack.base');
const reactDocgenTypescript = require('react-docgen-typescript');
const typescriptDocReader = reactDocgenTypescript.withCustomConfig('./tsconfig.json', {});
const config = require('arui-demo');
/* eslint import/no-unresolved: 0 */
const { version } = require('./package');
const PORT = parseInt(process.env.PORT || 8080, 10);
const TITLE = 'arui-feather';
// Prepare styleguidist context https://react-styleguidist.js.org/docs/configuration.html#context
// For share example functionality
const getContext = source => readdirSync(source)
.filter(name => !['lib', 'mq', 'vars', 'font', 'skeleton-mixins'].includes(name))
.map(name => path.join(source, name))
.filter(file => lstatSync(file).isDirectory())
.reduce(
(prev, componentDirName) => {
const componentSourcesFileName = componentDirName.split(path.sep).pop();
const componentName = upperCamelCase(componentSourcesFileName);
prev[componentName] = componentDirName;
return prev;
},
{
PreviewFrame: 'arui-demo/preview-frame'
}
);
const context = getContext(path.join(__dirname, 'src'));
module.exports = {
...config,
title: TITLE,
version,
serverPort: PORT,
skipComponentsWithoutExample: true,
components: './src/*/index.{ts,js}',
propsParser(componentIndexPath) {
const dirPath = path.dirname(componentIndexPath);
const componentName = dirPath.split(path.sep).pop();
const componentPath = path.resolve(dirPath, `${componentName}.jsx`);
if (componentIndexPath && componentIndexPath.endsWith('.ts')) {
const componentPath = path.resolve(dirPath, `${componentName}.tsx`);
const docs = typescriptDocReader.parse(componentPath)[0];
Object.keys(docs.props).forEach((key) => {
const defaultValue = docs.props[key].defaultValue;
if (
defaultValue &&
defaultValue.value !== undefined &&
typeof defaultValue.value !== 'string') {
// TODO: постараться убрать после обновления styleguidist
// почему-то react styleguidist в недрах ожидает string;
// А тут, как и должно приходит true/false
// хачим чтоб работало
defaultValue.value = String(defaultValue.value);
}
});
return docs;
}
return reactDoc(componentPath);
},
getComponentPathLine(filePath) {
const componentDirName = path.dirname(filePath);
const componentSourcesFileName = componentDirName.split(path.sep).pop();
const componentName = upperCamelCase(componentSourcesFileName);
return `import ${componentName} from '${TITLE}/${componentSourcesFileName}';`;
},
getExampleFilename(componentPath) {
return path.resolve(path.dirname(componentPath), './README.md');
},
ignore: ['**/*-test.jsx', '**/*-test.tsx'],
moduleAliases: {
'arui-feather': path.resolve(__dirname, './src/')
},
context,
styleguideDir: path.resolve(__dirname, './demo/styleguide/'),
webpackConfig: merge.smart(WEBPACK_BASE_TEMPLATE, {
resolve: {
extensions: ['.ts', '.tsx']
},
devServer: {
disableHostCheck: true
},
module: {
rules: [
{
test: /\.(ico|xml)$/i,
loader: 'file-loader'
}
]
}
}),
sections: [
{
title: 'Components',
components: ['./src/*/index.ts', './src/*/index.js'],
sectionDepth: 1
}
]
};