7

I am attempting to setup grunt-notify with grunt-contrib-less and grunt-contrib-watch. Generally this is working well but I can't get grunt-notify to notify me when grunt-less is executed successfully.

If anyone has any insight on how to set this up or debug, happy to have any input.


Full info:

I have setup grunt-notify to trigger whenever less has run using a watch. This works great when the less task fails. Gives me a great pop-up error:

image

For reference this is the console output:

image

When less succeeds, I am not getting any notification. I would like to get a notification but cannot figure out how to enable this.

This is the console output when less succeeds:

image

This is the GruntFile that I am using:

module.exports = function(grunt) {

    grunt.initConfig({

        less: {
            development: {
                options: {
                    compress: true
                },
                files: {
                    "FILE.css": "FILE2.less"
                }
            }
        },

        watch: {
            less: {
                files: '**/*.less',
                tasks: ['less', 'notify_hooks']
            }
        },


        notify_hooks: {
            options: {
                message: "MESSAGE"
            }

        }


    });

    grunt.loadNpmTasks('grunt-contrib-less');
    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-notify');

    grunt.registerTask("default", ['less']);

};

Original question on Github

Cyril Gandon
  • 16,830
  • 14
  • 78
  • 122
sixtyfootersdude
  • 25,859
  • 43
  • 145
  • 213

2 Answers2

9

You need to add a message for your task to the gruntfile and specify which task it is going to give that message for. See below

notify: {
    less:{
        options:{
            title: "CSS Files built",
            message: "Less task complete"
        }
    }
}

For reference you can see them use in the git repo readme

Added for completeness:

As uKolka has mentioned below, you will also require the watch task to be updated as per his solution:

watch: {
    less: {
        files: '**/*.less',
        tasks: ['less', 'notify:less']
    }
},

Where notify:less references the less task within the notifiy object.

DavidT
  • 2,341
  • 22
  • 30
  • Thanks! I swear I tried this yesterday, but it didnt work. Works now though, so thanks! - Will accept this as the accepted answer in 5 minutes (once allowed). – sixtyfootersdude Sep 25 '14 at 15:26
8

It should be noted that specifying the notification task...

notify: {
    less:{
        options:{
            title: "CSS Files built"
            message: "Less task complete"
        }
    }
}

... is just a part of the deal.

It also should be registered in a task that you want it to be triggered for.

So for original OP's code to work

    watch: {
        less: {
            files: '**/*.less',
            tasks: ['less', 'notify_hooks']
        }
    },

should be changed to

    watch: {
        less: {
            files: '**/*.less',
            tasks: ['less', 'notify:less']
        }
    },

This references the notify:less mentioned earlier.

uKolka
  • 36,422
  • 4
  • 33
  • 44
  • This answer has the true solution to where most people may falter in configuring things right. – Ikon Nov 14 '14 at 15:34