@@ -22,6 +22,7 @@ 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 ,
2526 distDir : function ( context ) {
2627 return context . distDir ;
2728 } ,
@@ -46,26 +47,28 @@ module.exports = {
4647 var filePattern = this . readConfig ( 'filePattern' ) ;
4748 var distDir = this . readConfig ( 'distDir' ) ;
4849 var distFiles = this . readConfig ( 'distFiles' ) || [ ] ;
50+ var keep = this . readConfig ( 'keep' ) ;
4951
5052 this . log ( 'gzipping `' + filePattern + '`' ) ;
51- return this . _gzipFiles ( distDir , distFiles , filePattern )
53+ return this . _gzipFiles ( distDir , distFiles , filePattern , keep )
5254 . then ( function ( gzippedFiles ) {
5355 self . log ( 'gzipped ' + gzippedFiles . length + ' files ok' ) ;
5456 return { gzippedFiles : gzippedFiles } ;
5557 } )
5658 . catch ( this . _errorMessage . bind ( this ) ) ;
5759 } ,
58- _gzipFiles : function ( distDir , distFiles , filePattern , gzipLibrary ) {
60+ _gzipFiles : function ( distDir , distFiles , filePattern , keep ) {
5961 var filesToGzip = distFiles . filter ( minimatch . filter ( filePattern , { matchBase : true } ) ) ;
60- return Promise . map ( filesToGzip , this . _gzipFileInPlace . bind ( this , distDir ) ) ;
62+ return Promise . map ( filesToGzip , this . _gzipFile . bind ( this , distDir , keep ) ) ;
6163 } ,
62- _gzipFileInPlace : function ( distDir , filePath ) {
64+ _gzipFile : function ( distDir , keep , filePath ) {
6365 var self = this ;
6466 var fullPath = path . join ( distDir , filePath ) ;
67+ var outFilePath = fullPath + '.gz' ;
6568 return new Promise ( function ( resolve , reject ) {
6669 var gzip = self . gzipLibrary . createGzip ( { format : 'gzip' } ) ;
6770 var inp = fs . createReadStream ( fullPath ) ;
68- var out = fs . createWriteStream ( fullPath + '.gz' ) ;
71+ var out = fs . createWriteStream ( outFilePath ) ;
6972
7073 inp . pipe ( gzip ) . pipe ( out ) ;
7174 inp . on ( 'error' , function ( err ) {
@@ -78,10 +81,14 @@ module.exports = {
7881 resolve ( ) ;
7982 } ) ;
8083 } ) . then ( function ( ) {
81- return renameFile ( fullPath + '.gz' , fullPath ) ;
84+ if ( ! keep ) {
85+ outFilePath = fullPath ;
86+ return renameFile ( fullPath + '.gz' , fullPath ) ;
87+ }
8288 } ) . then ( function ( ) {
83- self . log ( '✔ ' + filePath ) ;
84- return filePath ;
89+ self . log ( '✔ ' + outFilePath ) ;
90+
91+ return outFilePath ;
8592 } ) ;
8693 } ,
8794 _errorMessage : function ( error ) {
0 commit comments