@@ -16,7 +16,7 @@ const cwd = require('./cwd')
16
16
function isDirectory ( file ) {
17
17
file = file . replace ( / \\ / g, path . sep )
18
18
try {
19
- return fs . statSync ( file ) . isDirectory ( )
19
+ return fs . stat ( file ) . then ( ( x ) => x . isDirectory ( ) )
20
20
} catch ( e ) {
21
21
if ( process . env . VUE_APP_CLI_UI_DEBUG ) console . warn ( e . message )
22
22
}
@@ -31,21 +31,41 @@ async function list (base, context) {
31
31
}
32
32
}
33
33
const files = await fs . readdir ( dir , 'utf8' )
34
- return files . map (
35
- file => {
34
+
35
+ const f = await Promise . all (
36
+ files . map ( async ( file ) => {
36
37
const folderPath = path . join ( base , file )
38
+
39
+ const [ directory , hidden ] = await Promise . all ( [
40
+ isDirectory ( folderPath ) ,
41
+ isHidden ( folderPath )
42
+ ] )
43
+ if ( ! directory ) {
44
+ return null
45
+ }
37
46
return {
38
47
path : folderPath ,
39
48
name : file ,
40
- hidden : isHidden ( folderPath )
49
+ hidden
41
50
}
42
- }
43
- ) . filter (
44
- file => isDirectory ( file . path )
51
+ } )
45
52
)
53
+ return f . filter ( ( x ) => ! ! x )
46
54
}
47
55
48
- function isHidden ( file ) {
56
+ async function isHiddenWindows ( file ) {
57
+ const windowsFile = file . replace ( / \\ / g, '\\\\' )
58
+ return new Promise ( ( resolve , reject ) => {
59
+ winattr . get ( windowsFile , ( file , error ) => {
60
+ if ( error ) {
61
+ return reject ( error )
62
+ }
63
+ resolve ( file )
64
+ } )
65
+ } ) . then ( ( x ) => x . hidden )
66
+ }
67
+
68
+ async function isHidden ( file ) {
49
69
try {
50
70
const prefixed = path . basename ( file ) . charAt ( 0 ) === hiddenPrefix
51
71
const result = {
@@ -54,11 +74,13 @@ function isHidden (file) {
54
74
}
55
75
56
76
if ( isPlatformWindows ) {
57
- const windowsFile = file . replace ( / \\ / g, '\\\\' )
58
- result . windows = winattr . getSync ( windowsFile ) . hidden
77
+ result . windows = await isHiddenWindows ( file )
59
78
}
60
79
61
- return ( ! isPlatformWindows && result . unix ) || ( isPlatformWindows && result . windows )
80
+ return (
81
+ ( ! isPlatformWindows && result . unix ) ||
82
+ ( isPlatformWindows && result . windows )
83
+ )
62
84
} catch ( e ) {
63
85
if ( process . env . VUE_APP_CLI_UI_DEBUG ) {
64
86
console . log ( 'file:' , file )
@@ -142,9 +164,10 @@ function isVueProject (file, context) {
142
164
}
143
165
144
166
function listFavorite ( context ) {
145
- return context . db . get ( 'foldersFavorite' ) . value ( ) . map (
146
- file => generateFolder ( file . id , context )
147
- )
167
+ return context . db
168
+ . get ( 'foldersFavorite' )
169
+ . value ( )
170
+ . map ( ( file ) => generateFolder ( file . id , context ) )
148
171
}
149
172
150
173
function isFavorite ( file , context ) {
0 commit comments