--
This commit is contained in:
parent
24f3d27984
commit
6b60015c02
9588 changed files with 1149251 additions and 49 deletions
63
node_modules/gulp-notify/lib/extra_api.js
generated
vendored
Normal file
63
node_modules/gulp-notify/lib/extra_api.js
generated
vendored
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
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 {
|
||||
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;
|
||||
};
|
||||
103
node_modules/gulp-notify/lib/notify.js
generated
vendored
Normal file
103
node_modules/gulp-notify/lib/notify.js
generated
vendored
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
"use strict";
|
||||
|
||||
var through = require('through2');
|
||||
var report = require('./report');
|
||||
var extra = require('./extra_api');
|
||||
var notifier = require('node-notifier');
|
||||
|
||||
module.exports = function (options) {
|
||||
var reporter;
|
||||
var lastFile = null;
|
||||
|
||||
options = options || {};
|
||||
var templateOptions = options.templateOptions || {};
|
||||
|
||||
if (options.notifier) {
|
||||
reporter = options.notifier;
|
||||
} else {
|
||||
if (options.host || options.appName || options.port) {
|
||||
notifier = new notifier.Notification({
|
||||
host: options.host,
|
||||
appName: options.appName,
|
||||
port: options.port
|
||||
});
|
||||
}
|
||||
reporter = notifier.notify.bind(notifier);
|
||||
}
|
||||
|
||||
function notify (file, enc, callback) {
|
||||
var stream = this;
|
||||
|
||||
report(reporter, file, options, templateOptions, function (err) {
|
||||
logError(err, stream);
|
||||
|
||||
if (options.emitError) {
|
||||
stream.push(file);
|
||||
return callback();
|
||||
}
|
||||
});
|
||||
|
||||
if (!options.emitError) {
|
||||
stream.push(file);
|
||||
return callback();
|
||||
}
|
||||
}
|
||||
|
||||
if (!options.onLast) {
|
||||
return through.obj(notify);
|
||||
}
|
||||
|
||||
// Only send notification on the last file.
|
||||
return through.obj(function (file, enc, callback) {
|
||||
lastFile = file;
|
||||
this.push(file);
|
||||
callback();
|
||||
}, function (callback) {
|
||||
var stream = this;
|
||||
|
||||
if (!lastFile) {
|
||||
return callback();
|
||||
}
|
||||
|
||||
report(reporter, lastFile, options, templateOptions, function (err) {
|
||||
logError(err, stream);
|
||||
if (options.emitError) {
|
||||
return callback();
|
||||
}
|
||||
});
|
||||
|
||||
lastFile = null; // reset
|
||||
if (!options.emitError) {
|
||||
return callback();
|
||||
}
|
||||
});
|
||||
|
||||
function logError (err, stream) {
|
||||
if (!err) return;
|
||||
|
||||
var isGrowl = notifier && notifier instanceof notifier.Growl;
|
||||
var isEcon = err.message.indexOf('ECONNREFUSED') !== -1;
|
||||
var dropMessage = isGrowl && isEcon;
|
||||
|
||||
if (dropMessage) {
|
||||
return extra.logError({
|
||||
title: 'Info',
|
||||
message: 'No notification system installed.'
|
||||
});
|
||||
}
|
||||
|
||||
if (options.emitError) return stream.emit('error', err);
|
||||
|
||||
extra.logError({
|
||||
title: 'Error in notifier',
|
||||
message: err
|
||||
}, true);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports.on = function (event, fn) {
|
||||
if (!notifier) return;
|
||||
return notifier.on(event, function (notifyObject, options) {
|
||||
return fn(options);
|
||||
});
|
||||
};
|
||||
131
node_modules/gulp-notify/lib/report.js
generated
vendored
Normal file
131
node_modules/gulp-notify/lib/report.js
generated
vendored
Normal file
|
|
@ -0,0 +1,131 @@
|
|||
var template = require("lodash.template");
|
||||
var gutil = require("gulp-util");
|
||||
var api = require("./extra_api");
|
||||
var extend = require("node.extend");
|
||||
var path = require("path");
|
||||
|
||||
"use strict";
|
||||
|
||||
var defaults = {
|
||||
error: {
|
||||
icon: path.join(__dirname, '..', 'assets', 'gulp-error.png'),
|
||||
sound: 'Frog'
|
||||
},
|
||||
regular: {
|
||||
icon: path.join(__dirname, '..', 'assets', 'gulp.png')
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
module.exports = function (reporter, message, options, templateOptions, callback) {
|
||||
var self = this;
|
||||
callback = callback || function () {};
|
||||
if (!reporter) return callback(new gutil.PluginError("gulp-notify", "No reporter specified."));
|
||||
|
||||
// Try/catch the only way to go to ensure catching all errors? Domains?
|
||||
try {
|
||||
var options = constructOptions(options, message, templateOptions);
|
||||
if (!options) {
|
||||
return callback();
|
||||
}
|
||||
api.logError(options, (message instanceof Error));
|
||||
reporter(options, function (err) {
|
||||
if (err) return callback(new gutil.PluginError("gulp-notify", err));
|
||||
return callback();
|
||||
});
|
||||
} catch (err) {
|
||||
return callback(new gutil.PluginError("gulp-notify", err));
|
||||
}
|
||||
};
|
||||
|
||||
function generate (outputData, object, title, message, subtitle, open, templateOptions) {
|
||||
if (object instanceof Error) {
|
||||
var titleTemplate = template(title);
|
||||
var messageTemplate = template(message);
|
||||
var openTemplate = template(open);
|
||||
var subtitleTemplate = template(subtitle);
|
||||
|
||||
return extend(defaults.error, outputData, {
|
||||
title: titleTemplate({
|
||||
error: object,
|
||||
options: templateOptions
|
||||
}),
|
||||
message: messageTemplate({
|
||||
error: object,
|
||||
options: templateOptions
|
||||
}),
|
||||
open: openTemplate({
|
||||
error: object,
|
||||
options: templateOptions
|
||||
}),
|
||||
subtitle: subtitleTemplate({
|
||||
error: object,
|
||||
options: templateOptions
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
return extend(defaults.regular, outputData, {
|
||||
title: gutil.template(title, {
|
||||
file: object,
|
||||
options: templateOptions
|
||||
}),
|
||||
message: gutil.template(message, {
|
||||
file: object,
|
||||
options: templateOptions
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
function constructOptions (options, object, templateOptions) {
|
||||
var message = object.path || object.message || object,
|
||||
title = !(object instanceof Error) ? "Gulp notification" : "Error running Gulp",
|
||||
open = "",
|
||||
subtitle = "",
|
||||
outputData = {};
|
||||
|
||||
if (typeof options === "function") {
|
||||
message = options(object);
|
||||
if (typeof message === "object") {
|
||||
options = message;
|
||||
}
|
||||
if (!message) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof options === "string") {
|
||||
message = options;
|
||||
}
|
||||
|
||||
if (typeof options === "object") {
|
||||
outputData = extend(true, {}, options);
|
||||
if (typeof outputData.title === "function") {
|
||||
title = outputData.title(object);
|
||||
} else {
|
||||
title = outputData.title || title;
|
||||
}
|
||||
|
||||
if (typeof outputData.subtitle === "function") {
|
||||
subtitle = outputData.subtitle(object);
|
||||
} else {
|
||||
subtitle = outputData.subtitle || subtitle;
|
||||
}
|
||||
|
||||
if (typeof outputData.open === "function") {
|
||||
open = outputData.open(object);
|
||||
} else {
|
||||
open = outputData.open || open;
|
||||
}
|
||||
|
||||
if (typeof outputData.message === "function") {
|
||||
message = outputData.message(object);
|
||||
if (!message) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
message = outputData.message || message;
|
||||
}
|
||||
}
|
||||
return generate(outputData, object, title, message, subtitle, open, templateOptions);
|
||||
}
|
||||
35
node_modules/gulp-notify/lib/withReporter.js
generated
vendored
Normal file
35
node_modules/gulp-notify/lib/withReporter.js
generated
vendored
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
var gutil = require("gulp-util");
|
||||
var api = require("./extra_api");
|
||||
var notify = require("./notify");
|
||||
|
||||
module.exports = function (reporter) {
|
||||
if (!reporter) throw new gutil.PluginError("gulp-notify", "No custom reporter defined.");
|
||||
|
||||
var inner = function (options) {
|
||||
options = setOptions(options, reporter);
|
||||
return notify(options);
|
||||
};
|
||||
|
||||
inner.onError = function (options) {
|
||||
options = setOptions(options, reporter);
|
||||
return api.onError(options);
|
||||
};
|
||||
|
||||
inner.logLevel = api.logLevel;
|
||||
inner.logger = api.logger;
|
||||
|
||||
return inner;
|
||||
};
|
||||
|
||||
function setOptions (options, reporter) {
|
||||
options = options || {};
|
||||
|
||||
if (typeof options !== "object") {
|
||||
options = {
|
||||
message: options
|
||||
};
|
||||
}
|
||||
|
||||
options.notifier = reporter;
|
||||
return options;
|
||||
}
|
||||
Loading…
Reference in a new issue