broccoli-asset-rewrite
Advanced tools
Comparing version 1.0.0 to 1.0.1
28
index.js
@@ -19,2 +19,4 @@ var Filter = require('broccoli-filter'); | ||
this.ignore = options.ignore || []; // files to ignore | ||
this.assetMapKeys = null; | ||
} | ||
@@ -38,2 +40,6 @@ | ||
AssetRewrite.prototype.canProcessFile = function(relativePath) { | ||
if (!this.assetMapKeys) { | ||
this.generateAssetMapKeys(); | ||
} | ||
if (!this.inverseAssetMap) { | ||
@@ -105,3 +111,5 @@ var inverseAssetMap = {}; | ||
for (var key in this.assetMap) { | ||
for (var i = 0, keyLength = this.assetMapKeys.length; i < keyLength; i++) { | ||
var key = this.assetMapKeys[i]; | ||
if (this.assetMap.hasOwnProperty(key)) { | ||
@@ -132,2 +140,20 @@ /* | ||
AssetRewrite.prototype.generateAssetMapKeys = function () { | ||
var keys = Object.keys(this.assetMap); | ||
keys.sort(function (a, b) { | ||
if (a.length < b.length) { | ||
return 1; | ||
} | ||
if (a.length > b.length) { | ||
return -1; | ||
} | ||
return 0; | ||
}); | ||
this.assetMapKeys = keys; | ||
} | ||
function escapeRegExp(string) { | ||
@@ -134,0 +160,0 @@ return string.replace(/([.*+?^${}()|\[\]\/\\])/g, "\\$1"); |
{ | ||
"name": "broccoli-asset-rewrite", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "broccoli plugin to rewrite a source tree from an asset map.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -106,2 +106,21 @@ var fs = require('fs'); | ||
}); | ||
it('replaces the correct match for the file extension', function () { | ||
var sourcePath = 'tests/fixtures/extensions'; | ||
var tree = rewrite(sourcePath + '/input', { | ||
assetMap: { | ||
'fonts/roboto-regular.eot': 'fonts/roboto-regular-f1.eot', | ||
'fonts/roboto-regular.woff': 'fonts/roboto-regular-f3.woff', | ||
'fonts/roboto-regular.ttf': 'fonts/roboto-regular-f4.ttf', | ||
'fonts/roboto-regular.svg': 'fonts/roboto-regular-f5.svg', | ||
'fonts/roboto-regular.woff2': 'fonts/roboto-regular-f2.woff2' | ||
} | ||
}); | ||
builder = new broccoli.Builder(tree); | ||
return builder.build().then(function (graph) { | ||
confirmOutput(graph.directory, sourcePath + '/output'); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17533
41
291