Skip to content

Commit

Permalink
add ignoreFilePattern config option
Browse files Browse the repository at this point in the history
Allow specific files to be omitted from the manifest file.
  • Loading branch information
stephencattaneo authored and lukemelia committed May 27, 2017
1 parent d1f25a2 commit 2bfd9aa
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ Files matching this pattern will be included in the manifest.

_Default:_ `"**/*.{js,css,png,gif,ico,jpg,map,xml,txt,svg,swf,eot,ttf,woff,woff2}"`

### ignoreFilePattern

Files matching this pattern will _not_ be included in the manifest even if they match filePattern.

_Default:_ `null`

### manifestPath

The relative path that the manifest is written to.
Expand Down
15 changes: 11 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module.exports = {
name: options.name,
defaultConfig: {
filePattern: '**/*.{js,css,png,gif,ico,jpg,map,xml,txt,svg,swf,eot,ttf,woff,woff2}',
fileIgnorePattern: null,
manifestPath: 'manifest.txt',
distDir: function(context) {
return context.distDir;
Expand All @@ -26,14 +27,20 @@ module.exports = {
},

willUpload: function(/* context */) {
var filePattern = this.readConfig('filePattern');
var distDir = this.readConfig('distDir');
var distFiles = this.readConfig('distFiles');
var manifestPath = this.readConfig('manifestPath');
var filePattern = this.readConfig('filePattern');
var distDir = this.readConfig('distDir');
var distFiles = this.readConfig('distFiles');
var manifestPath = this.readConfig('manifestPath');
var fileIgnorePattern = this.readConfig('fileIgnorePattern');

this.log('generating manifest at `' + manifestPath + '`', { verbose: true });
try {
var filesToInclude = distFiles.filter(minimatch.filter(filePattern, { matchBase: true }));
if (fileIgnorePattern != null) {
filesToInclude = filesToInclude.filter(function(path) {
return !minimatch(path, fileIgnorePattern, { matchBase: true });
});
}
filesToInclude.sort();
var outputPath = path.join(distDir, manifestPath);
fs.writeFileSync(outputPath, filesToInclude.join('\n'));
Expand Down
22 changes: 21 additions & 1 deletion tests/index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ describe('manifest plugin', function() {

return previous;
}, []);
assert.equal(messages.length, 4);
assert.equal(messages.length, 5);
});

it('adds default config to the config object', function() {
Expand All @@ -93,6 +93,7 @@ describe('manifest plugin', function() {
assert.isDefined(config.manifest.manifestPath);
assert.isDefined(config.manifest.distDir);
assert.isDefined(config.manifest.distFiles);
assert.isDefined(config.manifest.fileIgnorePattern);
});
});
});
Expand All @@ -112,6 +113,7 @@ describe('manifest plugin', function() {
'assets/foo-178d195608c0b18cf0ec5e982b39cad8.js',
'assets/bar-da3d0fb7db52f8273550c11403df178f.css',
'index.html',
'baz.txt',
],
ui: mockUi,
project: { name: function() { return 'test-project'; } },
Expand All @@ -130,6 +132,7 @@ describe('manifest plugin', function() {
fs.writeFileSync(path.join(context.distDir, context.distFiles[0]), 'alert("Hello foo world!");', 'utf8');
fs.writeFileSync(path.join(context.distDir, context.distFiles[1]), 'body { color: red; }', 'utf8');
fs.writeFileSync(path.join(context.distDir, context.distFiles[2]), '<html>Hello world</html>', 'utf8');
fs.writeFileSync(path.join(context.distDir, context.distFiles[3]), 'Here are some notes.', 'utf8');
plugin.beforeHook(context);
});

Expand All @@ -138,6 +141,23 @@ describe('manifest plugin', function() {
});

it('includes the matching files in a manifest', function(done) {
var result = plugin.willUpload(context);
try {
var manifestContents = fs.readFileSync(path.join(context.distDir, 'manifest.txt'), { encoding: 'utf8' });
var lines = manifestContents.split("\n");
assert.equal(lines.length, 3);
assert.equal(lines[0], "assets/bar-da3d0fb7db52f8273550c11403df178f.css");
assert.equal(lines[1], "assets/foo-178d195608c0b18cf0ec5e982b39cad8.js");
assert.equal(lines[2], "baz.txt");
assert.deepEqual(result, { manifestPath: 'manifest.txt' });
done();
} catch(err) {
done(err);
}
});

it('excludes files matching the fileIgnorePattern from the manifest', function(done) {
context.config.manifest.fileIgnorePattern = 'baz.txt'
var result = plugin.willUpload(context);
try {
var manifestContents = fs.readFileSync(path.join(context.distDir, 'manifest.txt'), { encoding: 'utf8' });
Expand Down

0 comments on commit 2bfd9aa

Please sign in to comment.