File tree Expand file tree Collapse file tree 2 files changed +13
-9
lines changed Expand file tree Collapse file tree 2 files changed +13
-9
lines changed Original file line number Diff line number Diff line change @@ -86,8 +86,8 @@ exports[`tree directoriesOnly 5`] = `
86
86
│ ├── alpha
87
87
│ │ └── beta
88
88
│ └── charlie
89
- ├ ── charlie
90
- │ ├ ── beta"
89
+ └ ── charlie
90
+ └ ── beta"
91
91
` ;
92
92
93
93
exports [` tree directoriesOnly 6` ] = ` "single-file"` ;
Original file line number Diff line number Diff line change @@ -73,10 +73,20 @@ function print(
73
73
}
74
74
75
75
// Handle directory files.
76
- const files = fs . readdirSync ( path )
76
+ let files = fs . readdirSync ( path )
77
77
. filter (
78
78
file => ! EXCLUSIONS . includes ( file )
79
79
) ;
80
+ if ( options . directoriesOnly ) {
81
+ // We have to filter here instead of at the start of the function
82
+ // because we need to know how many non-directories there are before
83
+ // we even start recursing.
84
+ files = files . filter ( file => {
85
+ const filePath = nodePath . join ( path , file ) ;
86
+ return ! fs . lstatSync ( filePath ) . isFile ( ) ;
87
+ } )
88
+ }
89
+
80
90
files . forEach ( ( file , index ) => {
81
91
const isCurrentLast = index === files . length - 1 ;
82
92
const linesForFile = print (
@@ -103,9 +113,3 @@ function tree(path, options) {
103
113
}
104
114
105
115
module . exports = tree ;
106
-
107
- // console.log(
108
- // printTree('/Users/yangshun/Developer/redux-devtools/', {
109
- // excludeDirs: ['node_modules'],
110
- // }),
111
- // );
You can’t perform that action at this time.
0 commit comments