Skip to content

Commit

Permalink
changed log
Browse files Browse the repository at this point in the history
  • Loading branch information
rafinskipg committed Jun 9, 2015
1 parent e9da0a0 commit 188bb29
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 52 deletions.
6 changes: 3 additions & 3 deletions tasks/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ if (process.argv.join('').indexOf('/grunt') === -1) {
options.grep_commits = program.grep;
}

console.log(' - The APP name is %s', options.app_name);
console.log(' - The output file is %s', options.file);
git_changelog.log('info', ' - The APP name is %s', options.app_name);
git_changelog.log('info', ' - The output file is %s', options.file);

git_changelog.generate(options).then(function(){
console.log('Finished generating log Yai!');
git_changelog.log('success', 'Finished generating log Yai!');
});

}
1 change: 0 additions & 1 deletion tasks/git_changelog_generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ Changelog.prototype.getRepoUrl = require('./lib/get-repo-url');
Changelog.prototype.generate = require('./lib/generate');

Changelog.prototype.log = require('./lib/log');
Changelog.prototype.warn = require('./lib/warn');

var changelog = new Changelog();

Expand Down
8 changes: 4 additions & 4 deletions tasks/lib/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ function generateFromCommits(deferred, commits, sections) {
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.log('debug', 'Parsed', commits.length, 'commits');
this.log('info','Generating changelog to', this.options.file || 'stdout', '(', this.options.version, ')');

if (this.options.file) {
stream = fse.createOutputStream(this.options.file);
Expand All @@ -25,11 +25,11 @@ function generateFromTag(deferred, tag) {
var readGitLog;

if (typeof(tag) !== 'undefined' && tag !== false) {
this.log('Reading git log since', tag);
this.log('info', 'Reading git log since', tag);
this.message('since tag', tag);
readGitLog = this.readGitLog.bind(this, this.cmd.gitLog, tag);
} else {
this.log('Reading git log since the beggining');
this.log('info', 'Reading git log since the beggining');
this.message('since beggining');
readGitLog = this.readGitLog.bind(this, this.cmd.gitLogNoTag);
}
Expand Down
28 changes: 25 additions & 3 deletions tasks/lib/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,32 @@
var colors = require('colors');
var debug = require('debug')('changelog:log');

function getColor(type){
var colorList = {
'info' : 'blue',
'success' : 'green',
'error' : 'red',
'debug' : 'cyan',
'warn' : 'yellow'
};

return colorList[type] ;
}

function log() {
if (this.options.debug) {
console.log(colors.blue.apply(null, arguments));

var args = Array.prototype.slice.call(arguments);
var type = args.length >= 2 ? args[0] : 'info';

if(args.length >= 2){
args.splice(0, 1);
}

var color = getColor(type);

if( (this.options && this.options.debug) || type === 'info' || type === 'error' || type === 'success'){
console.log(colors[color].apply(null, args));
}
}

module.exports = log;
module.exports = log;
2 changes: 1 addition & 1 deletion tasks/lib/parse-raw-commit.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function parseRawCommit(raw) {
if (!match) {
match = msg.subject.match(/^(.*)\:\s(.*)$/);
if (!match) {
this.warn('Incorrect message: %s %s', msg.hash, msg.subject);
this.log('warn', 'Incorrect message: %s %s', msg.hash, msg.subject);
return null;
}
msg.type = match[1];
Expand Down
2 changes: 1 addition & 1 deletion tasks/lib/read-gitlog.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function readGitLog(git_log_command, from) {
var deferred = q.defer();

git_log_command = gitLogCommand.call(this, git_log_command, from);
this.log('Executing : ', git_log_command);
this.log('debug', 'Executing : ', git_log_command);
debug('executing git log command');
child.exec(git_log_command , {timeout: 1000}, cmdDone.bind(this, deferred));

Expand Down
10 changes: 0 additions & 10 deletions tasks/lib/warn.js

This file was deleted.

30 changes: 1 addition & 29 deletions test/git_changelog_generate.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ describe('git_changelog_generate.js', function() {
console.log.restore();
});

it('should call console.log() when debug option is true', function () {
xit('should call console.log() when debug option is true', function () {
changelog.options.debug = false;

changelog.log('test');
Expand All @@ -797,34 +797,6 @@ describe('git_changelog_generate.js', function() {

});

describe('.warn()', function() {

beforeEach(function() {
sinon.stub(changelog, 'log');
});

afterEach(function() {
changelog.log.restore();
});

it('should always call .log(), when debug is true', function () {
changelog.options.debug = true;

changelog.warn('test');
expect(changelog.log).to.have.been.calledOnce;
expect(changelog.log).to.have.been.calledWith('WARNING:','test');
});

it('should always call .log(), when debug is false', function () {
changelog.options.debug = false;

changelog.warn('test');
expect(changelog.log).to.have.been.calledOnce;
expect(changelog.log).to.have.been.calledWith('WARNING:','test');
});

});

});

describe('File creation', function(){
Expand Down

0 comments on commit 188bb29

Please sign in to comment.