Skip to content

Commit

Permalink
refactor(generate): replace #getStream with fse#createOutputStream
Browse files Browse the repository at this point in the history
  • Loading branch information
Johnny Estilles committed Jun 4, 2015
1 parent 7c8e257 commit 2d252d8
Showing 1 changed file with 16 additions and 20 deletions.
36 changes: 16 additions & 20 deletions tasks/lib/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,23 @@

var debug = require('debug')('changelog:generate');
var q = require('q');

function writeChangelogDone(deferred) {
deferred.resolve(this.options);
}

function writeCommitsToStream(deferred, commits, stream) {
this.writeChangelog(stream, commits)
.then(writeChangelogDone.bind(this, deferred));
}
var fse = require('fs-extra');

function generateFromCommits(deferred, commits) {
var stream;

this.message('parsed commits', commits.length);
this.log('Parsed', commits.length, 'commits');
this.log('Generating changelog to', this.options.file || 'stdout', '(', this.options.version, ')');

this.getStream(this.options.file)
.then(writeCommitsToStream.bind(this, deferred, commits));
}
if (this.options.file) {
stream = fse.createOutputStream(this.options.file);
} else {
stream = process.stdout;
}

function handleReadGitLogError(err) {
console.log('error', err);
this.writeChangelog(stream, commits)
.then(deferred.resolve.bind(deferred, this.options));
}

function generateFromTag(deferred, tag) {
Expand All @@ -40,13 +36,13 @@ function generateFromTag(deferred, tag) {

readGitLog()
.then(generateFromCommits.bind(this, deferred))
.catch(handleReadGitLogError);
.catch(console.log.bind(console, 'error'));
}

function handleGenerateError(deferred, err) {
console.log('Error generating changelog ', err);
deferred.reject(err);
}
// function handleGenerateError(deferred, err) {
// console.log('Error generating changelog ', err);
// deferred.reject(err);
// }

function generate(params) {
debug('generating ...');
Expand All @@ -56,7 +52,7 @@ function generate(params) {
this.init(params)
.then(this.getPreviousTag.bind(this))
.then(generateFromTag.bind(this, deferred))
.catch(handleGenerateError.bind(null, deferred));
.catch(deferred.reject.bind(deferred));

return deferred.promise;
}
Expand Down

0 comments on commit 2d252d8

Please sign in to comment.