Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First of all, use <a href="https://github.com/visionmedia/node-growl" rel="noreferrer">growl</a>. It is easy and flexible to use. To install <strong>growl</strong>:</p> <pre><code>npm install growl --save-dev </code></pre> <p>Then you need to <a href="http://gruntjs.com/api/grunt.util#grunt.util.hooker" rel="noreferrer">hook</a> into the stderr/out stream of the process. This way you can create a notification each time a new message arrives at the stderr/out stream.</p> <p>This is what I've created. I've made a CommonJs module which adds hooks to:</p> <ul> <li><code>grunt.fail.warn()</code>, <code>grunt.fail.fatal()</code></li> <li><code>grunt.log.warn()</code>, <code>grunt.log.error()</code></li> <li><code>grunt.warn()</code></li> <li><code>process.stderr.write()</code></li> <li><code>process.stdout.write()</code> (error lines)</li> <li>(child) <code>process.stderr.write()</code></li> <li>(child) <code>process.stdout.write()</code> (error lines)</li> </ul> <p>It works more or less, but it may need some tweaking.</p> <p><strong>tasks/lib/notify.js</strong></p> <pre><code>(function (module) { var grunt = require('grunt'), growl = require('growl'), Buffer = require('buffer').Buffer; function notify(obj, title) { if (obj) { var message = Buffer.isBuffer(obj) ? obj.toString() : (obj.message || obj); var msg = grunt.log.uncolor(message); if (msg.length &gt; 0) { growl(msg, { title: title, image: 'Console' }); } } } // add a hook to grunt.fail.warn(), grunt.fail.fatal() ['warn', 'fatal'].forEach(function (level) { grunt.util.hooker.hook(grunt.fail, level, function(obj) { notify(obj); }); }); // add a hook to grunt.log.warn(), grunt.log.error() ['warn', 'error'].forEach(function (level) { grunt.util.hooker.hook(grunt.log, level, function(obj) { notify(obj, level); }); }); // add a hook to grunt.warn() grunt.util.hooker.hook(grunt, 'warn', function(obj) { notify(obj, 'warn'); }); // add a hook to process.stderr.write() grunt.util.hooker.hook(process.stderr, 'write', function(obj) { var messages = grunt.log.uncolor((Buffer.isBuffer(obj) ? obj.toString() : (obj.message || obj))).split('\n'); messages.forEach(function (message) { notify(message, 'stderr'); }); }); // add a hook to process.stdout.write() (only error lines) grunt.util.hooker.hook(process.stdout, 'write', function(obj) { var messages = grunt.log.uncolor((Buffer.isBuffer(obj) ? obj.toString() : (obj.message || obj))).split('\n'); messages.forEach(function (message) { if (message &amp;&amp; message.indexOf('error ') &gt; -1) { notify(message, 'stdout'); } }); }); // add a hook to child process stdout/stderr write() (only error lines) grunt.util.hooker.hook(grunt.util, 'spawn', { post: function(child) { child.stderr.on('data', function (data) { var messages = grunt.log.uncolor(data.toString()).split('\n'); messages.forEach(function (message) { notify(message, 'stderr'); }); }); child.stdout.on('data', function (data) { var messages = grunt.log.uncolor(data.toString()).split('\n'); messages.forEach(function (message) { if (message &amp;&amp; message.indexOf('error ') &gt; -1) { notify(message, 'stdout'); } }); }); } }); }) (module); </code></pre> <p>Then you need to include it in your <strong>Gruntfile.js</strong> with a <code>require</code> statement:</p> <pre><code>module.exports = function (grunt) { grunt.initConfig({ ... }); require('./tasks/lib/notify'); ... }; </code></pre> <p>PS I've placed the file in <code>tasks/lib/notify.js</code>, but feel free to place it somewhere else.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload