Skip to content

Commit e7969c4

Browse files
committed
Merge pull request #18 from jrjohnson/ignore-index-json
Add ignorePattern option for removing specific files
2 parents 7bd3aac + c2692ea commit e7969c4

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ Note: image files such as `.png`, `.jpg` and `.gif` should not be gzipped, as th
5757

5858
*Default:* `'\*\*/\*.{js,css,json,ico,map,xml,txt,svg,eot,ttf,woff,woff2}'`
5959

60+
### ignorePattern
61+
62+
Files matching this pattern will *not* be gzipped even if they match filePattern
63+
64+
*Default:* null
65+
6066
### distDir
6167

6268
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: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ module.exports = {
2121
name: options.name,
2222
defaultConfig: {
2323
filePattern: '**/*.{js,css,json,ico,map,xml,txt,svg,eot,ttf,woff,woff2}',
24+
ignorePattern: null,
2425
zopfli: false,
2526
keep: false,
2627
distDir: function(context){
@@ -44,13 +45,15 @@ module.exports = {
4445
willUpload: function(context) {
4546
var self = this;
4647

47-
var filePattern = this.readConfig('filePattern');
48-
var distDir = this.readConfig('distDir');
49-
var distFiles = this.readConfig('distFiles') || [];
50-
var keep = this.readConfig('keep');
48+
var filePattern = this.readConfig('filePattern');
49+
var ignorePattern = this.readConfig('ignorePattern');
50+
var distDir = this.readConfig('distDir');
51+
var distFiles = this.readConfig('distFiles') || [];
52+
var keep = this.readConfig('keep');
5153

5254
this.log('gzipping `' + filePattern + '`', { verbose: true });
53-
return this._gzipFiles(distDir, distFiles, filePattern, keep)
55+
this.log('ignoring `' + ignorePattern + '`', { verbose: true });
56+
return this._gzipFiles(distDir, distFiles, filePattern, ignorePattern, keep)
5457
.then(function(gzippedFiles) {
5558
self.log('gzipped ' + gzippedFiles.length + ' files ok', { verbose: true });
5659
if (keep) {
@@ -64,8 +67,13 @@ module.exports = {
6467
})
6568
.catch(this._errorMessage.bind(this));
6669
},
67-
_gzipFiles: function(distDir, distFiles, filePattern, keep) {
70+
_gzipFiles: function(distDir, distFiles, filePattern, ignorePattern, keep) {
6871
var filesToGzip = distFiles.filter(minimatch.filter(filePattern, { matchBase: true }));
72+
if (ignorePattern != null) {
73+
filesToGzip = filesToGzip.filter(function(path){
74+
return !minimatch(path, ignorePattern, { matchBase: true });
75+
});
76+
}
6977
return Promise.map(filesToGzip, this._gzipFile.bind(this, distDir, keep));
7078
},
7179
_gzipFile: function(distDir, keep, filePath) {

tests/unit/index-nodetest.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,22 +62,24 @@ describe('gzip plugin', function() {
6262
return previous;
6363
}, []);
6464

65-
assert.equal(messages.length, 5);
65+
assert.equal(messages.length, 6);
6666
});
6767

6868
it('adds default config to the config object', function() {
6969
plugin.configure(context);
7070
assert.isDefined(config.gzip.filePattern);
71+
assert.isDefined(config.gzip.ignorePattern);
7172
assert.isDefined(config.gzip.distDir);
7273
assert.isDefined(config.gzip.distFiles);
7374
assert.isDefined(config.gzip.zopfli);
7475
});
7576
});
76-
describe('with a filePattern, zopfli, distDir, and distFiles provided', function () {
77+
describe('with a filePattern, ignorePattern, zopfli, distDir, and distFiles provided', function () {
7778
beforeEach(function() {
7879
config = {
7980
gzip: {
8081
filePattern: '**/*.*',
82+
ignorePattern: '**/specific.thing',
8183
zopfli: false,
8284
keep: false,
8385
distDir: 'tmp/dist-deploy',
@@ -121,12 +123,14 @@ describe('gzip plugin', function() {
121123
distFiles: [
122124
'assets/foo.js',
123125
'assets/bar.notjs',
126+
'assets/ignore.js',
124127
],
125128
ui: mockUi,
126129
project: { name: function() { return 'test-project'; } },
127130
config: {
128131
gzip: {
129132
filePattern: '**/*.js',
133+
ignorePattern: '**/ignore.*',
130134
distDir: function(context){ return context.distDir; },
131135
distFiles: function(context){ return context.distFiles; }
132136
}
@@ -137,6 +141,7 @@ describe('gzip plugin', function() {
137141
if (!fs.existsSync(path.join(context.distDir, 'assets'))) { fs.mkdirSync(path.join(context.distDir, 'assets')); }
138142
fs.writeFileSync(path.join(context.distDir, context.distFiles[0]), 'alert("Hello foo world!");', 'utf8');
139143
fs.writeFileSync(path.join(context.distDir, context.distFiles[1]), 'alert("Hello bar world!");', 'utf8');
144+
fs.writeFileSync(path.join(context.distDir, context.distFiles[2]), 'alert("Hello ignore world!");', 'utf8');
140145
plugin.beforeHook(context);
141146
plugin.gzipLibrary = require('zlib');
142147
});
@@ -145,7 +150,7 @@ describe('gzip plugin', function() {
145150
return rimraf(context.distDir);
146151
});
147152

148-
it('gzips the matching files', function(done) {
153+
it('gzips the matching files which are not ignored', function(done) {
149154
return assert.isFulfilled(plugin.willUpload(context))
150155
.then(function(result) {
151156
assert.deepEqual(result, { gzippedFiles: ['assets/foo.js'] });

0 commit comments

Comments
 (0)