-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
38 lines (35 loc) · 945 Bytes
/
index.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
import * as path from 'path'
import * as tree from 'directory-tree'
const root = `${__dirname}/pages`
function files(tree, result = []) {
result
.push(...tree
.map(child => {
if (child.children) {
result.push(...files(child.children))
return
}
return child
})
.filter(child => child && child.extension && child.extension.endsWith('.tsx'))
.map(tsx => {
if (tsx.size === 0) {
console.warn(`${tsx.path} has zero size`)
}
return tsx.path
.replace(root, '')
.replace(tsx.name, `${path.parse(tsx.name).name}`)
})
.filter(name => !(name.startsWith('/_') || name.startsWith('/test'))))
return result
}
export function exportPathMap() {
return files(tree(root).children)
.reduce(
(ret, file) => {
ret[file] = {page: file}
return ret
},
{'/': {page: '/index'}}
)
}