@@ -12,9 +12,10 @@ export interface Options {
12
12
export const DIR_ROOT = resolve ( __dirname , '../../../../' )
13
13
export const DIR_SRC = resolve ( DIR_ROOT , 'docs' )
14
14
15
- export function getDir ( dir : string , ignore : string [ ] = [ ] ) {
15
+ export function fastGlobSync ( type : string , dir : string , ignore : string [ ] = [ ] ) {
16
16
const files = fg . sync ( '*' , {
17
- onlyDirectories : true ,
17
+ onlyDirectories : type === 'dir' ,
18
+ onlyFiles : type === 'file' ,
18
19
cwd : dir ,
19
20
ignore : [
20
21
'_*' ,
@@ -27,32 +28,17 @@ export function getDir(dir: string, ignore: string[] = []) {
27
28
return files
28
29
}
29
30
30
- export function getFiles ( dir : string , ignore : string [ ] = [ ] ) {
31
- const files = fg . sync ( '*' , {
32
- onlyFiles : true ,
33
- cwd : dir ,
34
- ignore : [
35
- '_*' ,
36
- 'dist' ,
37
- 'node_modules' ,
38
- ...ignore ,
39
- ] ,
40
- } )
41
- files . sort ( )
42
- return files
43
- }
44
-
45
- export const dirs = getDir ( DIR_SRC )
31
+ export const dirs = fastGlobSync ( 'dir' , DIR_SRC )
46
32
47
33
const getSidebar = ( dir : string , title : string | undefined ) => {
48
34
const curDir = resolve ( DIR_SRC , dir )
49
- const dirs = getDir ( curDir )
35
+ const dirs = fastGlobSync ( 'dir' , curDir )
50
36
const res = [ ]
51
37
if ( dirs . length ) {
52
38
// TODO 多级目录
53
39
dirs . forEach ( ( e ) => {
54
40
const childDir = resolve ( curDir , e )
55
- const mdFiles = getFiles ( childDir )
41
+ const mdFiles = fastGlobSync ( 'file' , childDir )
56
42
const sidebar = {
57
43
text : ( e . charAt ( 0 ) . toUpperCase ( ) + e . slice ( 1 ) ) . replaceAll ( '-' , ' ' ) ,
58
44
collapsed : false ,
@@ -75,7 +61,7 @@ const getSidebar = (dir: string, title: string | undefined) => {
75
61
} )
76
62
}
77
63
else {
78
- const mdFiles = getFiles ( curDir )
64
+ const mdFiles = fastGlobSync ( 'file' , curDir )
79
65
const sidebar = {
80
66
text : title ,
81
67
collapsed : false ,
0 commit comments