diff --git a/index.js b/index.js index a9fabf5..2bedc63 100644 --- a/index.js +++ b/index.js @@ -10,6 +10,8 @@ var _ = require('lodash'); function conventionalChangelogWriter(context, options) { var savedKeyCommit; var commits = []; + var firstGeneration = true; + var neverGenerated = true; context = _.extend({ commit: 'commits', @@ -78,7 +80,6 @@ function conventionalChangelogWriter(context, options) { options.commitsSort = util.functionify(options.commitsSort); options.noteGroupsSort = util.functionify(options.noteGroupsSort); options.notesSort = util.functionify(options.notesSort); - var firstGeneration = true; return through.obj(function(chunk, enc, cb) { try { @@ -93,6 +94,7 @@ function conventionalChangelogWriter(context, options) { } if (generateOn(keyCommit, commits, context, options)) { + neverGenerated = false; result = util.generate(options, commits, context, keyCommit); if (options.includeDetails) { this.push({ @@ -107,6 +109,7 @@ function conventionalChangelogWriter(context, options) { } } else { if (generateOn(keyCommit, commits, context, options)) { + neverGenerated = false; result = util.generate(options, commits, context, savedKeyCommit); if (!firstGeneration || options.doFlush) { @@ -136,7 +139,7 @@ function conventionalChangelogWriter(context, options) { cb(err); } }, function(cb) { - if (!options.doFlush && options.reverse) { + if (!options.doFlush && (options.reverse || neverGenerated)) { cb(null); return; } diff --git a/test/index.spec.js b/test/index.spec.js index 73b93c7..43cd2e6 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -536,7 +536,7 @@ describe('conventionalChangelogWriter', function() { })); }); - it('should not flush', function(done) { + it('should not flush when previous release is generated', function(done) { var i = 0; var upstream = through.obj(); @@ -573,6 +573,37 @@ describe('conventionalChangelogWriter', function() { done(); })); }); + + it('should not flush when it is the only potential release', function(done) { + var i = 0; + + var upstream = through.obj(); + upstream.write({ + header: 'feat(scope): broadcast $destroy event on scope destruction', + body: null, + footer: null, + notes: [{ + title: 'BREAKING CHANGE', + text: 'No backward compatibility.' + }], + references: [], + committerDate: '2015-04-07 14:17:05 +1000' + }); + upstream.end(); + + upstream + .pipe(conventionalChangelogWriter({ + version: 'v2.0.0' + }, { + doFlush: false + })) + .pipe(through(function() { + done(new Error('should not flush when it is the only potential release')); + }, function() { + expect(i).to.equal(0); + done(); + })); + }); }); describe('when commits are reversed', function() { @@ -710,7 +741,7 @@ describe('conventionalChangelogWriter', function() { })); }); - it('should not flush', function(done) { + it('should not flush when previous release is generated', function(done) { var i = 0; var upstream = through.obj(); @@ -749,6 +780,38 @@ describe('conventionalChangelogWriter', function() { })); }); }); + + it('should not flush when it is the only potential release', function(done) { + var i = 0; + + var upstream = through.obj(); + upstream.write({ + header: 'feat(scope): broadcast $destroy event on scope destruction', + body: null, + footer: null, + notes: [{ + title: 'BREAKING CHANGE', + text: 'No backward compatibility.' + }], + references: [], + committerDate: '2015-04-07 14:17:05 +1000' + }); + upstream.end(); + + upstream + .pipe(conventionalChangelogWriter({ + version: 'v2.0.0' + }, { + reverse: true, + doFlush: false + })) + .pipe(through(function() { + done(new Error('should not flush when it is the only potential release')); + }, function() { + expect(i).to.equal(0); + done(); + })); + }); }); it('should sort notes on `text` by default', function(done) {