@@ -16,7 +16,7 @@ const cwd = require('./cwd')
1616function isDirectory ( file ) {
1717 file = file . replace ( / \\ / g, path . sep )
1818 try {
19- return fs . statSync ( file ) . isDirectory ( )
19+ return fs . stat ( file ) . then ( ( x ) => x . isDirectory ( ) )
2020 } catch ( e ) {
2121 if ( process . env . VUE_APP_CLI_UI_DEBUG ) console . warn ( e . message )
2222 }
@@ -31,21 +31,41 @@ async function list (base, context) {
3131 }
3232 }
3333 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 ) => {
3637 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+ }
3746 return {
3847 path : folderPath ,
3948 name : file ,
40- hidden : isHidden ( folderPath )
49+ hidden
4150 }
42- }
43- ) . filter (
44- file => isDirectory ( file . path )
51+ } )
4552 )
53+ return f . filter ( ( x ) => ! ! x )
4654}
4755
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 ) {
4969 try {
5070 const prefixed = path . basename ( file ) . charAt ( 0 ) === hiddenPrefix
5171 const result = {
@@ -54,11 +74,13 @@ function isHidden (file) {
5474 }
5575
5676 if ( isPlatformWindows ) {
57- const windowsFile = file . replace ( / \\ / g, '\\\\' )
58- result . windows = winattr . getSync ( windowsFile ) . hidden
77+ result . windows = await isHiddenWindows ( file )
5978 }
6079
61- return ( ! isPlatformWindows && result . unix ) || ( isPlatformWindows && result . windows )
80+ return (
81+ ( ! isPlatformWindows && result . unix ) ||
82+ ( isPlatformWindows && result . windows )
83+ )
6284 } catch ( e ) {
6385 if ( process . env . VUE_APP_CLI_UI_DEBUG ) {
6486 console . log ( 'file:' , file )
@@ -142,9 +164,10 @@ function isVueProject (file, context) {
142164}
143165
144166function 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 ) )
148171}
149172
150173function isFavorite ( file , context ) {
0 commit comments