@@ -79,27 +79,31 @@ module.exports.headlessZip = function headlessZip(dirToZip) {
7979 deleteFile ( earliest )
8080 }
8181
82- var zip = new JSZip ( ) ;
83- var files = fs . readdirSync ( dirToZip )
84- for ( var i = 0 , len = files . length ; i < len ; i ++ ) {
85- zip . file ( files [ i ] , fs . readFileSync ( path . join ( dirToZip , files [ i ] ) ) , { compression : "DEFLATE" } )
82+ if ( fs . existsSync ( dirToZip ) ) {
83+ var zip = new JSZip ( ) ;
84+ var files = fs . readdirSync ( dirToZip )
85+ for ( var i = 0 , len = files . length ; i < len ; i ++ ) {
86+ zip . file ( files [ i ] , fs . readFileSync ( path . join ( dirToZip , files [ i ] ) ) , { compression : "DEFLATE" } )
87+ }
88+ fs . writeFileSync ( outputFileName , zip . generate ( { type :"nodebuffer" , compression :'DEFLATE' } ) ) ;
89+ deleteDir ( dirToZip )
8690 }
87- fs . writeFileSync ( outputFileName , zip . generate ( { type :"nodebuffer" , compression :'DEFLATE' } ) ) ;
88- deleteDir ( dirToZip )
8991}
9092
9193module . exports . tryZipOnExit = function tryZipOnExit ( ) {
9294 var outputDir = dirToWriteTo ;
9395 if ( ! outputDir ) {
9496 ouputDir = process . cwd ( ) . toString ( )
9597 }
96- var files = fs . readdirSync ( outputDir ) ;
97- // Search for temporary output directory using pattern matching
98- for ( var i = 0 , len = files . length ; i < len ; i ++ ) {
99- if ( / t m p _ ( \w + ) / . test ( files [ i ] . toString ( ) ) ) {
100- var dirToZip = path . join ( outputDir , files [ i ] )
101- this . headlessZip ( dirToZip )
102- return ;
98+ if ( fs . existsSync ( outputDir ) ) {
99+ var files = fs . readdirSync ( outputDir ) ;
100+ // Search for temporary output directory using pattern matching
101+ for ( var i = 0 , len = files . length ; i < len ; i ++ ) {
102+ if ( / t m p _ ( \w + ) / . test ( files [ i ] . toString ( ) ) ) {
103+ var dirToZip = path . join ( outputDir , files [ i ] )
104+ this . headlessZip ( dirToZip )
105+ return ;
106+ }
103107 }
104108 }
105109}
0 commit comments