broccoli-glob-caching-writer
Advanced tools
Comparing version 0.0.1 to 0.0.2
18
index.js
@@ -36,3 +36,4 @@ var path = require('path') | ||
var destDir = this.destDir | ||
var hash = this.hashDirs(srcDirs) | ||
var files = this.findFiles(srcDirs) | ||
var hash = this.hashFiles(files) | ||
if (hash !== this.cachedHash) { | ||
@@ -42,3 +43,3 @@ destDir = quickTemp.makeOrRemake(this, 'destDir') | ||
var srcArg = srcDirs.length ? srcDirs : srcDirs[0] | ||
this.cachedResult = this.updateCache(srcArg, destDir) | ||
this.cachedResult = this.updateCache(srcArg, destDir, files) | ||
} | ||
@@ -49,8 +50,5 @@ return Q.when(this.cachedResult).then(function() { return destDir }) | ||
/** | ||
* Calculates hash of all files mathing globs in srcDirs. | ||
* @param srcDirs {array.<string>} | ||
*/ | ||
CachingWriter.prototype.hashDirs = function(srcDirs) { | ||
var files = _.flatten(_.map(srcDirs, function(srcDir) { | ||
//Finds all files mathing globs in srcDirs | ||
CachingWriter.prototype.findFiles = function(srcDirs) { | ||
return _.flatten(_.map(srcDirs, function(srcDir) { | ||
var files = multiglob.sync(this.options.files, { | ||
@@ -65,3 +63,6 @@ cwd: srcDir, | ||
}, this)) | ||
} | ||
//Calculates hash of all files. | ||
CachingWriter.prototype.hashFiles = function(files) { | ||
var keys = [] | ||
@@ -72,3 +73,2 @@ _.each(files, function(file) { | ||
}) | ||
return crypto.createHash('md5').update(keys.join('')).digest('hex') | ||
@@ -75,0 +75,0 @@ } |
{ | ||
"name": "broccoli-glob-caching-writer", | ||
"version": "0.0.1", | ||
"description": "Caching writer for broccoli that allows to specify files that need to be cached with glob patterns.", | ||
"version": "0.0.2", | ||
"description": "Caching writer for broccoli that allows to specify files that need to be cached using glob patterns.", | ||
"repository": { | ||
@@ -6,0 +6,0 @@ "type": "git", |
#broccoli-glob-caching-writer | ||
Similar to [broccoli-caching-writer](https://github.com/rwjblue/broccoli-caching-writer) | ||
but allows to specify files that need to be cached with glob patterns. | ||
but allows to specify files that need to be cached using glob patterns. | ||
@@ -62,3 +62,3 @@ ##Install | ||
###CachingWriter.prototype.updateCache(srcDirs, destDir) | ||
###CachingWriter.prototype.updateCache(srcDirs, destDir, cachedFiles) | ||
@@ -82,2 +82,9 @@ This method creates build results, it must be implemented in inherited class. | ||
####cachedFiles | ||
Type: `array.<string>` | ||
Array of cached files. | ||
Paths are absolute. | ||
##License | ||
@@ -84,0 +91,0 @@ |
@@ -124,3 +124,3 @@ var assert = require('assert') | ||
it('is called with destDir', function() { | ||
it('is called with destDir as second arg', function() { | ||
var Writer = createWriterWithSpy() | ||
@@ -136,2 +136,13 @@ var tree = Writer(DIR) | ||
it('is called with cachedFiles as third arg', function() { | ||
var Writer = createWriterWithSpy() | ||
var tree = Writer(DIR) | ||
builder = new broccoli.Builder(tree) | ||
return builder.build() | ||
.then(function() { | ||
var files = tree.updateCache.getCall(0).args[2] | ||
assert.deepEqual(files, [path.join(DIR, 'file.css'), path.join(DIR, 'file.js')]) | ||
}) | ||
}) | ||
it('files written to the destDir will be in the final output', function() { | ||
@@ -138,0 +149,0 @@ var FILE = 'file' |
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
12597
246
92