diff --git a/lib/asset-manifest-generator.js b/lib/asset-manifest-generator.js index 66a02c7..4672495 100644 --- a/lib/asset-manifest-generator.js +++ b/lib/asset-manifest-generator.js @@ -19,6 +19,7 @@ function AssetManifestGenerator(inputTrees, options) { options = options || {}; this.prepend = options.prepend || ''; + this.filesToIgnore = options.filesToIgnore || []; this.supportedTypes = options.supportedTypes || DEFAULT_SUPPORTED_TYPES; this.generateURI = options.generateURI || function generateURI(filePath) { return filePath; @@ -59,6 +60,7 @@ AssetManifestGenerator.prototype.build = function() { var supportedTypes = this.supportedTypes; var generateURI = this.generateURI; var prepend = this.prepend; + var filesToIgnore = this.filesToIgnore; var inputPath = this.inputPaths[0]; var existingManifestPath = this.inputPaths[1]; var existingManifest; @@ -102,7 +104,7 @@ AssetManifestGenerator.prototype.build = function() { else if (assetName && bundleName) { var assetType = assetName.split('.').pop(); - if (supportedTypes.indexOf(assetType) !== -1) { + if (supportedTypes.indexOf(assetType) !== -1 && !stringOrRegexMatch(filesToIgnore, entry)) { // only add non-empty assets let fullPath = path.join(inputPath, entry); @@ -125,4 +127,18 @@ AssetManifestGenerator.prototype.build = function() { fs.writeJsonSync(manifestFile, manifest, { spaces: 2 }); }; +function stringOrRegexMatch(matchers, value) { + for (var i = 0; i < matchers.length; i++) { + var matcher = matchers[i]; + + if (typeof matcher === 'string' && matcher === value) { + return true; + } else if (matcher instanceof RegExp && matcher.test(value)) { + return true; + } + } + + return false; +} + module.exports = AssetManifestGenerator; diff --git a/lib/generate-asset-manifest.js b/lib/generate-asset-manifest.js index 7a359c2..5685556 100644 --- a/lib/generate-asset-manifest.js +++ b/lib/generate-asset-manifest.js @@ -22,6 +22,7 @@ module.exports = function generateAssetManifest(tree, options) { options = options || {}; var bundlesLocation = options.bundlesLocation || 'bundles'; + var filesToIgnore = options.filesToIgnore || []; var supportedTypes = options.supportedTypes; var generateURI = options.generateURI; var appName = options.appName; @@ -44,6 +45,7 @@ module.exports = function generateAssetManifest(tree, options) { generateURI: generateURI, supportedTypes: supportedTypes, prepend: '/' + bundlesLocation, + filesToIgnore: filesToIgnore, annotation: 'Asset Manifest Generator' }); diff --git a/node-tests/asset-manifest-generator-test.js b/node-tests/asset-manifest-generator-test.js index 6f3b4e7..6d44692 100644 --- a/node-tests/asset-manifest-generator-test.js +++ b/node-tests/asset-manifest-generator-test.js @@ -62,6 +62,20 @@ describe('asset-manifest-generator', function() { return verifyAssetManifest('resources', { prepend: '/resources/' }); }); + it('can ignore specific files', function() { + return verifyAssetManifest('full-minus-ignored-files', { + prepend: '/bundles', + filesToIgnore: [ 'blog/assets/engine.css', 'chat/assets/engine.js' ] + }); + }); + + it('can ignore specific files using regex', function() { + return verifyAssetManifest('full-minus-ignored-files', { + prepend: '/bundles', + filesToIgnore: [ /(blog\/assets\/engine\.css|chat\/assets\/engine\.js)/ ] + }); + }); + it('merges with an existing manifest', function() { var existingManifest = path.join(manifestsPath, 'existing'); return verifyAssetManifest('full-plus-existing', { prepend: '/bundles' }, existingManifest); diff --git a/node-tests/fixtures/manifests/full-minus-ignored-files.json b/node-tests/fixtures/manifests/full-minus-ignored-files.json new file mode 100644 index 0000000..e834dda --- /dev/null +++ b/node-tests/fixtures/manifests/full-minus-ignored-files.json @@ -0,0 +1,67 @@ +{ + "bundles": { + "blog": { + "assets": [ + { + "uri": "/bundles/blog/assets/engine.js", + "type": "js" + }, + { + "uri": "/bundles/blog/assets/vendor.css", + "type": "css" + }, + { + "uri": "/bundles/blog/assets/vendor.js", + "type": "js" + }, + { + "uri": "/bundles/blog/shared/addon.css", + "type": "css" + }, + { + "uri": "/bundles/blog/shared/addon.js", + "type": "js" + } + ], + "dependencies": [ + "shared" + ] + }, + "chat": { + "assets": [ + { + "uri": "/bundles/chat/assets/engine.css", + "type": "css" + }, + { + "uri": "/bundles/chat/assets/vendor.css", + "type": "css" + }, + { + "uri": "/bundles/chat/assets/vendor.js", + "type": "js" + } + ] + }, + "shared": { + "assets": [ + { + "uri": "/bundles/shared/assets/addon.css", + "type": "css" + }, + { + "uri": "/bundles/shared/assets/addon.js", + "type": "js" + }, + { + "uri": "/bundles/shared/assets/vendor.css", + "type": "css" + }, + { + "uri": "/bundles/shared/assets/vendor.js", + "type": "js" + } + ] + } + } +} diff --git a/node-tests/generate-asset-manifest-test.js b/node-tests/generate-asset-manifest-test.js index b61a357..b4bba84 100644 --- a/node-tests/generate-asset-manifest-test.js +++ b/node-tests/generate-asset-manifest-test.js @@ -64,6 +64,10 @@ describe('generate-asset-manifest', function() { return verifyAssetManifest('engines', { bundlesLocation: 'engines-dist' }); }); + it('can ignore specific files', function() { + return verifyAssetManifest('full-minus-ignored-files', { filesToIgnore: [ 'blog/assets/engine.css', 'chat/assets/engine.js' ] }); + }); + it('merges an existing manifest into the new one', co.wrap(function* () { var inputTree = path.join(fixturePath, 'existing-test'); var assetManifestTree = generateAssetManifest(inputTree);