-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgenerate-api-docs.ts
40 lines (34 loc) · 1.02 KB
/
generate-api-docs.ts
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
import { getPayload } from 'payload'
import config from '../payload.config'
/**
* Script to generate API documentation for all collections
* This creates MDX files in the /content/apis directory
*/
const generateApiDocs = async () => {
try {
console.log('Initializing Payload...')
const payload = await getPayload({
config,
})
console.log('Queueing API documentation generation task...')
const job = await payload.jobs.queue({
task: 'generateApiDocs',
input: {},
} as any)
console.log('Running API documentation generation task...')
try {
await payload.jobs.runByID({ id: (job as any)?.id })
console.log('API documentation generated successfully!')
} catch (jobError) {
console.error('Error generating API documentation:', jobError)
}
if (payload.db && typeof payload.db.destroy === 'function') {
await payload.db.destroy()
}
process.exit(0)
} catch (error) {
console.error('Error:', error)
process.exit(1)
}
}
generateApiDocs()