Skip to content

Commit

Permalink
default handling of headers, warning, and error logs
Browse files Browse the repository at this point in the history
  • Loading branch information
rburns committed Jul 15, 2012
1 parent 3a6fa83 commit 9b72833
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
Binary file added img/error.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/ok.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
65 changes: 64 additions & 1 deletion tasks/growl.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@


module.exports = function(grunt) { module.exports = function(grunt) {


var growl = require('growl'); var growl = require('growl'),
path = require('path'),
messages = [],
ignoreWatch = false;


// Please see the grunt documentation for more information regarding task and // Please see the grunt documentation for more information regarding task and
// helper creation: https://github.com/cowboy/grunt/blob/master/docs/toc.md // helper creation: https://github.com/cowboy/grunt/blob/master/docs/toc.md
Expand All @@ -27,6 +30,54 @@ module.exports = function(grunt) {


grunt.registerHelper('growl', growlMessage); grunt.registerHelper('growl', growlMessage);


// ==========================================================================
// DEFAULT NOTIFICATIONS
// ==========================================================================

grunt.utils.hooker.hook(grunt.log, 'write', function(msg){
if( grunt.log.uncolor(msg).match(/Waiting.../) ) { flushMessages('ok'); }
});

grunt.utils.hooker.hook(grunt.log, 'header', function(msg){
msg = grunt.log.uncolor(msg);

if( ignoreWatch && msg.match(/"watch" task/) ) { return; }

if( msg.match(/".+:.+"/) ) { return; }

if( !ignoreWatch && msg.match(/"watch" task/) ) {
msg += ' for ' + path.basename(process.cwd());
ignoreWatch = true;
}

messages.push(msg);
});

grunt.utils.hooker.hook(grunt.log, 'ok', function(msg){
if( typeof msg === 'string' ) {
messages.push(grunt.log.uncolor(msg));
}
});

grunt.utils.hooker.hook(grunt, 'warn', function(error){
var warning = [];

if( typeof error !== 'undefined' ) {
warning.push(messages[0]);
warning.push(messages[messages.length-1]);
warning.push(String(error.message || error));
messages = warning;
flushMessages('error');
}
});

grunt.utils.hooker.hook(grunt.log, 'error', function(msg){
if( typeof msg === 'string' ) {
messages.push(grunt.log.uncolor(msg));
flushMessages('error');
}
});

// ========================================================================== // ==========================================================================
// SHARED FUNCTIONS // SHARED FUNCTIONS
// ========================================================================== // ==========================================================================
Expand All @@ -35,4 +86,16 @@ module.exports = function(grunt) {
growl(config.message, config); growl(config.message, config);
} }


function flushMessages(status) {
if( messages.length <= 0 ) {
return;
}

growlMessage({
message: messages.join('\n'),
title: 'Grunt',
image: __dirname + '/../img/' + status + '.png'
});
messages = [];
}
}; };

0 comments on commit 9b72833

Please sign in to comment.