• Stars
    star
    592
  • Rank 75,570 (Top 2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 11 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

gulp-notify NPM version Build Status Dependency Status

notification plugin for gulp

Information

Package gulp-notify
Description Send messages to Mac Notification Center, Linux notifications (using notify-send) or Windows >= 8 (using native toaster) or Growl as fallback, using the node-notifier module. Can also specify custom notifier.
Node Version >= 0.8

Table of Contents

Requirements

  • Mac OS X: No external installation needed (if Mac OS X 10.8 or higher).
  • Linux: notify-send/notify-osd should be installed (On Ubuntu this is installed per default)
  • Windows: Uses native toaster (if Windows 8 or higher).
  • Fallback: Growl: Growl (for Mac, Windows or similar) should be installed.

See node-notifier for details.

Windows 10 Note: You might have to activate banner notification for the toast to show.

From #90 (comment)

You can make it work by going to System > Notifications & Actions. The 'toast' app needs to have Banners enabled. (You can activate banners by clicking on the 'toast' app and setting the 'Show notification banners' to On)

Usage

First, install gulp-notify as a development dependency:

npm install --save-dev gulp-notify

Then, add it to your gulpfile.js:

var notify = require("gulp-notify");
gulp.src("./src/test.ext")
  .pipe(notify("Hello Gulp!"));

Or with template

var notify = require("gulp-notify");
gulp.src("./src/test.ext")
  .pipe(notify("Found file: <%= file.relative %>!"));

See examples for more or the API section for various inputs.

Notes/tip

gulp-notify passes on the vinyl files even on error. So if you are using gulp-plumber the run will not break if the notifier returns an error.

If you want to notify on errors gulp-plumber can be used to not break the run and force you to have to restart gulp.

You can use notify.onError() as the errorHandler for gulp-plumber like this:

gulp.src("../test/fixtures/*")
      .pipe(plumber({errorHandler: notify.onError("Error: <%= error.message %>")}))
      .pipe(through(function () {
        this.emit("error", new Error("Something happend: Error message!"))
      }));

API

notify(String)

A message to notify per data on stream. The string can be a lodash template as it is passed through gulp-util.template.

notify(Function)

Type: function(VinylFile)

Vinyl File from gulp stream passed in as argument.

The result of the function can be a string used as the message or an options object (see below). If the returned value is a string, it can be a lodash template as it is passed through gulp-util.template.

If false is returned from the function the notification won't run.

notify(options)

*Options are passed onto the reporter, so on Windows, you can define Growl host, on Mac you can pass in contentImage, and so on.

See node-notifier for all options*

Default notification values:

  • Gulp logo on regular notification
  • Inverted Gulp logo on error
  • Frog sound on error on Mac.

See also the advanced example.

options.onLast

Type: Boolean Default: false

If the notification should only happen on the last file of the stream. Per default a notification is triggered on each file.

options.emitError

Type: Boolean Default: false

If the returned stream should emit an error or not. If emitError is true, you have to handle .on('error') manually in case the notifier (gulp-notify) fails. If the default false is set, the error will not be emitted but simply printed to the console.

This means you can run the notifier on a CI system without opting it out but simply letting it fail gracefully.

options.message

Type: String Default: File path in stream

The message you wish to attach to file. The string can be a lodash template as it is passed through gulp-util.template.

Example: Created <%= file.relative %>.

as function

Type: Function(vinylFile)

See notify(Function).

options.title

Type: String Default: "Gulp Notification"

The title of the notification. The string can be a lodash template as it is passed through gulp-util.template.

Example: Created <%= file.relative %>.

as function

Type: Function(vinylFile)

See notify(Function).

options.templateOptions

Type: Object Default: {}

Object passed to the lodash template, for additional properties passed to the template.

Examples:

gulp.src("../test/fixtures/*")
    .pipe(notify({
      message: "Generated file: <%= file.relative %> @ <%= options.date %>",
      templateOptions: {
        date: new Date()
      }
    }))

options.notifier

Type: Function(options, callback) Default: node-notifier module

Swap out the notifier by passing in an function. The function expects two arguments: options and callback.

The callback must be called when the notification is finished. Options will contain both title and message.

See notify.withReporter for syntactic sugar.

notify.on(event, function (notificationOptions)) - Events

If the wait option is set to true, the notifier will trigger events click or timeout, whether the user clicks the notification or it times out. You listen to these events on the main notify object, not the produces stream.

var notify = require('gulp-notify');

notify.on('click', function (options) {
  console.log('I clicked something!', options);
});

notify.on('timeout', function (options) {
  console.log('The notification timed out', options);
});

gulp.task("click", function () {
  return gulp.src("some/glob/**")
    .pipe(notify({ message: 'Click or wait', wait: true }));
});

notify.withReporter(Function)

Type: Reporter

Wraps options.notifier to return a new notify-function only using the passed in reporter.

Example:

var custom = notify.withReporter(function (options, callback) {
  console.log("Title:", options.title);
  console.log("Message:", options.message);
  callback();
});

gulp.src("../test/fixtures/1.txt")
    .pipe(custom("This is a message."));

This will be the same as

gulp.src("../test/fixtures/1.txt")
    .pipe(notify({
      message: "This is a message."
      notifier: function (options, callback) {
        console.log("Title:", options.title);
        console.log("Message:", options.message);
        callback();
      }
    }));

But much, much prettier.

notify.onError()

The exact same API as using notify(), but where a vinyl File is passed, the error object is passed instead.

Example:

gulp.src("../test/fixtures/*")
      .pipe(through(function () {
        this.emit("error", new Error("Something happend: Error message!"))
      }))
      .on("error", notify.onError(function (error) {
        return "Message to the notifier: " + error.message;
      }));

Or simply:

gulp.src("../test/fixtures/*")
      .pipe(through(function () {
        this.emit("error", new Error("Something happend: Error message!"))
      }))
      .on("error", notify.onError("Error: <%= error.message %>"));
gulp.src("../test/fixtures/*")
      .pipe(through(function () {
        this.emit("error", new Error("Something happend: Error message!"))
      }))
      .on("error", notify.onError({
        message: "Error: <%= error.message %>",
        title: "Error running something"
      }));

The onError() end point does support lodash.template.

onError() will automatically end the stream for you. Making it easer for watching.

notify.logLevel(level)

Type: Integer Default: 2

Set if logger should be used or not. If log level is set to 0, no logging will be used. If no new log level is passed, the current log level is returned.

  • 0: No logging
  • 1: Log on error
  • 2: Log both on error and regular notification.

If logging is set to > 0, the title and message passed to gulp-notify will be logged like so:

➜  gulp-notify git:(master) ✗ gulp --gulpfile examples/gulpfile.js one
[gulp] Using file /Users/example/gulp-notify/examples/gulpfile.js
[gulp] Working directory changed to /Users/example/repos/gulp-notify/examples
[gulp] Running 'one'...
[gulp] Finished 'one' in 4.08 ms
[gulp] gulp-notify: [Gulp notification] /Users/example/gulp-notify/test/fixtures/1.txt

Disable gulp-notify

If you are running on a system that handles notifications poorly or you simply do not wish to use gulp-notify but your project does? You can disable gulp-notify by using enviroment variable DISABLE_NOTIFIER.

export DISABLE_NOTIFIER=true;

This will disable all methods; notify(), notify.onError and notify.withReporter.

Examples

To see all examples run from root:

$ gulp --gulpfile examples/gulpfile.js --tasks
[gulp] Using file /Users/example/gulp-notify/examples/gulpfile.js
[gulp] Working directory changed to /Users/example/gulp-notify/examples
[gulp] Tasks for /Users/example/gulp-notify/examples/gulpfile.js
[gulp] ├── multiple
[gulp] ├── one
[gulp] ├── message
[gulp] ├── customReporter
[gulp] ├── template
[gulp] ├── templateadv
[gulp] ├── function
[gulp] ├── onlast
[gulp] ├── advanceMac
[gulp] ├── error
[gulp] ├── forceGrowl
[gulp] └── customError

To run an example:

$ gulp --gulpfile examples/gulpfile.js multiple
[gulp] Using file /Users/example/gulp-notify/examples/gulpfile.js
[gulp] Working directory changed to /Users/example/gulp-notify/examples
[gulp] Running 'multiple'...
[gulp] Finished 'multiple' in 3.75 ms

As jshint reporter

gulp-notify can easily be used as jshint reporter. As jshint exposes the result on the vinyl file we can use them in a function like so:

gulp.task('lint', function() {
  gulp.src('/src/**/*.js')
    .pipe(jshint())
    // Use gulp-notify as jshint reporter
    .pipe(notify(function (file) {
      if (file.jshint.success) {
        // Don't show something if success
        return false;
      }

      var errors = file.jshint.results.map(function (data) {
        if (data.error) {
          return "(" + data.error.line + ':' + data.error.character + ') ' + data.error.reason;
        }
      }).join("\n");
      return file.relative + " (" + file.jshint.results.length + " errors)\n" + errors;
    }));
});

If you use a function for message in gulp-notify, the message won't be shown. This is true for both direct use of function and { message: function () {}}.

NPM downloads

License

MIT License

More Repositories

1

node-notifier

A Node.js module for sending notifications on native Mac, Windows and Linux (or Growl as fallback)
JavaScript
5,742
star
2

awesome-es2015-proxy

For learning how to use JavaScript Proxy, or just to see what is possible
JavaScript
609
star
3

marked-terminal

A Renderer for the marked project. Allowing you to render Markdown to print to your Terminal
JavaScript
423
star
4

mversion

A cross packaging module version bumper. CLI or API for bumping versions of package.json, bower.json, *.jquery.json etc.
JavaScript
199
star
5

node-notifier-cli

CLI API for node-notifier as separate package.
JavaScript
143
star
6

SocialFeed.js

Generate a social feed in javascript.
JavaScript
132
star
7

metatune

PHP Wrapper for the Spotify Metadata API and the Spotify Play Button
PHP
55
star
8

node-osascript

A stream for Apple Open Scripting Architecture (OSA) through AppleScript or Javascript
JavaScript
50
star
9

bacon-love

A Nodeschool type workshop for Functional Reactive Programming and Bacon.js
JavaScript
48
star
10

fp-react

Functional tools for React components
JavaScript
41
star
11

vscodemod

VSCode extension for doing codemod on selected text
JavaScript
30
star
12

did-i-do-that

A debug tool based on JavaScript Proxy to track surprising/unwanted mutation of objects.
JavaScript
26
star
13

gulp-gitmodified

A plugin for Gulp to get an object stream of modified files on git.
JavaScript
22
star
14

frp-piano

An example of Functional Reactive Programming, by implementing a simple collaborative piano.
CSS
19
star
15

babel-plugin-transform-react-require

Transform files using JSX to implicitly require React (or other implementations).
JavaScript
15
star
16

node-heartrate

A Bluethooth Low Energy heart rate stream
JavaScript
15
star
17

gulp-gitshasuffix

A plugin for Gulp to suffix files with latest commit sha.
JavaScript
11
star
18

chrome-github-packages

Enhance Package.json on Github by linking up modules to NPM
JavaScript
11
star
19

mrun

mrun - A npm module for setting npm run properties to build/watch less and browserify code
JavaScript
10
star
20

lastfm-spotify-urilist

A Node.js module for an easy way of getting a list of Spotify URIs based on Last.fm data.
JavaScript
10
star
21

markdowner

Markdowner is a cloud based application for writing and sharing Markdown documents.
JavaScript
9
star
22

cli-usage

Easily show the usage of your CLI tool from a Markdown string or file
JavaScript
9
star
23

AI-Poker-Player

NTNU Project for AI Programming
Python
8
star
24

metabrag

A jQuery plugin for showing off your GitHub and Coderwall stats.
JavaScript
7
star
25

kodesnutt

Kode brukt i episoder av Kodesnutt.io
JavaScript
5
star
26

simplify-playbutton

Automated service for generating Spotify Play Button for your Last.fm scrobbled tracks. Using Node.js and running on Heroku.
JavaScript
5
star
27

kakle

If Commit, Then Do. Kakle helps you remember when you should run commands after pulling external changes
JavaScript
5
star
28

clapper

Do actions on applause and listen on claps on browser usermedia
JavaScript
4
star
29

node-csstats

Parse AMX Mod X Stats File. A result of procrastinating during a Master's thesis and nostalgia.
JavaScript
4
star
30

SwarmWebots

Project 4 - Artificial Swarm Behavior
Python
4
star
31

traceur-cli

Wraps traceur cli to add REPL and string eval
JavaScript
4
star
32

record-access

Property accessors as functions similar to .property in elm-lang.
JavaScript
4
star
33

didt

Did I do that?
JavaScript
3
star
34

json-ast

OCaml JSON AST generator. Work in progress
OCaml
3
star
35

phpcoderwall

PHP library for fetching Coderwall data
PHP
3
star
36

presentations

A collection of presentations
JavaScript
3
star
37

bacon.decorate

Unify your API and abstract time using Functional Reactive Programming and Bacon.js
JavaScript
3
star
38

graphql-node-import

Import `.graphql` and `.gql` files directly in Node, accessing queries and fragments
TypeScript
3
star
39

rm-debugger

Simplest codemod you can think of, but is still handy: Remove all `debugger;` statements from your code.
JavaScript
2
star
40

nextjs-css-relative-assets-bug-repro

JavaScript
2
star
41

diy-nextjs-server-actions

Example code from presentation "DIY Nextjs Server Actions"
TypeScript
2
star
42

standalone-unrar

A standalone unrar library without any need for external dependencies.
JavaScript
2
star
43

AnnWebots

Project 3 - Webots with Generic Anns
Python
2
star
44

node-repo-github

A very simple node.js wrapper to get Github Repo Information.
JavaScript
2
star
45

twit-stream

Streaming Twitter data with proper Node.JS streams2 with a simple API
JavaScript
2
star
46

react-formdata

A library for generating an object of values from a set of inputs in React
JavaScript
2
star
47

twitscraper

A binary used for scraping the Twitter site for tweets and generate a .tsv file for output
JavaScript
2
star
48

mikaelbr

My special repository
2
star
49

release-actions-demo

JavaScript
1
star
50

bekk-open-source

Repo brukt for planlegging av faggruppearbeid ifm. Open Source
1
star
51

metaenter

A simple jQuery plugin for simulating a facebook-like text input.
JavaScript
1
star
52

dotfiles

My dotfiles used for importing to new systems and backup
Shell
1
star
53

Basic-Evolutionary-Programming

The code for a University project
Python
1
star
54

simplserv

A simple HTTP server using Python. For web development and testing AJAX calls.
Python
1
star
55

aoc22

Advent of Code solutions for 2022 in OCaml
OCaml
1
star
56

lsystem-reasonml

ReasonML experimentation implementing Lindenmayer system
OCaml
1
star
57

stringywingy

Check if a sentence or a word is an anagram or a palindrome.
JavaScript
1
star
58

tweetsa

Python
1
star
59

webkom-kurs2015

Kurs for Webkom Kickoff 2015.
JavaScript
1
star
60

tdcinfographic-raspberry

Server component to the tdcinfographic application. Connecting to the tdcinfographic Node.js app through WebSockets.
Python
1
star
61

podcast-player

CLI tool for listening to podcasts.
JavaScript
1
star
62

kodesnutt.io

Kodesnutt.io homepage
HTML
1
star
63

asyncjs.kodesnutt.io-source

Source for asyncjs.kodesnutt.io
CSS
1
star
64

async-kodesnutt

CSS
1
star
65

webkom-kurs2015-webpack

Kurs for Webkom Kickoff 2015 - WebPack versjon
JavaScript
1
star
66

gifme

gifme client for posting gifs to Slack
OCaml
1
star
67

ndc

My talk for NDC2014: Functional Reactive Programming and Bacon
JavaScript
1
star
68

simplify-zones

Simplify geometry of tariff zones from Entur
JavaScript
1
star
69

tweetannotator

A web tool for annotating sentiment on random tweets. Can be used to generate data sets for machine learning algorithms
JavaScript
1
star
70

CP-Sudoku

Constraint based sudoku solver
Java
1
star
71

immutable-memo

Memoization with immutable data structures for React.memo
JavaScript
1
star
72

textareaAutoHeight

Create a Facebook like input box in seconds. A text area will automaticly set height according to content, and submit on enter, but give new line at shift + enter.
JavaScript
1
star
73

auto-unrar

Automatic unpack all recursive rar-files from a directory
JavaScript
1
star
74

azure-ml-text-analysis

API Wrapper for doing text analysis on Azure Machine Learning Platform
JavaScript
1
star
75

cheerful.dev

Test site for Svelte, Sapper and Now.sh
Svelte
1
star
76

Coding-Dojo-Counter

A web application for selecting sparrers and keeping time in Coding Dojos. Integration with Facebook Events
JavaScript
1
star
77

bekk-trhfrontend-prosjektoppsett

Oppsett av nye frontendprosjekter med transpilering og LESS. Stegvis guide til hvordan det kan gjøres.
JavaScript
1
star