mikaelbr / gulp-notify

gulp plugin to send messages based on Vinyl Files or Errors to Mac OS X, Linux or Windows using the node-notifier module. Fallbacks to Growl or simply logging
MIT License
591 stars 40 forks source link

Change defaults for reporter #109

Open jorenmartijn opened 8 years ago

jorenmartijn commented 8 years ago

Hi,

I'd like to be able to set my notification icon globally so I don't have to pass it through the .pipe(notify()) command in my gulp file. Is there anyway I can do that? I found the defaults object in the reporter.js file, but can't figure out how to manipulate that from the gulp file.

Regards, Joren

mikaelbr commented 8 years ago

Hi, @jorenmartijn! I think maybe extracting the usage to your own function which returns the notify object with default options is the "best practise" way to solve this.

jorenmartijn commented 8 years ago

Thanks for the quick response! Using your suggestion I wrote the following, which seems to work perfectly :)

function notice(options){
    var params = options;
    params['icon'] = path.join(__dirname, "favicon.png");
    return notify(params);
}

Regards, Joren

mikaelbr commented 8 years ago

Good! Note, though, this mutates the object that you passed in. This means that if you send in the same object across several functions, they have the same changes. You can use something like lodash.assign, some extend implementation or just Object.assign if you are running Node 6 to avoid mutation. For instance:

function notice(options){
    return notify(Object.assign({}, options, {
        icon: path.join(__dirname, "favicon.png")
    });
}