Skip to content

Commit

Permalink
Compare to previous run time if src and dest are the same
Browse files Browse the repository at this point in the history
  • Loading branch information
tschaub committed Jan 13, 2014
1 parent ba0fb3f commit 3e49f48
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ var filterFilesByTime = exports.filterFilesByTime = function(files, previous,
// dest file not yet created, use all src files
return done(null, obj);
}
if (obj.src && obj.src.length === 1 && obj.src[0] === obj.dest) {
// when src and dest are same, compare to previous
return filterPathsByTime(obj.src, previous, function(err, src) {
if (err) {
return done(err);
}
done(null, {src: src, dest: obj.dest});
});
}
return anyNewer(obj.src, stats.mtime, function(err, any) {
done(err, any && obj);
});
Expand Down
26 changes: 26 additions & 0 deletions test/lib/util.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,32 @@ describe('util', function() {
});
});

it('provides newer src files if same as dest', function(done) {
var files = [{
src: ['src/js/a.js'],
dest: 'src/js/a.js'
}, {
src: ['src/js/b.js'],
dest: 'src/js/b.js'
}, {
src: ['src/js/c.js'],
dest: 'src/js/c.js'
}];
util.filterFilesByTime(files, new Date(150), function(err, results) {
assert.isNull(err);
assert.equal(results.length, 2);
var first = results[0];
assert.equal(first.dest, 'src/js/b.js');
assert.equal(first.src.length, 1);
assert.deepEqual(first.src, files[1].src);
var second = results[1];
assert.equal(second.dest, 'src/js/c.js');
assert.equal(second.src.length, 1);
assert.deepEqual(second.src, files[2].src);
done();
});
});

it('provides files newer than previous if no dest', function(done) {
var files = [{
src: ['src/js/a.js', 'src/js/b.js', 'src/js/c.js']
Expand Down

0 comments on commit 3e49f48

Please sign in to comment.