Created
February 7, 2014 15:57
-
-
Save shellscape/8865569 to your computer and use it in GitHub Desktop.
overriding grunt output
This file contains 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
// -------- | |
var hooker = require('hooker'), | |
prefix, | |
newline = true; | |
// Override grunt.log.header to update a per-line prefix and prevent default logging. | |
hooker.hook(grunt.log, 'header', function () { | |
prefix = '[' + grunt.task.current.nameArgs + '] '; | |
return hooker.preempt(); | |
}); | |
// Override process.stdout to log the name+args of the current task before every logged line. | |
hooker.hook(process.stdout, 'write', function (str) { | |
str = String(str); | |
if (newline) { | |
if (str === '\n') { | |
return hooker.preempt(); | |
} else if (prefix) { | |
str = prefix + str.replace(/(\n)(?!$)/g, '$1' + prefix); | |
} | |
} | |
newline = str.slice(-1) === '\n'; | |
return hooker.filter(this, [str]); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment