在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):mikaelbr/gulp-notify开源软件地址(OpenSource Url):https://github.com/mikaelbr/gulp-notify开源编程语言(OpenSource Language):JavaScript 100.0%开源软件介绍(OpenSource Introduction):gulp-notify
Information
Table of ContentsRequirements
See node-notifier for details. Windows 10 Note: You might have to activate banner notification for the toast to show. From #90 (comment)
UsageFirst, install npm install --save-dev gulp-notify Then, add it to your 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
If you want to notify on errors 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!"))
})); APInotify(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: 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 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:
See also the advanced example. options.onLastType: If the notification should only happen on the last file of the stream. Per default a notification is triggered on each file. options.emitErrorType: If the returned stream should emit an error or not.
If This means you can run the notifier on a CI system without opting it out but simply letting it fail gracefully. options.messageType: The message you wish to attach to file. The string can be a lodash template as it is passed through gulp-util.template. Example: as functionType: See options.titleType: The title of the notification. The string can be a lodash template as it is passed through gulp-util.template. Example: as functionType: See options.templateOptionsType: Object passed to the Examples: gulp.src("../test/fixtures/*")
.pipe(notify({
message: "Generated file: <%= file.relative %> @ <%= options.date %>",
templateOptions: {
date: new Date()
}
})) options.notifierType: 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.on(event, function (notificationOptions)) - EventsIf the 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: Wraps 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 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
notify.logLevel(level)Type: 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.
If logging is set to ➜ 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 |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论