-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
45 lines (35 loc) · 1.25 KB
/
index.js
File metadata and controls
45 lines (35 loc) · 1.25 KB
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
import walk from 'walkdir'
import fs from 'fs/promises'
import fsSync from 'fs'
import markdownAttacher from './markdown/index.js'
import path from 'path'
async function CopyAsIsProcessor ({ outDocDir, relPath, filePath }) {
await fs.copyFile(filePath, path.resolve(outDocDir, relPath))
}
async function SkipProcessor () {}
async function convertAll () {
const repoDir = path.resolve('.', 'raw')
const docDir = path.resolve(repoDir, 'docs')
const outDocDir = path.resolve('.', 'out', 'docs')
const env = { repoDir, docDir, outDocDir }
const processors = {}
async function registerProcessors (env) {
processors.default = CopyAsIsProcessor
processors['.md'] = await markdownAttacher(env);
['.webmanifest', '.ico', '.css', '.js', '.txt'].forEach(e => {
processors[e] = SkipProcessor
})
}
await registerProcessors(env)
walk(docDir, async function (filePath, stat) {
const relPath = path.relative(docDir, filePath)
if (stat.isDirectory()) {
fsSync.mkdirSync(path.resolve(outDocDir, relPath), { recursive: true })
return
}
const processor = processors[path.extname(filePath)] ?? processors.default
console.log(relPath, processor.name)
await processor({ relPath, filePath, ...env })
})
}
convertAll()