Getting started with the Command Line Interface (CLI)
Setup
The CLI can be used directly, installed globally, or installed in any project as a dependency.
No installation
In order to use it directly any of these commands will work:
npx @react-docgen/cli --help
Install
Installing the CLI can be done with any available package manager:
npm install --save @react-docgen/cli
Usage
For basic usage, you need to provide a glob or path to a file that includes a
react component. The result will be printed to the stdout
and in case there
are errors or warnings while analyzing the file, these will be printed to
stderr
.
The result will be an array of Documentation objects, stringified to JSON.
react-docgen ./src/components/Button.tsx
Multiple files can be analyzed at once
react-docgen ./src/components/Button.tsx ./src/components/Label.tsx
Or a glob can be used to include multiple files
react-docgen ./src/components/**/*.tsx
The output can be written into a file instead of directly outputting it.
Warnings and errors will still be written to stderr
.
react-docgen -o output.json ./src/components/Button.tsx
The CLI supports a lot more advanced options and for a full list checkout the reference page