-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstyleguide.config.js
94 lines (91 loc) · 2.64 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
const path = require("path")
const findUp = require("find-up")
const packages = [
"components",
"react-design-tokens",
"react-focus-within",
"with-selector",
"mixins"
]
const file = (filepath) => path.join(__dirname, filepath)
module.exports = {
sections: [
{
name: "Introduction",
content: "./Readme.md"
},
{
name: "Packages",
sections: packages.map((pkg) => ({
name: pkg,
components: `packages/${pkg}/**/[A-Z]*.{js,ts,jsx,tsx}`
})),
sectionDepth: 1
}
],
styleguideComponents: {
Wrapper: file(".styleguidist/StyleguideProvider.tsx")
},
require: [file(".styleguidist/setup.js")],
propsParser: require("react-docgen-typescript").withCustomConfig(file("tsconfig.json"), {
propFilter(prop) {
if (prop.parent) {
return (
!prop.parent.fileName.includes("node_modules") ||
prop.parent.fileName.includes("@types/styled-system")
)
}
return true
},
componentNameResolver: (exp, source) =>
exp.getName() === "StyledComponentClass" &&
require("react-docgen-typescript").getDefaultExportForFile(source)
}).parse,
webpackConfig: {
module: {
rules: [
{
test: /\.(jsx?|tsx?)$/,
exclude: /node_modules/,
loader: "babel-loader"
}
]
}
},
getExampleFilename(componentPath) {
// Try to locate ${componentName}.md in the same directory
// and if not found fallback to Readme.md
const componentName = path.basename(componentPath, path.extname(componentPath))
const examplePath = findUp.sync(`${componentName}.md`, { cwd: componentPath })
if (examplePath) {
return examplePath
}
const readmePath = findUp.sync("Readme.md", { cwd: componentPath })
console.log(readmePath)
if (readmePath) {
return readmePath
}
console.error(`Could not find example file for ${componentPath}`)
},
getComponentPathLine(componentPath) {
const componentName = path.basename(componentPath, path.extname(componentPath))
const pkgPath = findUp.sync("package.json", { cwd: componentPath })
if (!pkgPath) {
console.error(`Could not find \`package.json\` for ${componentName}`)
return ""
}
const { name } = require(pkgPath)
return `import { ${componentName} } from "${name}"`
},
exampleMode: "expand",
usageMode: "collapse",
showSidebar: true,
pagePerSection: true,
skipComponentsWithoutExample: true,
ribbon: {
// Link to open on the ribbon click (required)
url: "https://github.com/component-driven/ui",
// Text to show on the ribbon (optional)
text: "Fork me on GitHub"
}
}