forked from intity/epub-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocsgen.js
89 lines (87 loc) · 2.13 KB
/
docsgen.js
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
const fs = require("node:fs")
const path = require("path")
const jsdoc2md = require("jsdoc-to-markdown")
const output = (dir, filename, data) => {
try {
fs.mkdirSync(dir, { recursive: true }, err => {
if (err) throw err
})
const ws = fs.createWriteStream(filename)
ws.write(data)
} catch (e) {
console.error(e)
}
}
const docs = [
"annotation",
"annotations",
"archive",
"book",
"container",
"contents",
"epub",
"epubcfi",
"input",
"layout",
"location",
"locations",
"managers/continuous/index",
"managers/default/index",
"managers/helpers/snap",
"managers/helpers/views",
"managers/views/iframe",
"marks-pane/events",
"marks-pane/mark",
"marks-pane/marks",
"marks-pane/highlight",
"marks-pane/underline",
"mapping",
"navigation",
"navigation/landmarks",
"navigation/pagelist",
"navigation/toc",
"packaging",
"packaging/metadata",
"packaging/manifest",
"packaging/spine",
"rendition",
"resources",
"section",
"sections",
"storage",
"themes",
"viewport",
"utils/constants",
"utils/core",
"utils/defer",
"utils/hook",
"utils/mime",
"utils/path",
"utils/replacements",
"utils/request",
"utils/scrolltype",
"utils/queue",
"utils/url"
]
for (const doc of docs) {
const time = Date.now()
const item = doc.split('/')
let opath = path.resolve(__dirname, "docs/API")
let ifile = "src"
let ofile = opath
for (let i = 0, len = item.length; i < len; ++i) {
if (i === (len - 1)) {
ifile = path.join(ifile, item[i]) + ".js"
ofile = path.join(ofile, item[i]) + ".md"
} else {
opath = path.join(opath, item[i])
ifile = path.join(ifile, item[i])
ofile = path.join(ofile, item[i])
}
}
jsdoc2md.render({ files: ifile, "heading-depth": 1 }).then(data => {
output(opath, ofile, data)
const t = (Date.now() - time).toString().padStart(3)
console.log("output [time:%s ms, path:%s]", t, ofile)
})
}