https://github.com/alecaivazis/react-docs
A utility to generate documentation for every component exported by a single file
https://github.com/alecaivazis/react-docs
documentation documentation-generator flowtype react
Last synced: about 1 month ago
JSON representation
A utility to generate documentation for every component exported by a single file
- Host: GitHub
- URL: https://github.com/alecaivazis/react-docs
- Owner: AlecAivazis
- License: mit
- Created: 2018-04-21T22:43:42.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-05-21T06:58:40.000Z (about 8 years ago)
- Last Synced: 2025-04-04T17:50:28.779Z (about 1 year ago)
- Topics: documentation, documentation-generator, flowtype, react
- Language: JavaScript
- Size: 245 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# react-docs
A utility to generate documentation for every component exported by a single file
[](https://travis-ci.com/AlecAivazis/react-docs)
## Usage
The primary usecase for `react-docs` is to collect a description of every component
exported by a particular module. Currently `react-docs` only supports collecting prop
information by looking for FlowType definitions. For example:
```javascript
import { collectExports } from 'react-docs'
// the path of the root index.js of a package/module that we want to document
const { components } = await collectExports('/absolute/path/to/my/package/index.js')
// do something with the list of components
console.log(components)
```
The description of each component is returned as an object of the form:
```javascript
{
filepath: String // the absolute path to the component declaration
props: {
prop1: {
value: String // a pretty printed string of the flow definition
required: Boolean // whether the prop is required or not
nullable: Boolean // whether `null` is a valid value
}
}
}
```
note: The prop table for the exported types is also returned under the `types` field.
### Aliasing global packages
By default (for now), `react-docs` will ignore types imported from global packages. In order to provide
a location to retrieve definitions from a global package, you can pass a second argument to `collectExports`
that provides location aliases, for example:
```javascript
await collectExports('/absolute/path/to/my/package/index.js', {
alias: {
"quark-core": path.resolve(__dirname, "node_modules", "quark-core", "src", "index.js")
}
})
```