-
Notifications
You must be signed in to change notification settings - Fork 3
/
create-docs.ts
69 lines (52 loc) · 1.35 KB
/
create-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
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
import typedoc from 'typedoc'
const app = await typedoc.Application.bootstrapWithPlugins({
entryPoints: ['./src/mod.ts'],
name: 'yaksok.ts',
categorizeByGroup: true,
})
const outputDir = 'docs/api'
const VALID_OPERATIONS = ['create', 'modify', 'rename', 'remove']
const isWatch = Deno.args.includes('--watch')
const CWD = Deno.cwd()
async function buildMarkdownDocs() {
const project = await app.convert()
if (project) {
await app.generateDocs(project, outputDir)
}
}
await buildMarkdownDocs()
if (!isWatch) {
Deno.exit(0)
}
console.log('Waiting for file changes...')
const watcher = Deno.watchFs('./src', {
recursive: true,
})
for await (const event of watcher) {
const type = event.kind
const isValidOperation = VALID_OPERATIONS.includes(type)
const paths = event.paths.map(clarifyPath)
const message = `[${type}] ${paths.join(', ')}`
if (!isValidOperation) {
continue
}
console.log(message)
buildMarkdownDocs()
}
function clarifyPath(path: string) {
if (path.startsWith(CWD)) {
path = path.slice(CWD.length)
}
while (true) {
if (path.startsWith('/')) {
path = path.slice(1)
continue
}
if (path.startsWith('./')) {
path = path.slice(1)
continue
}
break
}
return path
}