extra_api.js
1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
var through = require("through2");
var gutil = require("gulp-util");
var notifier = require("node-notifier");
var report = require("./report");
"use strict";
// Default log level
var logLevel = 2;
// Default logger
var fnLog = gutil.log;
var logError = module.exports.logError = function (options, isError) {
if (!logLevel) return;
if (logLevel === 1 && !isError) return;
color = isError ? "red" : "green";
if (!gutil.colors[color]) return;
fnLog(gutil.colors.cyan('gulp-notify') + ':',
'[' + gutil.colors.blue(options.title) + ']',
gutil.colors[color].call(gutil.colors, options.message)
);
};
// Expose onError behaviour
module.exports.onError = function (options, callback) {
var reporter;
options = options || {};
var templateOptions = options.templateOptions || {};
var callback = callback || function (err) {
err && logError({
title: "Error running notifier",
message: "Could not send message: " + err.message
}, true);
};
if (options.notifier) {
reporter = options.notifier;
} else {
if (options.host || options.appName || options.port) {
notifier = new notifier.Notification({
host: options.host || 'localhost',
appName: options.appName || 'gulp-notify',
port: options.port || '23053'
});
}
reporter = notifier.notify.bind(notifier);
}
return function (error) {
var self = this;
report(reporter, error, options, templateOptions, function () {
callback.apply(self, arguments);
self.emit && self.emit('end');
});
};
};
// Expose to set log level
module.exports.logLevel = function (newLogLevel) {
if (newLogLevel === void 0) return logLevel;
logLevel = newLogLevel;
};
// Expose to set new logger
module.exports.logger = function (newLogger) {
if (!newLogger) return fnLog;
fnLog = newLogger;
};