@@ -21,7 +21,6 @@ function good_filepaths(top_dir = ".") {
21
21
} else {
22
22
if ( file . toLowerCase ( ) . endsWith ( ".js" ) ) {
23
23
filepaths . push ( path . slice ( 2 ) ) ;
24
- // console.log(filepaths);
25
24
}
26
25
}
27
26
} ) ;
@@ -47,14 +46,63 @@ function print_path(old_path, new_path) {
47
46
if ( i + 1 > old_parts . len || old_parts [ i ] != new_part ) {
48
47
if ( new_part ) {
49
48
g_output . push ( `${ md_prefix ( i ) } ${ new_part . replace ( '_' , ' ' ) } ` ) ;
50
- // console.log(`${md_prefix(i)} ${new_part.replace('_', ' ')}`);
51
49
}
52
50
}
53
51
}
54
52
return new_path ;
55
53
}
56
54
55
+ function build_directory_md ( top_dir = "." ) {
56
+ old_path = "" ;
57
+ filepaths . sort ( function ( a , b ) {
58
+ if ( a . toLowerCase ( ) < b . toLowerCase ( ) ) return - 1 ;
59
+ if ( a . toLowerCase ( ) > b . toLowerCase ( ) ) return 1 ;
60
+ return 0 ;
61
+ } ) ;
62
+ for ( let filepath of filepaths ) {
63
+ file = filepath . split ( path . sep ) ;
64
+ if ( file . length == 1 ) {
65
+ filepath = "" ;
66
+ filename = file [ 0 ] ;
67
+ } else {
68
+ let total = file . length ;
69
+ filename = file [ total - 1 ] ;
70
+ filepath = file . splice ( 0 , total - 1 ) . join ( path . sep ) ;
71
+ }
72
+ if ( filepath != old_path ) {
73
+ old_path = print_path ( old_path , filepath ) ;
74
+ }
75
+ let indent = 0 ;
76
+ for ( let i = 0 ; i < filepath . length ; ++ i ) {
77
+ if ( filepath [ i ] == path . sep ) {
78
+ ++ indent ;
79
+ }
80
+ }
81
+ if ( filepath ) {
82
+ ++ indent ;
83
+ }
84
+ let urls = [ URL_BASE , filepath , filename ] ;
85
+ let url = urls . join ( "/" ) . replace ( " " , "%20" ) ;
86
+ // remove extension from filename
87
+ filename = filename . split ( "." ) [ 0 ] ;
88
+ g_output . push ( `${ md_prefix ( indent ) } [${ filename } ](${ url } )` ) ;
89
+ }
90
+ g_output = g_output . join ( '\n' ) ;
91
+ return g_output ;
92
+ }
93
+
57
94
good_filepaths ( ) ;
58
95
setTimeout ( ( ) => {
59
- console . log ( filepaths ) ;
96
+ // once the filepaths have been computed
97
+ build_directory_md ( ) ;
98
+ // console.log(filepaths);
99
+ } , 1000 ) ;
100
+ setTimeout ( ( ) => {
101
+ // once the g_output has been constructed, write to the file
102
+ fs . writeFile ( 'DIRECTORY.md' , g_output + '\n' , ( err ) => {
103
+ if ( err ) {
104
+ console . log ( err ) ;
105
+ }
106
+ } )
107
+ // console.log(g_output);
60
108
} , 1000 ) ;
0 commit comments