gulp-notify
Advanced tools
Comparing version 0.4.6 to 0.5.0
@@ -21,2 +21,14 @@ | ||
gulp.task("customReporter", function () { | ||
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.")); | ||
}); | ||
gulp.task("template", function () { | ||
@@ -23,0 +35,0 @@ gulp.src("../test/fixtures/1.txt") |
15
index.js
@@ -62,3 +62,18 @@ var through = require("through2"), | ||
module.exports.withReporter = function (reporter) { | ||
if (!reporter) throw new gutil.PluginError("gulp-notify", "No custom reporter defined."); | ||
return function (options) { | ||
options = options || {}; | ||
if (typeof options !== "object") { | ||
options = { | ||
message: options | ||
}; | ||
} | ||
options.notifier = reporter; | ||
return plugin(options); | ||
}; | ||
}; | ||
function report (reporter, message, options, templateOptions, callback) { | ||
@@ -65,0 +80,0 @@ var self = this; |
{ | ||
"name": "gulp-notify", | ||
"version": "0.4.6", | ||
"version": "0.5.0", | ||
"description": "A plugin for Gulp to send messages to Mac Notification Center or Linux' notify-send", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -8,3 +8,3 @@ # gulp-notify [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][depstat-image]][depstat-url] | ||
| ------------- |--------------| | ||
| Description | Send messages to Mac Notification Center or Linux notifications (using `notify-send`) using the [node-notifier](https://github.com/mikaelbr/node-notifier) module. Can also specify custom notifier (e.g. Growl notification). | | ||
| Description | Send messages to Mac Notification Center or Linux notifications (using `notify-send`) using the [node-notifier](https://github.com/mikaelbr/node-notifier) module. Can also [specify custom notifier](#) (e.g. Growl notification). | | ||
| Node Version | >= 0.8 | | ||
@@ -136,3 +136,43 @@ | ||
*See `notify.withReporter` for syntactic sugar.* | ||
### notify.withReporter(Function) | ||
Type: `Reporter` | ||
Wraps `options.notifier` to return a new notify-function only using | ||
the passed in reporter. | ||
Example: | ||
```javascript | ||
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 | ||
```javascript | ||
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() | ||
@@ -189,2 +229,3 @@ | ||
[gulp] ├── one | ||
[gulp] ├── customReporter | ||
[gulp] ├── message | ||
@@ -205,3 +246,10 @@ [gulp] ├── function | ||
## Changelog | ||
# `v0.5.0` | ||
1. Added API end point `notify.withReporter(Reporter)` as syntactic suger for custom reporter | ||
2. Updated dependency for node-notfier - now checking if `notify-send` is installed on the Linux box | ||
## License | ||
@@ -208,0 +256,0 @@ |
@@ -34,13 +34,24 @@ /*global describe, it*/ | ||
it('should allow setting of own reporter', function(done) { | ||
var notifier = notify.withReporter(mockGenerator); | ||
var stream = notifier(); | ||
should.exist(stream); | ||
should.exist(stream.on); | ||
should.exist(stream.pipe); | ||
done(); | ||
}); | ||
it('should call notifier with title and message', function(done) { | ||
var mockedNotify = notify.withReporter(mockGenerator(function (opts) { | ||
should.exist(opts); | ||
should.exist(opts.title); | ||
should.exist(opts.message); | ||
String(opts.message).should.equal(testString); | ||
})); | ||
var testString = "this is a test", | ||
instream = gulp.src(join(__dirname, "./fixtures/*.txt")), | ||
outstream = notify({ | ||
message: testString, | ||
notifier: mockGenerator(function (opts) { | ||
should.exist(opts); | ||
should.exist(opts.title); | ||
should.exist(opts.message); | ||
String(opts.message).should.equal(testString); | ||
}) | ||
outstream = mockedNotify({ | ||
message: testString | ||
}); | ||
@@ -62,9 +73,11 @@ | ||
it('should emit error when sub-module returns error', function(done) { | ||
var mockedNotify = notify.withReporter(function (options, callback) { | ||
callback(new Error(testString)); | ||
}); | ||
var testString = "testString", | ||
instream = gulp.src(join(__dirname, "./fixtures/*.txt")), | ||
outstream = notify({ | ||
message: testString, | ||
notifier: function (options, callback) { | ||
callback(new Error(testString)); | ||
} | ||
outstream = mockedNotify({ | ||
message: testString | ||
}); | ||
@@ -83,2 +96,4 @@ | ||
it('should pass on files', function(done) { | ||
var mockedNotify = notify.withReporter(mockGenerator()); | ||
var | ||
@@ -88,5 +103,3 @@ testSuffix = "tester", | ||
instream = gulp.src(srcFile), | ||
outstream = notify({ | ||
notifier: mockGenerator() | ||
}); | ||
outstream = mockedNotify(); | ||
@@ -93,0 +106,0 @@ var numFilesBefore = 0, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
29690
618
263