/
styleguide.config.js
93 lines (81 loc) 路 2.37 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
const path = require('path');
const glob = require('fast-glob');
const camelCase = require('lodash/camelCase');
const upperFirst = require('lodash/upperFirst');
const docgenTypescript = require('react-docgen-typescript');
const sections = [
{
name: 'Lunar',
content: './guide/README.md',
},
];
const aliases = {
':core': path.join(__dirname, 'packages/core/src'),
':icons': path.join(__dirname, 'packages/icons/src'),
};
glob
.sync('./packages/*/', {
absolute: true,
onlyDirectories: true,
})
.forEach(filePath => {
const folder = path.basename(filePath);
const { name } = require(path.join(filePath, 'package.json'));
if (filePath.includes('metrics') || filePath.includes('test-utils')) {
return;
}
sections.push({
name: upperFirst(camelCase(folder)),
content: `packages/${folder}/GUIDE.md`,
components: `packages/${folder}/src/components/!(private)/+([a-zA-Z]).tsx`,
sectionDepth: 1,
});
// Use source files so we don't have duplicate and or stale components
aliases[`${name}$`] = `${name}/src`;
aliases[`${name}/lib`] = `${name}/src`;
});
function getPathImport(component) {
let importPath = component
.replace('packages/', '')
.replace('src/', 'lib/')
.replace('/index.tsx', '')
.replace('.tsx', '');
importPath = `lunar-${importPath}`.replace('lunar-core', 'lunar');
const parts = importPath.split('lib/')[1].split('/');
const name = parts[parts.length - 1];
if (parts.length === 3) {
return `import { ${name} } from '@airbnb/${path.dirname(importPath)}'`;
}
return `import ${name} from '@airbnb/${importPath}'`;
}
module.exports = {
title: 'Lunar',
usageMode: 'collapse',
exampleMode: 'collapse',
pagePerSection: true,
skipComponentsWithoutExample: true,
getComponentPathLine: getPathImport,
propsParser: filePath => docgenTypescript.withCustomConfig('./tsconfig.json').parse(filePath),
styleguideDir: 'public',
sections,
require: [path.join(__dirname, 'guide/setup.js')],
moduleAliases: aliases,
webpackConfig: {
module: {
rules: [
{
test: /\.tsx?$/,
exclude: /node_modules/,
loader: 'babel-loader',
},
{
test: /\.(png|jpg|jpeg)$/,
loader: 'url-loader',
},
],
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx', '.json'],
},
},
};