# sourcejs-react-styleguidist

> SourceJS integration plugin for react-styleuguidist

Latest version **0.5.0** (published 2016-05-31) · MIT license · 0 weekly downloads

## Install

```sh
npm install sourcejs-react-styleguidist
pnpm add sourcejs-react-styleguidist
yarn add sourcejs-react-styleguidist
bun add sourcejs-react-styleguidist
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.5.0 |
| Published | 2016-05-31 |
| First published | 2015-11-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.12.0 |
| Dependencies | 33 |
| Known vulnerabilities | 0 (+22 in 6 direct dependencies) |
| Install scripts | no |
| GitHub stars | 17 |
| Maintainers | sourcejs |
| Keywords | sourcejs, react, jsx, styleguide, style guide, documentation, docs, component, components |

## Links

- npm: https://www.npmjs.com/package/sourcejs-react-styleguidist
- Repository: https://github.com/sourcejs/sourcejs-react-styleguidist
- Issues: https://github.com/sourcejs/sourcejs-react-styleguidist/issues
- npm.io page: https://npm.io/package/sourcejs-react-styleguidist

## Dependencies (33)

- [glob](https://npm.io/package/glob.md) 7.0.3
- [chalk](https://npm.io/package/chalk.md) 1.1.3
- [react](https://npm.io/package/react.md) ^0.14.8
- [findup](https://npm.io/package/findup.md) 0.1.5
- [lodash](https://npm.io/package/lodash.md) 4.12.0
- [marked](https://npm.io/package/marked.md) 0.3.5
- [express](https://npm.io/package/express.md) 4.13.3
- [webpack](https://npm.io/package/webpack.md) 1.13.1
- [minimist](https://npm.io/package/minimist.md) 1.2.0
- [cross-env](https://npm.io/package/cross-env.md) ^1.0.7
- [react-dom](https://npm.io/package/react-dom.md) ^0.14.8
- [babel-core](https://npm.io/package/babel-core.md) ~6.9.0
- [codemirror](https://npm.io/package/codemirror.md) 5.8.0
- [css-loader](https://npm.io/package/css-loader.md) 0.23.1
- [prettyjson](https://npm.io/package/prettyjson.md) 1.1.3
- [babel-loader](https://npm.io/package/babel-loader.md) 6.2.4
- [redbox-react](https://npm.io/package/redbox-react.md) 1.1.1
- [sanitize.css](https://npm.io/package/sanitize.css.md) 3.0.0
- [style-loader](https://npm.io/package/style-loader.md) 0.13.0
- [webpack-merge](https://npm.io/package/webpack-merge.md) 0.12.0
- [postcss-loader](https://npm.io/package/postcss-loader.md) 0.9.1
- [react-codemirror](https://npm.io/package/react-codemirror.md) 0.2.6
- [babel-preset-react](https://npm.io/package/babel-preset-react.md) ^6.5.0
- [babel-preset-es2015](https://npm.io/package/babel-preset-es2015.md) ^6.9.0
- [react-transform-hmr](https://npm.io/package/react-transform-hmr.md) 1.0.4
- [babel-preset-stage-0](https://npm.io/package/babel-preset-stage-0.md) ^6.5.0
- [webpack-dev-middleware](https://npm.io/package/webpack-dev-middleware.md) 1.6.1
- [webpack-hot-middleware](https://npm.io/package/webpack-hot-middleware.md) 2.10.0
- [babel-preset-react-hmre](https://npm.io/package/babel-preset-react-hmre.md) ^1.1.1
- [postcss-advanced-variables](https://npm.io/package/postcss-advanced-variables.md) 1.2.2
- [extract-text-webpack-plugin](https://npm.io/package/extract-text-webpack-plugin.md) 1.0.1
- [babel-plugin-react-transform](https://npm.io/package/babel-plugin-react-transform.md) 2.0.2
- [react-transform-catch-errors](https://npm.io/package/react-transform-catch-errors.md) 1.0.2

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.5.0 (latest) — 2016-05-31
- 0.4.0 — 2015-11-22
- 0.3.2 — 2015-11-22
- 0.3.1 — 2015-11-17
- 0.3.0 — 2015-11-17
- 0.2.0 — 2015-11-15
- 0.1.0 — 2015-11-15

## README

# React Styleguidist Integration Plugin for SourceJS

[![Build Status](https://travis-ci.org/sourcejs/sourcejs-react-styleguidist.svg?branch=master)](https://travis-ci.org/sourcejs/sourcejs-react-styleguidist)

Fork of React Style Guide generator [react-styleguidist](https://github.com/sapegin/react-styleguidist) with integration to [SourceJS](http://sourcejs.com) platform.

[Original styleguidist example](http://sapegin.github.io/react-styleguidist/).
(example with SourceJS will be available later)

![](https://s3.amazonaws.com/f.cl.ly/items/3i0E1D1L1c1m1s2G1d0y/Screen%20Recording%202015-09-24%20at%2009.49%20AM.gif)

To add automatically generated React props docs use [sourcejs-react-docgen](https://github.com/sourcejs/sourcejs-react-docgen) plugin. Check [SourceJS React bundle example](http://github.com/sourcejs/sourcejs-react-bundle-example) for more insights.

## Installation

```
cd sourcejs-project
npm install sourcejs-react-styleguidist --save
```

Add custom markdown renderer conf into SourceJS `options.js` file:

```javascript
module.exports = {
	core: {
        processMd: {
            languageRenderers: {
                jsx: require('sourcejs-react-styleguidist/core/lang-jsx').processExample
            }
        }
    }
};
```

After re-running your SourceJS app, plugin will be loaded automatically.

### Important configs

Configure path to components in SourceJS `options.js` file:

```javascript
module.exports = {
	plugins: {
		reactStyleguidist: {
			rootDir: './relative/path/to/components',
			components: './**/*.jsx'
		}
	}
};
```

See Configuration section below for the list of available options.

## Documenting components

Examples are written in Markdown where any code blocks will be rendered as a react components. By default any `readme.md` in the component folder is treated as an examples file but you can change it with the `getExampleFilename` option.

	React component example:

	```jsx
	<Button size="large">Push Me</Button>
	```

	Any [Markdown](http://daringfireball.net/projects/markdown/):

	* Foo;
	* bar;
	* baz.

## How it works

SourceJS plugins are loaded together with main application, adding additional initialization steps or changing rendering flow using middleware integration. With this plugin, in development mode, SourceJS in enhanced with webpack middleware, that builds all the React examples on demand and listens to file changes for hot-reloading.

In production mode webpack is not triggered, expecting that bundle is already built (read configuration section for more).

Rendering flow with this plugins looks like this:

* On app start `webpack-dev-middleware` and `webpack-hot-middleware` are loaded from `core/index.js`
* Then happens initial build of `bundle.js` which packs all the components and development tools into one package
* Using custom loaders, webpack gathers info about all component from `readme.md` files, and saves defined code examples
* On Spec page request, common `bundle.js` is loaded onto every page, loading only examples of defined spec
* To determine which component to load from common bundle, all examples are grouped by Spec name, and special middleware (`code/middleware/index.js`) during rendering flow replaces code examples from `readme.md` with special hooks, that are then used as roots to React components
* Using SourceJS as a platform together with this integration plugin you get benefits both from SourceJS ecosystem, and custom client-side rendreding handled by react/webpack and hot module replacement tool

## Configuration

Use SourceJS `options.js` for deep plugin configuration.

* **`enabled`**
  Type: `Boolean`
  Set to `false`, if wan't to disable plugin load with SourceJS app.

* **`preBuild`**
  Type: `Boolean`
  Set to `true`, if you wan't to automatically build webpack bundle in production mode right after app starts.

* **`rootDir`**
  Type: `String`, required
  Your components sources root folder (eg. `./lib`). Should not point to a folder with the `node_modules` folder.

* **`components`**
  Type: `String` or `Function`, required
  - when `String`: a [glob pattern](https://github.com/isaacs/node-glob#glob-primer) that matches all your component modules. Relative to the `rootDir`.
  - when `Function`: function that returns an array of modules.

  If your components look like `components/Button.jsx` or `components/Button/Button.jsx` or `components/Button/index.jsx`:

  ```javascript
  components: './components/**/*.jsx'
  ```

  If your components look like `components/Button/Button.js` + `components/Button/index.js`:

  ```javascript
  components: function(config, glob) {
  	return glob.sync(config.rootDir + '/components/**/*.js').filter(function(module) {
  		return /\/[A-Z][a-z]*\.js$/.test(module);
  	});
  },
  ```

* **`highlightTheme`**
  Type: `String`, default: `base16-light`
  [CodeMirror theme](http://codemirror.net/demo/theme.html) name to use for syntax highlighting in examples.

* **`getExampleFilename`**
  Type: `Function`, default: finds `readme.md` in the component folder
  Function that returns examples file path for a given component path.

  For example, instead of `readme.md` you can use `ComponentName.examples.md`:

  ```javascript
  getExampleFilename: function(componentpath) {
  	return componentpath.replace(/\.jsx?$/,   '.examples.md');
  }
  ```

* **`updateWebpackConfig`**
  Type: `Function`, optional
  Function that allows you to modify Webpack config for style guide:

  ```javascript
  updateWebpackConfig: function(webpackConfig, env) {
  	if (env === 'development') {
  		/* ... modify config ... */
  	}
  	return webpackConfig;
  }
  ```

### Environment settings

Running app with `NODE_ENV=production`, initial webpack build won't be triggered. To properly prepare production environment, first run react-styleguidist build command, and only after that run application:

```
NODE_ENV=production node ./node_modules/sourcejs-react-styleguidist/core/build.js
NODE_ENV=production npm start
```

Note: this command should be ran from SourceJS root folder, where `node_modules` is placed.

Alternatively, you can set `preBuild` to true in plugin configuration, to build webpack bundle once app is ran in production mode. This will require less build steps, but may cause higher load in production environment container.

## Contributing

Everyone is welcome to contribute. Please take a moment to review the [contributing guidelines](contributing.md).

---

## License

The MIT License, see the included [license.md](license.md) file.

---
_Source: https://npm.io/package/sourcejs-react-styleguidist · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
