FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
query/scripts/generate-docs.ts at main · TanStack/query · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
TanStack
/
query
Public
Uh oh!
There was an error while loading.
Please reload this page
.
Notifications
You must be signed in to change notification settings
Fork
4.2k
Star
50.2k
Code
Issues
59
Pull requests
112
Discussions
Actions
Security and quality
1
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
query
/
scripts
/
generate-docs.ts
Copy path
More file actions
More file actions
Latest commit
History
History
History
186 lines (160 loc) · 5.45 KB
Breadcrumbs
query
/
scripts
/
generate-docs.ts
Copy path
File metadata and controls
186 lines (160 loc) · 5.45 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
import
{
mkdir
,
readFile
,
readdir
,
rm
,
writeFile
}
from
'node:fs/promises'
import
{
createRequire
}
from
'node:module'
import
{
dirname
,
resolve
}
from
'node:path'
import
{
fileURLToPath
}
from
'node:url'
const
__dirname
=
fileURLToPath
(
new
URL
(
'.'
,
import
.
meta
.
url
)
)
const
require
=
createRequire
(
import
.
meta
.
url
)
const
typedocConfigPackageJson
=
require
.
resolve
(
'@tanstack/typedoc-config/package.json'
)
const
typedocConfigDir
=
dirname
(
typedocConfigPackageJson
)
const
typedocConfigRequire
=
createRequire
(
typedocConfigPackageJson
)
const
TypeDoc
=
await
import
(
typedocConfigRequire
.
resolve
(
'typedoc'
)
)
type
PackageReferenceDocsConfig
=
{
entryPoints
:
Array
<
string
>
tsconfig
:
string
outputDir
:
string
exclude
?:
Array
<
string
>
excludeExternals
?:
boolean
simplifyLitQueriesControllerTypes
?:
boolean
trimGeneratedMarkdown
?:
boolean
}
type
TypeDocReflectionWithSignatures
=
{
name
:
string
children
?:
Array
<
TypeDocReflectionWithSignatures
>
signatures
?:
Array
<
{
typeParameters
?:
Array
<
{
name
:
string
default
?:
unknown
}
>
}
>
}
function
simplifyLitQueriesControllerTypes
(
project
:
TypeDocReflectionWithSignatures
,
)
{
const
stack
:
Array
<
TypeDocReflectionWithSignatures
>
=
[
project
]
for
(
const
reflection
of
stack
)
{
stack
.
push
(
...
(
reflection
.
children
??
[
]
)
)
if
(
reflection
.
name
!==
'createQueriesController'
)
{
continue
}
for
(
const
signature
of
reflection
.
signatures
??
[
]
)
{
const
combinedResult
=
signature
.
typeParameters
?.
find
(
(
typeParameter
)
=>
typeParameter
.
name
===
'TCombinedResult'
,
)
if
(
!
combinedResult
?.
default
)
{
continue
}
const
queryOptionsType
=
TypeDoc
.
ReferenceType
.
createBrokenReference
(
'TQueryOptions'
,
project
,
undefined
,
)
queryOptionsType
.
refersToTypeParameter
=
true
// CreateQueriesResults is internal; render it as plain text, not a link.
const
queriesResultsType
=
TypeDoc
.
ReferenceType
.
createBrokenReference
(
'CreateQueriesResults'
,
project
,
undefined
,
)
queriesResultsType
.
typeArguments
=
[
queryOptionsType
]
combinedResult
.
default
=
queriesResultsType
}
}
}
async
function
trimTrailingWhitespaceInMarkdown
(
outputDir
:
string
)
{
const
entries
=
await
readdir
(
outputDir
,
{
withFileTypes
:
true
}
)
await
Promise
.
all
(
entries
.
map
(
async
(
entry
)
=>
{
const
path
=
resolve
(
outputDir
,
entry
.
name
)
if
(
entry
.
isDirectory
(
)
)
{
await
trimTrailingWhitespaceInMarkdown
(
path
)
return
}
if
(
!
entry
.
isFile
(
)
||
!
path
.
endsWith
(
'.md'
)
)
{
return
}
const
markdown
=
await
readFile
(
path
,
'utf8'
)
const
trimmed
=
markdown
.
replace
(
/
[
\t
]
+
$
/
gm
,
''
)
if
(
trimmed
!==
markdown
)
{
await
writeFile
(
path
,
trimmed
)
}
}
)
,
)
}
async
function
generatePackageReferenceDocs
(
pkg
:
PackageReferenceDocsConfig
)
{
const
outputDir
=
pkg
.
outputDir
await
rm
(
outputDir
,
{
recursive
:
true
,
force
:
true
}
)
await
mkdir
(
outputDir
,
{
recursive
:
true
}
)
const
app
=
await
TypeDoc
.
Application
.
bootstrapWithPlugins
(
{
plugin
:
[
'typedoc-plugin-markdown'
,
'typedoc-plugin-frontmatter'
,
resolve
(
typedocConfigDir
,
'./src/typedoc-custom-settings.js'
)
,
]
,
hideGenerator
:
true
,
readme
:
'none'
,
entryFileName
:
'index'
,
hideBreadcrumbs
:
true
,
hidePageHeader
:
true
,
hidePageTitle
:
true
,
useCodeBlocks
:
true
,
excludePrivate
:
true
,
excludeInternal
:
true
,
excludeExternals
:
pkg
.
excludeExternals
,
sourceLinkTemplate
:
'https://github.com/TanStack/query/blob/{gitRevision}/{path}#L{line}'
,
gitRevision
:
'main'
,
entryPoints
:
pkg
.
entryPoints
,
tsconfig
:
pkg
.
tsconfig
,
exclude
:
pkg
.
exclude
,
out
:
outputDir
,
}
)
const
project
=
await
app
.
convert
(
)
if
(
project
)
{
if
(
pkg
.
simplifyLitQueriesControllerTypes
)
{
simplifyLitQueriesControllerTypes
(
project
)
}
await
app
.
generateOutputs
(
project
)
if
(
pkg
.
trimGeneratedMarkdown
)
{
await
trimTrailingWhitespaceInMarkdown
(
outputDir
)
}
}
}
for
(
const
pkg
of
[
{
entryPoints
:
[
resolve
(
__dirname
,
'../packages/angular-query-experimental/src/index.ts'
)
,
]
,
tsconfig
:
resolve
(
__dirname
,
'../packages/angular-query-experimental/tsconfig.json'
,
)
,
outputDir
:
resolve
(
__dirname
,
'../docs/framework/angular/reference'
)
,
exclude
:
[
'./packages/query-core/**/*'
]
,
}
,
{
entryPoints
:
[
resolve
(
__dirname
,
'../packages/svelte-query/src/index.ts'
)
]
,
tsconfig
:
resolve
(
__dirname
,
'../packages/svelte-query/tsconfig.json'
)
,
outputDir
:
resolve
(
__dirname
,
'../docs/framework/svelte/reference'
)
,
exclude
:
[
'./packages/query-core/**/*'
]
,
}
,
{
entryPoints
:
[
resolve
(
__dirname
,
'../packages/preact-query/src/index.ts'
)
]
,
tsconfig
:
resolve
(
__dirname
,
'../packages/preact-query/tsconfig.json'
)
,
outputDir
:
resolve
(
__dirname
,
'../docs/framework/preact/reference'
)
,
exclude
:
[
'./packages/query-core/**/*'
]
,
}
,
{
entryPoints
:
[
resolve
(
__dirname
,
'../packages/lit-query/src/index.ts'
)
]
,
tsconfig
:
resolve
(
__dirname
,
'../packages/lit-query/tsconfig.json'
)
,
outputDir
:
resolve
(
__dirname
,
'../docs/framework/lit/reference'
)
,
exclude
:
[
'./packages/query-core/**/*'
]
,
excludeExternals
:
true
,
simplifyLitQueriesControllerTypes
:
true
,
trimGeneratedMarkdown
:
true
,
}
,
]
satisfies
Array
<
PackageReferenceDocsConfig
>
)
{
await
generatePackageReferenceDocs
(
pkg
)
}
console
.
log
(
'\n✅ All markdown files have been processed!'
)
process
.
exit
(
0
)
Back
|
FazBrowse Home
|
New Git URL