Created
May 2, 2017 07:16
-
-
Save GrtDev/184e10ac7435e62da24d797a77c9ddba to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require( 'path' ) | |
const fs = require( 'fs' ) | |
const assign = require( 'lodash/assign' ) | |
const packageJson = require( '../package.json' ) | |
const webpackConfig = require( '../webpack/webpack.config' ) | |
const WebpackIsomorphicToolsPlugin = require( 'webpack-isomorphic-tools/plugin' ) | |
const rootProject = process.cwd() | |
const rootComponents = path.resolve( rootProject, './src/components/' ) | |
const ignoreComponentDirectories = [ 'pages', 'templates', 'theme' ] | |
const styleguideConfig = { | |
title : `${packageJson.name} - Styleguide`, | |
defaultExample : false, | |
skipComponentsWithoutExample: false, | |
highlightTheme : 'dracula', | |
styleguideDir : path.join( __dirname, '../styleguide' ), | |
sections : [{ | |
name : 'App settings', | |
components: './src/components/App.js', | |
sections : [{ | |
name : 'Theme', | |
components: './src/components/theme/overview/**/index.js', | |
}], | |
}], | |
webpackConfig: assign( | |
{}, | |
webpackConfig, | |
{ | |
plugins: webpackConfig.plugins.filter( plugin => !( plugin instanceof WebpackIsomorphicToolsPlugin ) ), | |
output : { | |
path : path.join( __dirname, '../build/styleguide' ), | |
filename : '[name].[hash].js', | |
publicPath: '/', | |
}, | |
} | |
), | |
require: [ | |
'babel-polyfill', | |
], | |
} | |
function getDirectories( srcpath ) { | |
return fs.readdirSync( srcpath ) | |
.filter( ( file ) => fs.statSync( path.join( srcpath, file ) ).isDirectory() ) | |
} | |
/** | |
* Add all subdirectories as sections | |
*/ | |
getDirectories( rootComponents ) | |
.filter( dirname => ignoreComponentDirectories.indexOf( dirname ) === -1 ) | |
.sort() | |
.forEach( ( directoryName ) => { | |
const introPath = path.resolve( rootComponents, directoryName, './README.md' ) | |
const section = { | |
name : directoryName, | |
components: `${path.resolve( rootComponents, directoryName )}/*/**/index.js`, | |
} | |
if ( fs.existsSync( introPath ) ) { | |
section.content = introPath | |
} | |
styleguideConfig.sections.push( section ) | |
} ) | |
module.exports = styleguideConfig |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment