From a2846533f5848be7c720aa44dda5c0c737f5ad0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Teixeira?= Date: Thu, 15 Dec 2016 11:37:27 +0000 Subject: [PATCH] fix: #26 correctly upload gzipped files --- README.md | 11 ++++++++++- index.js | 15 ++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 05a7245..68c778e 100644 --- a/README.md +++ b/README.md @@ -168,10 +168,18 @@ Enable adding a meta tag with the current revisionKey into the head of your `ind ### replaceFiles -At deploy-time, the plugin will check your Sentry instance for an existing release under the current `revisionKey`. If a release is found and this is set to `true`, all existing files for the matching release will be deleted before the current build's files are uploaded to Sentry. If this is set to `false`, the files on Sentry will remain untouched and the just-built files will not be uploaded. +At deploy-time, the plugin will check your Sentry instance for an existing release under the current `revisionKey`. If a release is found and this is set to `true`, all existing files for the matching release will be deleted before the current build's files are uploaded to Sentry. If this is set to `false`, the files on Sentry will remain untouched and the just-built files will not be uploaded. *Default* true +### gzippedFiles + +The list of files that have been gziped. This option should be relative to `distDir`. By default, this option will use the `gzippedFiles` property of the deployment context, provided by [ember-cli-deploy-gzip][13]. + +This option will be used to determine which files in `distDir`, that match `filePattern`, require the gzip content encoding when uploading. + +*Default:* `context.gzippedFiles` + ## Prerequisites The following properties are expected to be present on the deployment `context` object: @@ -225,3 +233,4 @@ It works. We use it in production at [Hatchet](https://hatchet.is). [10]: http://ember-cli.github.io/ember-cli-deploy/plugins "Plugin Documentation" [11]: https://github.com/zapnito/ember-cli-deploy-build "ember-cli-deploy-build" [12]: https://github.com/zapnito/ember-cli-deploy-revision-data "ember-cli-deploy-revision-data" +[13]: https://github.com/lukemelia/ember-cli-deploy-gzip "ember-cli-deploy-gzip" \ No newline at end of file diff --git a/index.js b/index.js index db33782..3523f98 100644 --- a/index.js +++ b/index.js @@ -45,7 +45,11 @@ module.exports = { + this.readConfig('revisionKey') + '/'; }, - replaceFiles: true + replaceFiles: true, + + gzippedFiles: function(context) { + return context.gzippedFiles || []; // e.g. from ember-cli-deploy-gzip + } }, requiredConfig: ['publicUrl', 'sentryUrl', 'sentryOrganizationSlug', 'sentryProjectSlug', 'sentryApiKey', 'revisionKey'], @@ -147,6 +151,11 @@ module.exports = { throw new SilentError('Creating release failed'); }); }, + _isFileGzipped(filePath) { + var gzippedFiles = this.readConfig('gzippedFiles') || []; + var isGzipped = gzippedFiles.indexOf(filePath) >= 0; + return isGzipped; + }, _doUpload: function doUpload() { return this._getFilesToUpload() .then(this._uploadFileList.bind(this)); @@ -185,6 +194,10 @@ module.exports = { file: fs.createReadStream(fileName), }; + if (this._isFileGzipped(filePath)) { + formData.header = 'content-encoding:gzip'; + } + return request({ uri: urljoin(this.releaseUrl, 'files/'), method: 'POST',