@@ -22,7 +22,6 @@ module.exports = {
2222 defaultConfig : {
2323 filePattern : '**/*.{js,css,png,gif,ico,jpg,map,xml,txt,svg,swf,eot,ttf,woff,woff2}' ,
2424 zopfli : false ,
25- keep : false ,
2625 distDir : function ( context ) {
2726 return context . distDir ;
2827 } ,
@@ -47,28 +46,26 @@ module.exports = {
4746 var filePattern = this . readConfig ( 'filePattern' ) ;
4847 var distDir = this . readConfig ( 'distDir' ) ;
4948 var distFiles = this . readConfig ( 'distFiles' ) || [ ] ;
50- var keep = this . readConfig ( 'keep' ) ;
5149
5250 this . log ( 'gzipping `' + filePattern + '`' ) ;
53- return this . _gzipFiles ( distDir , distFiles , filePattern , keep )
51+ return this . _gzipFiles ( distDir , distFiles , filePattern )
5452 . then ( function ( gzippedFiles ) {
5553 self . log ( 'gzipped ' + gzippedFiles . length + ' files ok' ) ;
5654 return { gzippedFiles : gzippedFiles } ;
5755 } )
5856 . catch ( this . _errorMessage . bind ( this ) ) ;
5957 } ,
60- _gzipFiles : function ( distDir , distFiles , filePattern , keep ) {
58+ _gzipFiles : function ( distDir , distFiles , filePattern , gzipLibrary ) {
6159 var filesToGzip = distFiles . filter ( minimatch . filter ( filePattern , { matchBase : true } ) ) ;
62- return Promise . map ( filesToGzip , this . _gzipFile . bind ( this , distDir , keep ) ) ;
60+ return Promise . map ( filesToGzip , this . _gzipFileInPlace . bind ( this , distDir ) ) ;
6361 } ,
64- _gzipFile : function ( distDir , keep , filePath ) {
62+ _gzipFileInPlace : function ( distDir , filePath ) {
6563 var self = this ;
6664 var fullPath = path . join ( distDir , filePath ) ;
67- var outFilePath = fullPath + '.gz' ;
6865 return new Promise ( function ( resolve , reject ) {
6966 var gzip = self . gzipLibrary . createGzip ( { format : 'gzip' } ) ;
7067 var inp = fs . createReadStream ( fullPath ) ;
71- var out = fs . createWriteStream ( outFilePath ) ;
68+ var out = fs . createWriteStream ( fullPath + '.gz' ) ;
7269
7370 inp . pipe ( gzip ) . pipe ( out ) ;
7471 inp . on ( 'error' , function ( err ) {
@@ -81,14 +78,10 @@ module.exports = {
8178 resolve ( ) ;
8279 } ) ;
8380 } ) . then ( function ( ) {
84- if ( ! keep ) {
85- outFilePath = fullPath ;
86- return renameFile ( fullPath + '.gz' , fullPath ) ;
87- }
81+ return renameFile ( fullPath + '.gz' , fullPath ) ;
8882 } ) . then ( function ( ) {
89- self . log ( '✔ ' + outFilePath ) ;
90-
91- return outFilePath ;
83+ self . log ( '✔ ' + filePath ) ;
84+ return filePath ;
9285 } ) ;
9386 } ,
9487 _errorMessage : function ( error ) {
0 commit comments