Skip to content

Instantly share code, notes, and snippets.

@shellscape
Created February 7, 2014 15:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shellscape/8865569 to your computer and use it in GitHub Desktop.
Save shellscape/8865569 to your computer and use it in GitHub Desktop.
overriding grunt output
// --------
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