Badoo Styleguide
Work in progress: This is a styleguide used by the frontend team in Badoo, at the moment we are in the process of open sourcing it. Just working out some issues, cleaning up the API and adding documentation.
To Do
Usage
Getting started
Add styleguide dependency
yarn add badoo-styleguide --dev
Create a styleguide config
Create a file called styleguide.config.js
in your project (The name doesn't really matter).
Add the following content to the file
module.exports = {
isReactNative: false,
hasResizableSandbox: false,
sandboxMinWidth: 320,
sandboxMaxWidth: '100%',
isSpecificationPath(componentMeta, path) {
return path.indexOf(`${componentMeta.fileNameWithoutPrefix}.spec`) !== -1;
},
browserSetup() {
window.parameters = true;
}
getComponentWrapper() {
return require('MyComponent');
},
getSectionComponents({ path }) {
return [
{
components: [path.resolve('src/components/component/component')],
},
{
components: [path.resolve('src/components/error-boundary/error-boundary')],
},
];
},
getSections() {
return [
{
name: 'MyComponentSection',
components: [
require('MyComponent'),
],
},
];
},
getComponentRoots({ path }) {
return [
path.resolve(cwd, 'src')
];
},
getExceptionForLoaders({ path }) {
return {
jsLoader: path.resolve(cwd, 'src'),
tsLoader: /src/,
};
},
getWebpackConfig({ path }) {
const cwd = path.resolve(__dirname, '.');
return {
resolve: {
modules: [
path.resolve(cwd, 'src/'),
path.resolve(cwd, 'node_modules/'),
],
}
};
}
}
Running and compiling
The styleguide can be run as a local dev server or be compiled if you want to serve it from another host.
Running
yarn badoo-styleguide --config=PATH_TO_STYLEGUIDE_CONFIG.js
Note: Styleguide benefits from caching results of initial build. It makes all subsequents recompilations much faster.
Compiling
yarn badoo-styleguide --config=PATH_TO_STYLEGUIDE_CONFIG.js --buildDir=dist/
Or add it to your package.json "scripts" section
{
"scripts": {
"styleguide": "badoo-styleguide --config=PATH_TO_STYLEGUIDE_CONFIG.js",
"styleguide:compile": "badoo-styleguide --config=PATH_TO_STYLEGUIDE_CONFIG.js --buildDir=dist/"
}
}
The buildDir parameter switches off webpack-server and caching.
Note: The buildDir is resolved relative to where you ran "yarn" from
Examples
Debugging
Pass --debug flag to the command line to get additional debug information.
yarn badoo-styleguide --config=PATH_TO_STYLEGUIDE_CONFIG.js --debug