Skip to content

Commit a4bdbb4

Browse files
committed
Support for working with a gzip plugin.
If the deployment context has a gzippedFiles list, then gzipped files will be uploaded with a ContentEncoding param equal to 'gzip'.
1 parent 904933c commit a4bdbb4

File tree

3 files changed

+44
-10
lines changed

3 files changed

+44
-10
lines changed

index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
var Promise = require('ember-cli/lib/ext/promise');
55
var minimatch = require('minimatch');
6-
var path = require('path');
76

87
var chalk = require('chalk');
98
var blue = chalk.blue;
@@ -60,6 +59,7 @@ module.exports = {
6059
var filePattern = config.filePattern;
6160
var distDir = context.distDir;
6261
var distFiles = context.distFiles || [];
62+
var gzippedFiles = context.gzippedFiles || []; // e.g. from ember-cli-deploy-gzip
6363
var filesToUpload = distFiles.filter(minimatch.filter(filePattern, { matchBase: true }));
6464

6565
var s3 = context.s3Client || new S3({
@@ -69,8 +69,9 @@ module.exports = {
6969
});
7070

7171
var options = {
72-
cwd: context.distDir,
72+
cwd: distDir,
7373
filePaths: filesToUpload,
74+
gzippedFilePaths: gzippedFiles,
7475
prefix: config.prefix,
7576
bucket: config.bucket
7677
};

lib/s3.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,15 @@ module.exports = CoreObject.extend({
3030
upload: function(options) {
3131
options = options || {};
3232

33-
var ui = this._ui;
34-
var cwd = options.cwd;
35-
var bucket = options.bucket;
36-
var prefix = options.prefix;
37-
var acl = options.acl || 'public-read';
38-
var filePaths = options.filePaths || [];
39-
var cacheControl = 'max-age='+TWO_YEAR_CACHE_PERIOD_IN_SEC+', public';
40-
var expires = EXPIRE_IN_2030;
33+
var ui = this._ui;
34+
var cwd = options.cwd;
35+
var bucket = options.bucket;
36+
var prefix = options.prefix;
37+
var acl = options.acl || 'public-read';
38+
var filePaths = options.filePaths || [];
39+
var gzippedFilePaths = options.gzippedFilePaths || [];
40+
var cacheControl = 'max-age='+TWO_YEAR_CACHE_PERIOD_IN_SEC+', public';
41+
var expires = EXPIRE_IN_2030;
4142

4243
if (typeof filePaths === 'string') {
4344
filePaths = [filePaths];
@@ -48,6 +49,7 @@ module.exports = CoreObject.extend({
4849
var data = fs.readFileSync(basePath);
4950
var contentType = mime.lookup(basePath);
5051
var key = path.join(prefix, filePath);
52+
var isGzipped = gzippedFilePaths.indexOf(filePath) !== -1;
5153

5254
var params = {
5355
Bucket: bucket,
@@ -58,6 +60,9 @@ module.exports = CoreObject.extend({
5860
CacheControl: cacheControl,
5961
Expires: expires
6062
};
63+
if (isGzipped) {
64+
params.ContentEncoding = 'gzip';
65+
}
6166

6267
return new Promise(function(resolve, reject) {
6368
this._client.putObject(params, function(error, data) {

tests/unit/index-nodetest.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,5 +149,33 @@ describe('s3 plugin', function() {
149149
assert.match(mockUi.messages[1], /- something bad went wrong/);
150150
});
151151
});
152+
153+
it('sets the appropriate header if the file is inclued in gzippedFiles list', function(done) {
154+
var plugin = subject.createDeployPlugin({
155+
name: 's3'
156+
});
157+
158+
context.gzippedFiles = ['app.css'];
159+
var assertionCount = 0;
160+
context.client = {
161+
putObject: function(params, cb) {
162+
if (params.Key === 'app.css') {
163+
assert.equal(params.ContentEncoding, 'gzip');
164+
assertionCount++;
165+
} else {
166+
assert.isUndefined(params.ContentEncoding);
167+
assertionCount++;
168+
}
169+
cb();
170+
}
171+
};
172+
173+
return assert.isFulfilled(plugin.upload.call(plugin, context)).then(function(){
174+
assert.equal(assertionCount, 2);
175+
done();
176+
}).catch(function(reason){
177+
done(reason.actual.stack);
178+
});
179+
});
152180
});
153181
});

0 commit comments

Comments
 (0)