broccoli-asset-rev
Advanced tools
Comparing version 1.0.1 to 1.1.0
@@ -16,3 +16,2 @@ var fs = require('fs'); | ||
this.assetMap = options.assetMap || {}; | ||
this.customHash = options.customHash; | ||
this.extensions = options.extensions || []; | ||
@@ -24,2 +23,10 @@ this.exclude = options.exclude || []; | ||
this.prepend = options.prepend; | ||
if (typeof options.customHash === 'function') { | ||
this.customHash = null; | ||
this.hashFn = options.customHash; | ||
} else { | ||
this.customHash = options.customHash; | ||
this.hashFn = md5Hash; | ||
} | ||
} | ||
@@ -65,5 +72,3 @@ | ||
} else { | ||
var md5 = crypto.createHash('md5'); | ||
md5.update(file); | ||
hash = md5.digest('hex'); | ||
hash = this.hashFn(file); | ||
} | ||
@@ -117,7 +122,4 @@ | ||
var assets = { assets: assetMap, files: files }; | ||
var contents = JSON.stringify(assets); | ||
var hash = ''; | ||
var md5 = crypto.createHash('md5'); | ||
md5.update(contents); | ||
hash = md5.digest('hex'); | ||
var contents = new Buffer(JSON.stringify(assets)); | ||
var hash = this.hashFn(contents); | ||
fs.writeFileSync(destDir + '/assets/manifest-' + hash + '.json', contents); | ||
@@ -140,2 +142,8 @@ }; | ||
function md5Hash(buf) { | ||
var md5 = crypto.createHash('md5'); | ||
md5.update(buf); | ||
return md5.digest('hex'); | ||
} | ||
module.exports = Fingerprint; |
{ | ||
"name": "broccoli-asset-rev", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "broccoli asset revisions (fingerprint)", | ||
@@ -5,0 +5,0 @@ "main": "lib/asset-rev.js", |
@@ -45,3 +45,3 @@ #broccoli-asset-rev | ||
- `generateRailsManifest` - Default: none - If true, will generate a `manifest.json` to be used by Sprockets for the Rails Asset Pipeline | ||
- `customHash` - Default: none - If defined, will be appended to filename instead of a md5 checksum. | ||
- `customHash` - Default: none - If set, overrides the md5 checksum calculation with the result of calling `customHash(buffer)`. If it is not a `function`, `customHash` is used as the hash value. | ||
@@ -48,0 +48,0 @@ ## Ember CLI addon usage |
var fs = require('fs'); | ||
var path = require('path'); | ||
var crypto = require('crypto'); | ||
var assert = require('assert'); | ||
@@ -79,2 +80,36 @@ var walkSync = require('walk-sync'); | ||
}); | ||
it('uses customHash string value', function(){ | ||
var sourcePath = 'tests/fixtures/customHash-simple'; | ||
var tree = assetRev(sourcePath + '/input', { | ||
extensions: ['js', 'css', 'png', 'jpg', 'gif'], | ||
replaceExtensions: ['html', 'js', 'css'], | ||
customHash: 'test' | ||
}); | ||
builder = new broccoli.Builder(tree); | ||
return builder.build().then(function(graph) { | ||
confirmOutput(graph.directory, sourcePath + '/output'); | ||
}); | ||
}); | ||
it('uses customHash function value', function(){ | ||
var sourcePath = 'tests/fixtures/customHash-function'; | ||
var tree = assetRev(sourcePath + '/input', { | ||
extensions: ['js', 'css', 'png', 'jpg', 'gif'], | ||
replaceExtensions: ['html', 'js', 'css'], | ||
customHash: function(buf) { | ||
var sha1 = crypto.createHash('sha1'); | ||
sha1.update(buf); | ||
return sha1.digest('hex'); | ||
} | ||
}); | ||
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
34594
48
352