Skip to content

Commit d34c6e2

Browse files
committed
feat: upgrade to react-docgen-typescript v2
BREAKING CHANGE: - upgrade to react-docgen-typescript v2 - rework exports
1 parent 3278ff2 commit d34c6e2

14 files changed

+22995
-8880
lines changed

.eslintrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": ["@djthoms/eslint-config", "@djthoms/eslint-config/typescript"]
3+
}

.github/workflows/on_push.yml

+23-19
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
1-
on: [push, pull_request]
2-
name: Build PR & Push
1+
name: Release
2+
on:
3+
push:
4+
branches:
5+
- main
36
jobs:
4-
build:
5-
runs-on: ubuntu-latest
7+
release:
8+
name: Release
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout
12+
uses: actions/checkout@v3
13+
with:
14+
fetch-depth: 0
15+
- name: Setup Node.js
16+
uses: actions/setup-node@v3
17+
with:
18+
node-version: 16
19+
- name: Install dependencies
20+
run: npm ci
21+
- name: Release
622
env:
7-
HUSKY: 0
8-
strategy:
9-
matrix:
10-
node-version: [14.x]
11-
steps:
12-
- uses: actions/checkout@v2
13-
- name: Use Node.js ${{ matrix.node-version }}
14-
uses: actions/setup-node@v2
15-
with:
16-
node-version: ${{ matrix.node-version }}
17-
- name: npm install, lint, and build
18-
run: |
19-
npm ci
20-
npm run lint
21-
npm run build
23+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
24+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
25+
run: npx semantic-release

.github/workflows/on_release.yml

-21
This file was deleted.

.husky/commit-msg

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env sh
2+
. "$(dirname -- "$0")/_/husky.sh"
3+
4+
npx --no -- commitlint --edit "${1}"

.releaserc.json

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"branches": ["main"],
3+
"plugins": [
4+
"@semantic-release/commit-analyzer",
5+
[
6+
"@semantic-release/release-notes-generator",
7+
{
8+
"preset": "conventionalcommits",
9+
"parserOpts": {
10+
"noteKeywords": ["BREAKING CHANGE", "BREAKING CHANGES", "BREAKING"]
11+
},
12+
"writerOpts": {
13+
"commitsSort": ["subject", "scope"]
14+
}
15+
}
16+
],
17+
[
18+
"@semantic-release/changelog",
19+
{
20+
"changelogFile": "CHANGELOG.md"
21+
}
22+
],
23+
"@semantic-release/github",
24+
"@semantic-release/npm",
25+
[
26+
"@semantic-release/git",
27+
{
28+
"assets": ["package.json", "package-lock.json", "CHANGELOG.md"],
29+
"message": "chore(release): ${nextRelease.version} [skip ci]"
30+
}
31+
]
32+
]
33+
}

.swcrc

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"$schema": "https://json.schemastore.org/swcrc",
3+
"sourceMaps": true,
4+
"module": {
5+
"type": "es6"
6+
},
7+
"jsc": {
8+
"target": "es2019",
9+
"parser": {
10+
"syntax": "typescript",
11+
"tsx": true
12+
},
13+
"transform": {
14+
"react": {
15+
"runtime": "automatic"
16+
}
17+
}
18+
}
19+
}

README.md

+62-67
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ A Docusaurus 2.x plugin that help generate and consume auto-generated docs from
88
Grab from NPM and install along with `react-docgen-typescript`:
99

1010
```sh
11-
npm i docusaurus-plugin-react-docgen-typescript react-docgen-typescript # or
12-
yarn add docusaurus-plugin-react-docgen-typescript react-docgen-typescript
11+
npm i docusaurus-plugin-react-docgen-typescript react-docgen-typescript@2 # or
12+
yarn add docusaurus-plugin-react-docgen-typescript react-docgen-typescript@2
1313
```
1414

1515
## Usage
@@ -19,29 +19,29 @@ with full glob support :+1:.
1919

2020
```js
2121
module.exports = {
22-
// ...
23-
plugins: [
24-
[
25-
'docusaurus-plugin-react-docgen-typescript',
26-
{
27-
// pass in a single string or an array of strings
28-
src: ['path/to/**/*.tsx', '!path/to/**/*test.*'],
29-
global: true,
30-
parserOptions: {
31-
// pass parserOptions to react-docgen-typescript
32-
// here is a good starting point which filters out all
33-
// types from react
34-
propFilter: (prop, component) => {
35-
if (prop.parent) {
36-
return !prop.parent.fileName.includes('@types/react');
37-
}
38-
39-
return true;
40-
},
41-
},
42-
},
43-
],
22+
// ...
23+
plugins: [
24+
[
25+
'docusaurus-plugin-react-docgen-typescript',
26+
{
27+
// pass in a single string or an array of strings
28+
src: ['path/to/**/*.tsx', '!path/to/**/*test.*'],
29+
global: true,
30+
parserOptions: {
31+
// pass parserOptions to react-docgen-typescript
32+
// here is a good starting point which filters out all
33+
// types from react
34+
propFilter: (prop, component) => {
35+
if (prop.parent) {
36+
return !prop.parent.fileName.includes('@types/react');
37+
}
38+
39+
return true;
40+
},
41+
},
42+
},
4443
],
44+
],
4545
};
4646
```
4747

@@ -58,51 +58,46 @@ Using the default settings, annotations are stored inside of the `.docusaurus` d
5858
Most of the time props will want to be shown as API information to a particular component. For
5959
convenience, we can use a simple hook from this package to dynamically import `.json` files:
6060

61-
```jsx
62-
import * as React from 'react';
63-
import { useDynamicImport } from 'docusaurus-plugin-react-docgen-typescript/pkg/dist-src/hooks/useDynamicImport';
61+
```tsx
62+
import { useDynamicImport } from 'docusaurus-plugin-react-docgen-typescript/dist/esm/hooks';
6463

6564
export const PropTable = ({ name }) => {
66-
const props = useDynamicImport(name);
67-
68-
if (!props) {
69-
return null;
70-
}
71-
72-
return (
73-
<table>
74-
<thead>
75-
<tr>
76-
<th>Name</th>
77-
<th>Type</th>
78-
<th>Default Value</th>
79-
<th>Required</th>
80-
<th>Description</th>
81-
</tr>
82-
</thead>
83-
<tbody>
84-
{Object.keys(props).map(key => {
85-
return (
86-
<tr key={key}>
87-
<td>
88-
<code>{key}</code>
89-
</td>
90-
<td>
91-
<code>{props[key].type?.name}</code>
92-
</td>
93-
<td>
94-
{props[key].defaultValue && (
95-
<code>{props[key].defaultValue.value}</code>
96-
)}
97-
</td>
98-
<td>{props[key].required ? 'Yes' : 'No'}</td>
99-
<td>{props[key].description}</td>
100-
</tr>
101-
);
102-
})}
103-
</tbody>
104-
</table>
105-
);
65+
const props = useDynamicImport(name);
66+
67+
if (!props) {
68+
return null;
69+
}
70+
71+
return (
72+
<table>
73+
<thead>
74+
<tr>
75+
<th>Name</th>
76+
<th>Type</th>
77+
<th>Default Value</th>
78+
<th>Required</th>
79+
<th>Description</th>
80+
</tr>
81+
</thead>
82+
<tbody>
83+
{Object.keys(props).map(key => {
84+
return (
85+
<tr key={key}>
86+
<td>
87+
<code>{key}</code>
88+
</td>
89+
<td>
90+
<code>{props[key].type?.name}</code>
91+
</td>
92+
<td>{props[key].defaultValue && <code>{props[key].defaultValue.value}</code>}</td>
93+
<td>{props[key].required ? 'Yes' : 'No'}</td>
94+
<td>{props[key].description}</td>
95+
</tr>
96+
);
97+
})}
98+
</tbody>
99+
</table>
100+
);
106101
};
107102
```
108103

commitlint.config.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/* eslint-disable no-undef */
2+
// eslint-disable-next-line id-denylist
3+
module.exports = { extends: ['@commitlint/config-conventional'] };

0 commit comments

Comments
 (0)