-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstyleguide.config.js
104 lines (99 loc) · 2.26 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
const fs = require('fs');
const path = require('path');
const glob = require('glob');
const borderedStyle = {
border: '1px solid #e8e8e8',
borderRadius: 3,
padding: 16,
};
const exercises = glob.sync(`${path.join(__dirname, `src/exercises`)}/*`);
// Prepare Markdown file to use as final result:
// 1. Remove ```js ... ``` markers from Markdown
// 2. Replace <></> with a <div /> that looks like a Styleguidist example,
// but without an editor
const markdownToCodeExample = (s) =>
s
.replace(/^```\w*$/gm, '')
.replace(/<>/, `<div style={${JSON.stringify(borderedStyle)}}>`)
.replace(/<\/>/, `</div>`);
const config = {
serverPort: 6061,
title: 'Resilient component libraries in React',
styleguideDir: 'public/styleguide',
assetsDir: 'static',
// Read examples from Component.md files only, not from Readme.md
getExampleFilename: (x) => x.replace(/\.js$/, '.md'),
skipComponentsWithoutExample: true,
pagePerSection: true,
exampleMode: 'expand',
usageMode: 'expand',
styles: {
StyleGuide: {
'@global img': {
maxWidth: '100%',
},
},
},
webpackConfig: {
module: {
rules: [
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/,
options: {
presets: [
[
'@babel/env',
{
modules: false,
},
],
'@babel/react',
],
},
},
],
},
},
updateExample(props, exampleFilePath) {
const { settings, lang } = props;
if (settings && typeof settings.file === 'string') {
const filepath = path.resolve(
path.dirname(exampleFilePath),
settings.file
);
const { file, ...restSettings } = settings;
const rawContent = fs.readFileSync(filepath, 'utf8');
const content =
filepath.endsWith('.md') && lang === 'jsx'
? markdownToCodeExample(rawContent)
: rawContent;
return {
content,
settings: restSettings,
lang,
};
}
return props;
},
// Generate sections for all exercises
sections: exercises.map((folder) => ({
name: path
.basename(folder)
.replace(/^(\d+)-/, '$1. ')
.replace(/_/g, ' '),
sectionDepth: 1,
sections: [
{
name: 'Task',
content: `${folder}/Readme.md`,
},
{
name: 'Exercises',
components: `${folder}/*.js`,
},
],
})),
};
module.exports = config;