Skip to content

Commit 6c41f40

Browse files
author
Francesco Novy
committed
Add fileIgnorePattern option
1 parent 83e0254 commit 6c41f40

File tree

3 files changed

+57
-2
lines changed

3 files changed

+57
-2
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,12 @@ Files that match this pattern will be uploaded to S3. The file pattern must be r
122122

123123
*Default:* '\*\*/\*.{js,css,png,gif,ico,jpg,map,xml,txt,svg,swf,eot,ttf,woff,woff2,otf,wasm}'
124124

125+
### fileIgnorePattern
126+
127+
Files matching this pattern will _not_ be uploaded even if they match filePattern.
128+
129+
*Default:* `null`
130+
125131
### distDir
126132

127133
The root directory where the files matching `filePattern` will be searched for. By default, this option will use the `distDir` property of the deployment context, provided by [ember-cli-deploy-build][2].

index.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module.exports = {
1717
name: options.name,
1818
defaultConfig: {
1919
filePattern: '**/*.{js,css,png,gif,ico,jpg,map,xml,txt,svg,swf,eot,ttf,woff,woff2,otf,wasm}',
20+
fileIgnorePattern: null,
2021
prefix: '',
2122
profile: '',
2223
acl: 'public-read',
@@ -53,6 +54,7 @@ module.exports = {
5354
var self = this;
5455

5556
var filePattern = this.readConfig('filePattern');
57+
var fileIgnorePattern = this.readConfig('fileIgnorePattern');
5658
var distDir = this.readConfig('distDir');
5759
var distFiles = this.readConfig('distFiles');
5860
var gzippedFiles = this.readConfig('gzippedFiles');
@@ -69,6 +71,17 @@ module.exports = {
6971
var defaultMimeType = this.readConfig('defaultMimeType');
7072

7173
var filesToUpload = distFiles.filter(minimatch.filter(filePattern, { matchBase: true, dot: dotFolders }));
74+
if (fileIgnorePattern) {
75+
filesToUpload = filesToUpload.filter(function(path) {
76+
return !minimatch(path, fileIgnorePattern, { matchBase: true });
77+
});
78+
gzippedFiles = gzippedFiles.filter(function(path) {
79+
return !minimatch(path, fileIgnorePattern, { matchBase: true });
80+
});
81+
brotliCompressedFiles = brotliCompressedFiles.filter(function(path) {
82+
return !minimatch(path, fileIgnorePattern, { matchBase: true });
83+
});
84+
}
7285

7386
var s3 = this.readConfig('uploadClient') || new S3({
7487
plugin: this

tests/index-test.js

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ describe('s3 plugin', function() {
5757
gzippedFiles: function(context) {
5858
return context.gzippedFiles || []; // e.g. from ember-cli-deploy-gzip
5959
},
60+
brotliCompressedFiles: function(context) {
61+
return context.brotliCompressedFiles || []; // e.g. from ember-cli-deploy-gzip
62+
},
6063
manifestPath: function(context) {
6164
return context.manifestPath; // e.g. from ember-cli-deploy-manifest
6265
},
@@ -235,6 +238,39 @@ describe('s3 plugin', function() {
235238
});
236239
});
237240

241+
it('filters out ignored files via fileIgnorePattern', function() {
242+
var plugin = subject.createDeployPlugin({
243+
name: 's3'
244+
});
245+
246+
context.config.s3.fileIgnorePattern = '*.css';
247+
context.gzippedFiles = ['app.css', 'app.js'];
248+
context.brotliCompressedFiles = ['app.css', 'app.js'];
249+
context.config.s3.fileIgnorePattern = '*.css';
250+
context.uploadClient.upload = function(options) {
251+
assert.equal(options.filePaths.length, 1, 'file paths are filtered');
252+
assert.equal(options.gzippedFilePaths.length, 1, 'gzipped file paths are filtered');
253+
assert.equal(options.brotliCompressedFilePaths.length, 1, 'brotli compressed file paths are filtered');
254+
return RSVP.resolve(options.filePaths);
255+
};
256+
plugin.beforeHook(context);
257+
258+
return assert.isFulfilled(plugin.upload(context))
259+
.then(function() {
260+
assert.equal(mockUi.messages.length, 2);
261+
262+
var messages = mockUi.messages.reduce(function(previous, current) {
263+
if (/- uploaded 1 files ok/.test(current)) {
264+
previous.push(current);
265+
}
266+
267+
return previous;
268+
}, []);
269+
270+
assert.equal(messages.length, 1);
271+
});
272+
});
273+
238274
it('prints an error message if the upload errors', function() {
239275
var plugin = subject.createDeployPlugin({
240276
name: 's3'
@@ -259,7 +295,7 @@ describe('s3 plugin', function() {
259295
name: 's3'
260296
});
261297

262-
var assertionCount = 0
298+
var assertionCount = 0;
263299
context.proxyAgent = function(/* proxy */) {
264300
assertionCount++;
265301
};
@@ -272,7 +308,7 @@ describe('s3 plugin', function() {
272308
});
273309
});
274310

275-
it('sets the appropriate header if the file is inclued in gzippedFiles list', function(done) {
311+
it('sets the appropriate header if the file is included in gzippedFiles list', function(done) {
276312
var plugin = subject.createDeployPlugin({
277313
name: 's3'
278314
});

0 commit comments

Comments
 (0)