Permalink
Browse files

default handling of headers, warning, and error logs

  • Loading branch information...
1 parent 3a6fa83 commit 9b72833e1bd1f4b3f284e668acb690c1d5eac424 @rburns rburns committed Jul 15, 2012
Showing with 64 additions and 1 deletion.
  1. BIN img/error.png
  2. BIN img/ok.png
  3. +64 −1 tasks/growl.js
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -8,7 +8,10 @@
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
// helper creation: https://github.com/cowboy/grunt/blob/master/docs/toc.md
@@ -28,11 +31,71 @@ module.exports = function(grunt) {
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
// ==========================================================================
function growlMessage(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.