Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to ignore specific files from being added to the manifest #58

Merged
merged 2 commits into from
Sep 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion lib/asset-manifest-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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;
2 changes: 2 additions & 0 deletions lib/generate-asset-manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -44,6 +45,7 @@ module.exports = function generateAssetManifest(tree, options) {
generateURI: generateURI,
supportedTypes: supportedTypes,
prepend: '/' + bundlesLocation,
filesToIgnore: filesToIgnore,
annotation: 'Asset Manifest Generator'
});

Expand Down
14 changes: 14 additions & 0 deletions node-tests/asset-manifest-generator-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' ]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor quibble about the naming, we have a similar concept in broccoli-funnel land and call it exclude. Thoughts?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I originally had this as ignore, but changed it because there may be a use case in the future where we want an entire "bundle" ignored, in which case we may want some added specificity. Also, I prefer the explicitness. That said, I don't feel super strongly about it either way.

});
});

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);
Expand Down
67 changes: 67 additions & 0 deletions node-tests/fixtures/manifests/full-minus-ignored-files.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
}
}
4 changes: 4 additions & 0 deletions node-tests/generate-asset-manifest-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down