@@ -120,29 +120,35 @@ var util = {
120120 } ,
121121
122122 syncDirs : function ( fromDir , toDir ) {
123+ let toFilePaths ;
124+ let fromFilePaths ;
123125 return Promise . all ( [
124126 util . getFilePathsRelativeToDir ( toDir ) ,
125127 util . getFilePathsRelativeToDir ( fromDir )
126- ] ) . then ( function ( filePaths ) {
127- const toFilePaths = filePaths [ 0 ] ;
128- const fromFilePaths = filePaths [ 1 ] ;
129-
130- // Delete files that aren't in fromDir
131- toFilePaths . forEach ( function ( filePath ) {
132- if ( ! util . isFile ( path . join ( fromDir , filePath ) ) ) {
133- fse . remove ( path . join ( toDir , filePath ) ) ;
134- }
128+ ] )
129+ . then ( function ( filePaths ) {
130+ toFilePaths = filePaths [ 0 ] ;
131+ fromFilePaths = filePaths [ 1 ] ;
132+
133+ // Delete files that aren't in fromDir
134+ return Promise . all ( toFilePaths . map ( function ( filePath ) {
135+ if ( ! util . isFile ( path . join ( fromDir , filePath ) ) ) {
136+ return fse . remove ( path . join ( toDir , filePath ) ) ;
137+ }
138+ return Promise . resolve ( ) ;
139+ } ) ) ;
140+ } )
141+ . then ( function ( ) {
142+ // Copy files that don't exist in toDir or have different contents
143+ return Promise . all ( fromFilePaths . map ( function ( filePath ) {
144+ const toFilePath = path . join ( toDir , filePath ) ;
145+ const fromFilePath = path . join ( fromDir , filePath ) ;
146+ if ( ! util . isFile ( toFilePath ) || util . readFile ( toFilePath ) !== util . readFile ( fromFilePath ) ) {
147+ return fse . copy ( fromFilePath , toFilePath ) ;
148+ }
149+ return Promise . resolve ( ) ;
150+ } ) ) ;
135151 } ) ;
136-
137- // Copy files that don't exist in toDir or have different contents
138- fromFilePaths . forEach ( function ( filePath ) {
139- const toFilePath = path . join ( toDir , filePath ) ;
140- const fromFilePath = path . join ( fromDir , filePath ) ;
141- if ( ! util . isFile ( toFilePath ) || util . readFile ( toFilePath ) !== util . readFile ( fromFilePath ) ) {
142- fse . copy ( fromFilePath , toFilePath ) ;
143- }
144- } ) ;
145- } ) ;
146152 }
147153} ;
148154
0 commit comments