Skip to content

Commit 1227681

Browse files
committed
Merge pull request #9 from dschmidt/keep
Add keep option
2 parents ad0a283 + ed3001b commit 1227681

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ If set to `true`, you will need to `npm install node-zopfli --save-dev` in your
7878

7979
*Default:* `false`
8080

81+
### keep
82+
83+
Keep original file and write compressed data to `originalFile.gz`
84+
85+
*Default:* `false`
86+
8187
## Prequisites
8288

8389
The following properties are expected to be present on the deployment `context` object:
@@ -97,8 +103,3 @@ The following properties are expected to be present on the deployment `context`
97103
[1]: http://ember-cli.github.io/ember-cli-deploy/plugins "Plugin Documentation"
98104
[2]: https://github.com/zapnito/ember-cli-deploy-build "ember-cli-deploy-build"
99105
[3]: https://github.com/zapnito/ember-cli-deploy-s3 "ember-cli-deploy-s3"
100-
101-
## TODO
102-
103-
Some deployment flows require side-by-side deployment of compressed and uncompressed
104-
assets. A PR to add this option would be welcome.

index.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)