@apify/docusaurus-plugin-typedoc-api 4.2.5 → 4.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/styles-8ad572ec.css +44 -0
- package/lib/components/ApiItem.js +53 -29
- package/lib/components/ApiItem.js.map +1 -1
- package/lib/components/ApiItemLayout.js +15 -8
- package/lib/components/ApiItemLayout.js.map +1 -1
- package/lib/components/ApiOptionsLayout.js +35 -0
- package/lib/components/ApiOptionsLayout.js.map +1 -0
- package/lib/components/Comment.js +3 -0
- package/lib/components/Comment.js.map +1 -1
- package/lib/components/Member.js +4 -1
- package/lib/components/Member.js.map +1 -1
- package/lib/components/MemberSignatureBody.js +107 -16
- package/lib/components/MemberSignatureBody.js.map +1 -1
- package/lib/components/MemberSignatureTitle.js +11 -1
- package/lib/components/MemberSignatureTitle.js.map +1 -1
- package/lib/components/Type.js +14 -3
- package/lib/components/Type.js.map +1 -1
- package/lib/index.js +4 -14
- package/lib/index.js.map +1 -1
- package/lib/plugin/data.js +37 -0
- package/lib/plugin/data.js.map +1 -1
- package/package.json +2 -1
- package/src/components/ApiItem.tsx +48 -32
- package/src/components/ApiItemLayout.tsx +11 -6
- package/src/components/ApiOptionsLayout.tsx +22 -0
- package/src/components/Comment.tsx +3 -0
- package/src/components/Member.tsx +6 -2
- package/src/components/MemberSignatureBody.tsx +110 -16
- package/src/components/MemberSignatureTitle.tsx +14 -1
- package/src/components/Type.tsx +20 -3
- package/src/components/styles.css +44 -0
- package/src/index.ts +11 -19
- package/src/plugin/data.ts +36 -1
- package/src/types.ts +5 -1
- package/lib/plugin/python-generator/index.js +0 -23
- package/lib/plugin/python-generator/index.js.map +0 -1
- package/lib/plugin/python-generator/pydoc-markdown.js +0 -72
- package/lib/plugin/python-generator/pydoc-markdown.js.map +0 -1
- package/lib/plugin/python-generator/transform-docs.js +0 -393
- package/lib/plugin/python-generator/transform-docs.js.map +0 -1
- package/src/plugin/python-generator/index.ts +0 -18
- package/src/plugin/python-generator/pydoc-markdown.ts +0 -70
- package/src/plugin/python-generator/transform-docs.ts +0 -417
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
// https://github.com/TypeStrong/typedoc-default-themes/blob/master/src/default/partials/member.signature.body.hbs
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import { Fragment, useContext } from 'react'
|
|
4
|
+
import type { JSONOutput, Models } from 'typedoc';
|
|
5
|
+
import { type GlobalData } from '@docusaurus/types';
|
|
6
|
+
import { usePluginData } from '@docusaurus/useGlobalData';
|
|
4
7
|
import { useMinimalLayout } from '../hooks/useMinimalLayout';
|
|
5
8
|
import type { TSDSignatureReflection } from '../types';
|
|
9
|
+
import { ApiDataContext } from './ApiDataContext';
|
|
6
10
|
import { Comment, hasComment } from './Comment';
|
|
7
11
|
import { CommentBadges, isCommentWithModifiers } from './CommentBadges';
|
|
8
12
|
import { DefaultValue } from './DefaultValue';
|
|
@@ -60,6 +64,46 @@ export function MemberSignatureBody({ hideSources, sig }: MemberSignatureBodyPro
|
|
|
60
64
|
const showParams = !minimal && sig.parameters && sig.parameters.length > 0;
|
|
61
65
|
const showReturn = !minimal && sig.type;
|
|
62
66
|
|
|
67
|
+
const { reflections } = useContext(ApiDataContext);
|
|
68
|
+
const { isPython } = usePluginData('docusaurus-plugin-typedoc-api') as GlobalData;
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
if (isPython) {
|
|
72
|
+
// eslint-disable-next-line
|
|
73
|
+
sig.parameters = sig.parameters?.reduce<typeof sig.parameters>((acc, param) => {
|
|
74
|
+
// @ts-expect-error Silence ts errors
|
|
75
|
+
switch (param.type?.name) {
|
|
76
|
+
case 'Unpack':
|
|
77
|
+
// @ts-expect-error Silence ts errors
|
|
78
|
+
// eslint-disable-next-line
|
|
79
|
+
acc.push(...reflections[param.type.typeArguments[0].target].children.map(x => ({...x, flags: {'keyword-only': true}})));
|
|
80
|
+
break;
|
|
81
|
+
default:
|
|
82
|
+
acc.push(param);
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return acc;
|
|
87
|
+
}, []);
|
|
88
|
+
|
|
89
|
+
// eslint-disable-next-line
|
|
90
|
+
sig.parameters = sig.parameters?.reduce<typeof sig.parameters>((acc, param) => {
|
|
91
|
+
// @ts-expect-error Silence ts errors
|
|
92
|
+
switch (param.type?.name) {
|
|
93
|
+
case 'NotRequired':
|
|
94
|
+
// @ts-expect-error Silence ts errors
|
|
95
|
+
// eslint-disable-next-line
|
|
96
|
+
acc.push({...param, type: param.type.typeArguments[0]});
|
|
97
|
+
break;
|
|
98
|
+
default:
|
|
99
|
+
acc.push(param);
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return acc;
|
|
104
|
+
}, []);
|
|
105
|
+
}
|
|
106
|
+
|
|
63
107
|
return (
|
|
64
108
|
<>
|
|
65
109
|
{!hideSources && <MemberSources reflection={sig} />}
|
|
@@ -85,21 +129,71 @@ export function MemberSignatureBody({ hideSources, sig }: MemberSignatureBodyPro
|
|
|
85
129
|
|
|
86
130
|
<ul className="tsd-parameters">
|
|
87
131
|
{sig.parameters?.map((param) => (
|
|
88
|
-
<
|
|
89
|
-
<
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
132
|
+
<Fragment key={param.id}>
|
|
133
|
+
<li>
|
|
134
|
+
<h5>
|
|
135
|
+
<Flags flags={param.flags} />
|
|
136
|
+
{param.flags?.isRest && <span className="tsd-signature-symbol">...</span>}
|
|
137
|
+
{`${param.name}: `}
|
|
138
|
+
<Type type={param.type} />
|
|
139
|
+
<DefaultValue
|
|
140
|
+
comment={param.comment}
|
|
141
|
+
type={param.type}
|
|
142
|
+
value={param.defaultValue}
|
|
143
|
+
/>
|
|
144
|
+
</h5>
|
|
145
|
+
|
|
146
|
+
<Comment comment={param.comment} />
|
|
147
|
+
</li>
|
|
148
|
+
|
|
149
|
+
{param.type?.type === 'reflection' && (
|
|
150
|
+
<ul key={param.type.declaration.id}>
|
|
151
|
+
{param.type.declaration?.children?.map((reflectionChild) => (
|
|
152
|
+
<li key={reflectionChild.id}>
|
|
153
|
+
<h5>
|
|
154
|
+
<Flags flags={reflectionChild.flags} />
|
|
155
|
+
{reflectionChild.flags?.isRest && <span className="tsd-signature-symbol">...</span>}
|
|
156
|
+
{`${reflectionChild.name}: `}
|
|
157
|
+
<Type type={reflectionChild.type} />
|
|
158
|
+
<DefaultValue
|
|
159
|
+
comment={reflectionChild.comment as unknown as JSONOutput.Comment}
|
|
160
|
+
type={reflectionChild.type}
|
|
161
|
+
value={reflectionChild.defaultValue}
|
|
162
|
+
/>
|
|
163
|
+
</h5>
|
|
164
|
+
|
|
165
|
+
<Comment comment={reflectionChild.comment as unknown as JSONOutput.Comment} />
|
|
166
|
+
</li>
|
|
167
|
+
))}
|
|
168
|
+
</ul>
|
|
169
|
+
)}
|
|
170
|
+
|
|
171
|
+
{param.type?.type === 'union' && (
|
|
172
|
+
((param.type.types.filter(
|
|
173
|
+
(unionType) => unionType.type === 'reflection')) as unknown as Models.ReflectionType[]).map(
|
|
174
|
+
(unionReflectionType) => (
|
|
175
|
+
<ul key={unionReflectionType.declaration.id}>
|
|
176
|
+
{unionReflectionType.declaration?.children?.map((unionChild) => (
|
|
177
|
+
<li key={unionChild.id}>
|
|
178
|
+
<h5>
|
|
179
|
+
<Flags flags={unionChild.flags} />
|
|
180
|
+
{unionChild.flags?.isRest && <span className="tsd-signature-symbol">...</span>}
|
|
181
|
+
{`${unionChild.name}: `}
|
|
182
|
+
<Type type={unionChild.type} />
|
|
183
|
+
<DefaultValue
|
|
184
|
+
comment={unionChild.comment as unknown as JSONOutput.Comment}
|
|
185
|
+
type={unionChild.type}
|
|
186
|
+
value={unionChild.defaultValue}
|
|
187
|
+
/>
|
|
188
|
+
</h5>
|
|
189
|
+
|
|
190
|
+
<Comment comment={unionChild.comment as unknown as JSONOutput.Comment} />
|
|
191
|
+
</li>
|
|
192
|
+
))}
|
|
193
|
+
</ul>
|
|
194
|
+
))
|
|
195
|
+
)}
|
|
196
|
+
</Fragment>
|
|
103
197
|
))}
|
|
104
198
|
</ul>
|
|
105
199
|
</>
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
// https://github.com/TypeStrong/typedoc-default-themes/blob/master/src/default/partials/member.signature.title.hbs
|
|
3
3
|
|
|
4
4
|
import { Fragment } from 'react';
|
|
5
|
-
import
|
|
5
|
+
import { usePluginData } from '@docusaurus/useGlobalData';
|
|
6
|
+
import type { GlobalData,TSDSignatureReflection } from '../types';
|
|
6
7
|
import { escapeMdx } from '../utils/helpers';
|
|
7
8
|
import { Type } from './Type';
|
|
8
9
|
import { TypeParametersGeneric } from './TypeParametersGeneric';
|
|
@@ -14,6 +15,7 @@ export interface MemberSignatureTitleProps {
|
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
export function MemberSignatureTitle({ useArrow, hideName, sig }: MemberSignatureTitleProps) {
|
|
18
|
+
const { isPython } = usePluginData('docusaurus-plugin-typedoc-api') as GlobalData;
|
|
17
19
|
// add `*` before the first keyword-only parameter
|
|
18
20
|
const parametersCopy = sig.parameters?.slice() ?? [];
|
|
19
21
|
const firstKeywordOnlyIndex = parametersCopy.findIndex((param) => Object.keys(param.flags).includes('keyword-only'));
|
|
@@ -50,6 +52,17 @@ export function MemberSignatureTitle({ useArrow, hideName, sig }: MemberSignatur
|
|
|
50
52
|
<span>
|
|
51
53
|
{param.flags?.isRest && <span className="tsd-signature-symbol">...</span>}
|
|
52
54
|
{escapeMdx(param.name)}
|
|
55
|
+
{
|
|
56
|
+
!isPython && (
|
|
57
|
+
<>
|
|
58
|
+
<span className="tsd-signature-symbol">
|
|
59
|
+
{(param.flags?.isOptional || 'defaultValue' in param) && '?'}
|
|
60
|
+
{': '}
|
|
61
|
+
</span>
|
|
62
|
+
<Type type={param.type} />
|
|
63
|
+
</>
|
|
64
|
+
)
|
|
65
|
+
}
|
|
53
66
|
</span>
|
|
54
67
|
</Fragment>
|
|
55
68
|
))}
|
package/src/components/Type.tsx
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
import { Fragment } from 'react';
|
|
5
5
|
import type { JSONOutput } from 'typedoc';
|
|
6
6
|
import Link from '@docusaurus/Link';
|
|
7
|
+
import { type GlobalData } from '@docusaurus/types';
|
|
8
|
+
import { usePluginData } from '@docusaurus/useGlobalData';
|
|
7
9
|
import { useReflectionMap } from '../hooks/useReflectionMap';
|
|
8
10
|
import type { TSDDeclarationReflection } from '../types';
|
|
9
11
|
import { MemberSignatureTitle } from './MemberSignatureTitle';
|
|
@@ -40,6 +42,7 @@ export interface TypeProps {
|
|
|
40
42
|
// eslint-disable-next-line complexity
|
|
41
43
|
export function Type({ needsParens = false, type: base }: TypeProps) {
|
|
42
44
|
const reflections = useReflectionMap();
|
|
45
|
+
const { isPython } = usePluginData('docusaurus-plugin-typedoc-api') as GlobalData;
|
|
43
46
|
|
|
44
47
|
if (!base) {
|
|
45
48
|
return null;
|
|
@@ -124,6 +127,10 @@ export function Type({ needsParens = false, type: base }: TypeProps) {
|
|
|
124
127
|
case 'literal': {
|
|
125
128
|
const type = base as JSONOutput.LiteralType;
|
|
126
129
|
|
|
130
|
+
if (isPython && type.value === null) {
|
|
131
|
+
return <span className="tsd-signature-type">None</span>;
|
|
132
|
+
}
|
|
133
|
+
|
|
127
134
|
return <span className="tsd-signature-type">{String(type.value)}</span>;
|
|
128
135
|
}
|
|
129
136
|
|
|
@@ -203,7 +210,9 @@ export function Type({ needsParens = false, type: base }: TypeProps) {
|
|
|
203
210
|
|
|
204
211
|
case 'reference': {
|
|
205
212
|
const type = base as JSONOutput.ReferenceType;
|
|
206
|
-
|
|
213
|
+
// eslint-disable-next-line
|
|
214
|
+
const reflectionIdentifier = type.target ?? (type as any).id;
|
|
215
|
+
const ref = reflectionIdentifier ? reflections[Number(reflectionIdentifier)] : null;
|
|
207
216
|
const genericClass = ref?.id && !ref.sources ? 'tsd-signature-type-generic' : '';
|
|
208
217
|
|
|
209
218
|
return (
|
|
@@ -221,14 +230,22 @@ export function Type({ needsParens = false, type: base }: TypeProps) {
|
|
|
221
230
|
)}
|
|
222
231
|
{type.typeArguments && type.typeArguments.length > 0 && (
|
|
223
232
|
<>
|
|
224
|
-
<span className="tsd-signature-symbol"
|
|
233
|
+
<span className="tsd-signature-symbol">
|
|
234
|
+
{
|
|
235
|
+
isPython ? '[' : '<'
|
|
236
|
+
}
|
|
237
|
+
</span>
|
|
225
238
|
{type.typeArguments.map((t, i) => (
|
|
226
239
|
<Fragment key={t.type + i}>
|
|
227
240
|
{i > 0 && <span className="tsd-signature-symbol">, </span>}
|
|
228
241
|
<Type type={t} />
|
|
229
242
|
</Fragment>
|
|
230
243
|
))}
|
|
231
|
-
<span className="tsd-signature-symbol"
|
|
244
|
+
<span className="tsd-signature-symbol">
|
|
245
|
+
{
|
|
246
|
+
isPython ? ']' : '>'
|
|
247
|
+
}
|
|
248
|
+
</span>
|
|
232
249
|
</>
|
|
233
250
|
)}
|
|
234
251
|
</>
|
|
@@ -6,6 +6,50 @@
|
|
|
6
6
|
--tsd-spacing-horizontal: 1rem;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
+
.tsd-api-options {
|
|
10
|
+
border-left: 1px solid var(--ifm-toc-border-color);
|
|
11
|
+
font-size: var(--tsd-font-small);
|
|
12
|
+
padding-left: var(--ifm-toc-padding-horizontal);
|
|
13
|
+
}
|
|
14
|
+
.tsd-api-options > div:first-child {
|
|
15
|
+
margin: var(--ifm-toc-padding-vertical) var(--ifm-toc-padding-horizontal);
|
|
16
|
+
}
|
|
17
|
+
.tsd-api-options > label {
|
|
18
|
+
margin: var(--ifm-toc-padding-vertical) var(--ifm-toc-padding-horizontal);
|
|
19
|
+
}
|
|
20
|
+
.tsd-api-options > label > input {
|
|
21
|
+
margin: 0 5px 0 0;
|
|
22
|
+
vertical-align: middle;
|
|
23
|
+
}
|
|
24
|
+
.tsd-api-options > label > span {
|
|
25
|
+
vertical-align: middle;
|
|
26
|
+
}
|
|
27
|
+
.tsd-api-options > div:last-child {
|
|
28
|
+
border-bottom: 1px solid var(--ifm-toc-border-color);
|
|
29
|
+
margin-top: 1rem;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.tsd-api-options-mobile {
|
|
33
|
+
font-size: var(--tsd-font-small);
|
|
34
|
+
}
|
|
35
|
+
.tsd-api-options-mobile > div:first-child {
|
|
36
|
+
margin: var(--ifm-toc-padding-vertical) var(--ifm-toc-padding-horizontal);
|
|
37
|
+
}
|
|
38
|
+
.tsd-api-options-mobile > label {
|
|
39
|
+
margin: var(--ifm-toc-padding-vertical) var(--ifm-toc-padding-horizontal);
|
|
40
|
+
}
|
|
41
|
+
.tsd-api-options-mobile > label > input {
|
|
42
|
+
margin: 0 5px 0 0;
|
|
43
|
+
vertical-align: middle;
|
|
44
|
+
}
|
|
45
|
+
.tsd-api-options-mobile > label > span {
|
|
46
|
+
vertical-align: middle;
|
|
47
|
+
}
|
|
48
|
+
.tsd-api-options-mobile > div:last-child {
|
|
49
|
+
border-bottom: 1px solid var(--ifm-toc-border-color);
|
|
50
|
+
margin-top: 1rem;
|
|
51
|
+
}
|
|
52
|
+
|
|
9
53
|
.tsd-panel {
|
|
10
54
|
border: 1px solid var(--ifm-card-background-color);
|
|
11
55
|
border-radius: var(--ifm-global-radius);
|
package/src/index.ts
CHANGED
|
@@ -13,12 +13,12 @@ import {
|
|
|
13
13
|
generateJson,
|
|
14
14
|
loadPackageJsonAndDocs,
|
|
15
15
|
} from './plugin/data';
|
|
16
|
-
import { generateJsonFromPythonProject } from './plugin/python-generator';
|
|
17
16
|
import { extractSidebar } from './plugin/sidebar';
|
|
18
17
|
import { getVersionedDocsDirPath, readVersionsMetadata } from './plugin/version';
|
|
19
18
|
import type {
|
|
20
19
|
ApiOptions,
|
|
21
20
|
DocusaurusPluginTypeDocApiOptions,
|
|
21
|
+
GlobalData,
|
|
22
22
|
LoadedContent,
|
|
23
23
|
PackageEntryConfig,
|
|
24
24
|
PackageReflectionGroup,
|
|
@@ -149,19 +149,12 @@ export default function typedocApiPlugin(
|
|
|
149
149
|
|
|
150
150
|
console.log(`[${prefix}]:`, 'Generating docs...');
|
|
151
151
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
await generateJson(
|
|
159
|
-
projectRoot,
|
|
160
|
-
entryPoints,
|
|
161
|
-
path.join(outDir, 'api-typedoc.json'),
|
|
162
|
-
options,
|
|
163
|
-
);
|
|
164
|
-
}
|
|
152
|
+
await generateJson(
|
|
153
|
+
projectRoot,
|
|
154
|
+
entryPoints,
|
|
155
|
+
path.join(outDir, 'api-typedoc.json'),
|
|
156
|
+
options,
|
|
157
|
+
);
|
|
165
158
|
|
|
166
159
|
console.log(`[${prefix}]:`, 'Persisting packages...');
|
|
167
160
|
|
|
@@ -207,11 +200,6 @@ export default function typedocApiPlugin(
|
|
|
207
200
|
fs.mkdirSync(context.generatedFilesDir, { recursive: true });
|
|
208
201
|
}
|
|
209
202
|
fs.copyFileSync(options.pathToCurrentVersionTypedocJSON, outFile);
|
|
210
|
-
} else if (options.python) {
|
|
211
|
-
await generateJsonFromPythonProject({
|
|
212
|
-
projectRoot,
|
|
213
|
-
outFile,
|
|
214
|
-
});
|
|
215
203
|
} else {
|
|
216
204
|
await generateJson(projectRoot, entryPoints, outFile, options);
|
|
217
205
|
}
|
|
@@ -277,6 +265,10 @@ export default function typedocApiPlugin(
|
|
|
277
265
|
return;
|
|
278
266
|
}
|
|
279
267
|
|
|
268
|
+
actions.setGlobalData({
|
|
269
|
+
isPython: !!options.python,
|
|
270
|
+
} as GlobalData);
|
|
271
|
+
|
|
280
272
|
const docs: PropVersionDocs = {};
|
|
281
273
|
|
|
282
274
|
// Create an index of versions for quick lookups.
|
package/src/plugin/data.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import * as TypeDoc from 'typedoc';
|
|
4
|
-
import { JSONOutput, ReflectionKind } from 'typedoc'
|
|
4
|
+
import { type InlineTagDisplayPart, type JSONOutput, ReflectionKind } from 'typedoc'
|
|
5
5
|
import ts from 'typescript';
|
|
6
6
|
import { normalizeUrl } from '@docusaurus/utils';
|
|
7
7
|
import type {
|
|
@@ -110,7 +110,42 @@ export function createReflectionMap(
|
|
|
110
110
|
): TSDDeclarationReflectionMap {
|
|
111
111
|
const map: TSDDeclarationReflectionMap = {};
|
|
112
112
|
|
|
113
|
+
// eslint-disable-next-line complexity
|
|
113
114
|
items.forEach((item) => {
|
|
115
|
+
// Add @reference categories to reflection.
|
|
116
|
+
const referenceCategories: Record<string, { title: string; children: number[] }> = {};
|
|
117
|
+
for (const tag of item.comment?.blockTags ?? []) {
|
|
118
|
+
if (tag.tag === '@reference' && tag.content.length >= 2 && tag.content[0].kind === 'text') {
|
|
119
|
+
const categoryName = tag.content[0].text.trim();
|
|
120
|
+
const ref = (tag.content as InlineTagDisplayPart[]).find((t) => t.tag === '@link');
|
|
121
|
+
|
|
122
|
+
if (ref && typeof ref.target === 'number') {
|
|
123
|
+
if (!(categoryName in referenceCategories)) {
|
|
124
|
+
referenceCategories[categoryName] = { title: categoryName, children: [] };
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (!referenceCategories[categoryName].children.includes(ref.target)) {
|
|
128
|
+
referenceCategories[categoryName].children.push(ref.target);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Update categories with reference categories.
|
|
135
|
+
if (!item.categories) {
|
|
136
|
+
// eslint-disable-next-line no-param-reassign
|
|
137
|
+
item.categories = [];
|
|
138
|
+
}
|
|
139
|
+
for (const category of Object.values(referenceCategories)) {
|
|
140
|
+
if (category.children.length > 0) {
|
|
141
|
+
const index = item.categories.findIndex((c) => c.title === category.title);
|
|
142
|
+
if (index === -1) {
|
|
143
|
+
item.categories.push(category);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// Add item.
|
|
114
149
|
map[item.id] = item;
|
|
115
150
|
});
|
|
116
151
|
|
package/src/types.ts
CHANGED
|
@@ -32,7 +32,7 @@ export interface DocusaurusPluginTypeDocApiOptions
|
|
|
32
32
|
typedocOptions?: Partial<TypeDocOptions>;
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
|
-
*
|
|
35
|
+
* Enables the Python-specific rendering patches.
|
|
36
36
|
*/
|
|
37
37
|
python: boolean;
|
|
38
38
|
|
|
@@ -45,6 +45,10 @@ export interface DocusaurusPluginTypeDocApiOptions
|
|
|
45
45
|
routeBasePath?: string;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
export interface GlobalData {
|
|
49
|
+
isPython: boolean;
|
|
50
|
+
}
|
|
51
|
+
|
|
48
52
|
// CONFIG
|
|
49
53
|
|
|
50
54
|
export interface PackageEntryConfig {
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const zx = require('zx');
|
|
4
|
-
const pydocMarkdown = require('./pydoc-markdown.js');
|
|
5
|
-
const transformDocs = require('./transform-docs.js');
|
|
6
|
-
async function generateJsonFromPythonProject({
|
|
7
|
-
outFile,
|
|
8
|
-
projectRoot
|
|
9
|
-
}) {
|
|
10
|
-
const pydocJson = await pydocMarkdown.parseWithPydocMarkdown({
|
|
11
|
-
projectRoot
|
|
12
|
-
});
|
|
13
|
-
await zx.spinner('Converting the Python JSON AST to a TypeDoc-compliant file...', async () => {
|
|
14
|
-
await transformDocs.pydocToTypedoc({
|
|
15
|
-
moduleName: 'python',
|
|
16
|
-
// TODO: get from project config files or passed options
|
|
17
|
-
outFile,
|
|
18
|
-
pydocJson
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
exports.generateJsonFromPythonProject = generateJsonFromPythonProject;
|
|
23
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/plugin/python-generator/index.ts"],"sourcesContent":null,"names":["parseWithPydocMarkdown","spinner","pydocToTypedoc"],"mappings":";;;;;;AAGO,eAAe,6BAA6B,CAAC;AACpD,EAAE,OAAO;AACT,EAAE,WAAW;AACb,CAAC,EAAE;AACH,EAAE,MAAM,SAAS,GAAG,MAAMA,oCAAsB,CAAC;AACjD,IAAI,WAAW;AACf,GAAG,CAAC,CAAC;AACL,EAAE,MAAMC,UAAO,CAAC,+DAA+D,EAAE,YAAY;AAC7F,IAAI,MAAMC,4BAAc,CAAC;AACzB,MAAM,UAAU,EAAE,QAAQ;AAC1B;AACA,MAAM,OAAO;AACb,MAAM,SAAS;AACf,KAAK,CAAC,CAAC;AACP,GAAG,CAAC,CAAC;AACL;;;;"}
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const fs = require('node:fs');
|
|
4
|
-
const path = require('node:path');
|
|
5
|
-
const zx = require('zx');
|
|
6
|
-
const _interopDefault = e => e && e.__esModule ? e : {
|
|
7
|
-
default: e
|
|
8
|
-
};
|
|
9
|
-
const path__default = /*#__PURE__*/_interopDefault(path);
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Generates the pydoc-markdown configuration file
|
|
13
|
-
* @returns The pydoc-markdown configuration file as a string
|
|
14
|
-
*/
|
|
15
|
-
function getConfigYml({
|
|
16
|
-
projectRoot
|
|
17
|
-
}) {
|
|
18
|
-
return `
|
|
19
|
-
loaders:
|
|
20
|
-
- type: python
|
|
21
|
-
search_path: ["${projectRoot}"]
|
|
22
|
-
processors:
|
|
23
|
-
- type: filter
|
|
24
|
-
skip_empty_modules: true
|
|
25
|
-
- type: crossref
|
|
26
|
-
renderer:
|
|
27
|
-
type: docusaurus
|
|
28
|
-
docs_base_path: docs
|
|
29
|
-
relative_output_path: reference
|
|
30
|
-
relative_sidebar_path: sidebar.json
|
|
31
|
-
sidebar_top_level_label: null
|
|
32
|
-
`;
|
|
33
|
-
}
|
|
34
|
-
async function parseWithPydocMarkdown({
|
|
35
|
-
projectRoot
|
|
36
|
-
}) {
|
|
37
|
-
// Check whether the user has Python and pydoc-markdown installed
|
|
38
|
-
for (const cmd of ['python', 'pydoc-markdown']) {
|
|
39
|
-
try {
|
|
40
|
-
// eslint-disable-next-line no-await-in-loop
|
|
41
|
-
await zx.spinner(`Checking for ${cmd}...`, () => zx.$`${cmd} --version`);
|
|
42
|
-
} catch {
|
|
43
|
-
throw new Error(`Please install ${cmd} to use this plugin with Python projects.`);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
;
|
|
47
|
-
|
|
48
|
-
// Generate the JSON file
|
|
49
|
-
try {
|
|
50
|
-
const configYml = getConfigYml({
|
|
51
|
-
projectRoot
|
|
52
|
-
});
|
|
53
|
-
const configPath = path__default.default.join(__dirname, 'pydoc-markdown.temp.yml');
|
|
54
|
-
fs.writeFileSync(configPath, configYml);
|
|
55
|
-
let pydoc = null;
|
|
56
|
-
await zx.spinner('Parsing the Python project into a JSON AST...', async () => {
|
|
57
|
-
pydoc = await zx.$`pydoc-markdown --quiet --dump ${configPath}`;
|
|
58
|
-
});
|
|
59
|
-
fs.rmSync(configPath);
|
|
60
|
-
|
|
61
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
62
|
-
let json = await pydoc.text();
|
|
63
|
-
json = json.replaceAll(path__default.default.resolve(projectRoot), 'REPO_ROOT_PLACEHOLDER');
|
|
64
|
-
return json;
|
|
65
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
66
|
-
} catch (error) {
|
|
67
|
-
// eslint-disable-next-line
|
|
68
|
-
throw new Error(`Failed to generate JSON file from Python project:\n\t${error.stderr.split('\n').slice(-2).join('\n')}`);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
exports.parseWithPydocMarkdown = parseWithPydocMarkdown;
|
|
72
|
-
//# sourceMappingURL=pydoc-markdown.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pydoc-markdown.js","sources":["../../../src/plugin/python-generator/pydoc-markdown.ts"],"sourcesContent":null,"names":["spinner","$","path","writeFileSync","rmSync"],"mappings":";;;;;;;;;;AAIA;AACA;AACA;AACA;AACA,SAAS,YAAY,CAAC;AACtB,EAAE,WAAW;AACb,CAAC,EAAE;AACH,EAAE,OAAO,CAAC;AACV;AACA;AACA,mBAAmB,EAAE,WAAW,CAAC;AACjC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC,CAAC;AACF,CAAC;AACM,eAAe,sBAAsB,CAAC;AAC7C,EAAE,WAAW;AACb,CAAC,EAAE;AACH;AACA,EAAE,KAAK,MAAM,GAAG,IAAI,CAAC,QAAQ,EAAE,gBAAgB,CAAC,EAAE;AAClD,IAAI,IAAI;AACR;AACA,MAAM,MAAMA,UAAO,CAAC,CAAC,aAAa,EAAE,GAAG,CAAC,GAAG,CAAC,EAAE,MAAMC,IAAC,CAAC,EAAE,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC;AACzE,KAAK,CAAC,MAAM;AACZ,MAAM,MAAM,IAAI,KAAK,CAAC,CAAC,eAAe,EAAE,GAAG,CAAC,yCAAyC,CAAC,CAAC,CAAC;AACxF,KAAK;AACL,GAAG;AACH,EAAE,CAAC;AACH;AACA;AACA,EAAE,IAAI;AACN,IAAI,MAAM,SAAS,GAAG,YAAY,CAAC;AACnC,MAAM,WAAW;AACjB,KAAK,CAAC,CAAC;AACP,IAAI,MAAM,UAAU,GAAGC,qBAAI,CAAC,IAAI,CAAC,SAAS,EAAE,yBAAyB,CAAC,CAAC;AACvE,IAAIC,gBAAa,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;AACzC,IAAI,IAAI,KAAK,GAAG,IAAI,CAAC;AACrB,IAAI,MAAMH,UAAO,CAAC,+CAA+C,EAAE,YAAY;AAC/E,MAAM,KAAK,GAAG,MAAMC,IAAC,CAAC,8BAA8B,EAAE,UAAU,CAAC,CAAC,CAAC;AACnE,KAAK,CAAC,CAAC;AACP,IAAIG,SAAM,CAAC,UAAU,CAAC,CAAC;AACvB;AACA;AACA,IAAI,IAAI,IAAI,GAAG,MAAM,KAAK,CAAC,IAAI,EAAE,CAAC;AAClC,IAAI,IAAI,GAAG,IAAI,CAAC,UAAU,CAACF,qBAAI,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,uBAAuB,CAAC,CAAC;AAC/E,IAAI,OAAO,IAAI,CAAC;AAChB;AACA,GAAG,CAAC,OAAO,KAAK,EAAE;AAClB;AACA,IAAI,MAAM,IAAI,KAAK,CAAC,CAAC,qDAAqD,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AAC7H,GAAG;AACH;;;;"}
|