Created
November 1, 2012 02:28
-
-
Save 5509/3991257 to your computer and use it in GitHub Desktop.
Grunt building tasks with "OS X 10.8 Notification Center"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// you execute "$ [sudo] gem install terminal-notifier" before using this | |
// https://github.com/alloy/terminal-notifier | |
var proc = require('child_process'); | |
function showNotif(type, msg) { | |
var title = 'Grunt building task'; | |
var activateId = null; | |
var output = null; | |
if ( type === 'ok' ) { | |
msg = 'all tasks are done.'; | |
} else { | |
activateId = ' -activate "com.apple.Terminal"'; | |
} | |
output = [ | |
'terminal-notifier ', | |
'-message "', | |
msg, | |
'" -title "', | |
title, | |
(type !== 'ok') ? '" -subtitle "' + type : '', | |
'" -group ', | |
type, | |
activateId | |
].join(''); | |
proc.exec(output); | |
} | |
grunt.utils.hooker.hook(grunt, 'initConfig', { | |
once: true, | |
post: function() { | |
grunt.utils.hooker.hook(grunt.log, 'write', function(msg) { | |
msg = grunt.log.uncolor(msg); | |
if ( msg.match(/^Done,/) ) { | |
showNotif('ok'); | |
} | |
}); | |
grunt.utils.hooker.hook(grunt.fail, 'warn', function(error) { | |
if ( typeof error !== 'undefined' ) { | |
showNotif('warn', error.message); | |
} | |
}); | |
grunt.utils.hooker.hook(grunt.fail, 'error', function(msg) { | |
if ( typeof msg === 'string' ) { | |
showNotif('error', 'error'); | |
} | |
}); | |
grunt.utils.hooker.hook(grunt.log, 'ok', function(msg) { | |
if ( typeof msg === 'string' ) { | |
showNotif('ok'); | |
} | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment