Skip to content

Commit

Permalink
Merge pull request #58 from trentmwillis/ignore-files
Browse files Browse the repository at this point in the history
Add option to ignore specific files from being added to the manifest
  • Loading branch information
trentmwillis authored Sep 12, 2017
2 parents 639ba9b + 0fc39bd commit 0ecc412
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 1 deletion.
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' ]
});
});

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

0 comments on commit 0ecc412

Please sign in to comment.