Updating NPM dependencies
This commit is contained in:
135
node_modules/node-notifier/lib/utils.js
generated
vendored
135
node_modules/node-notifier/lib/utils.js
generated
vendored
@@ -6,6 +6,9 @@ var path = require('path');
|
||||
var url = require('url');
|
||||
var os = require('os');
|
||||
var fs = require('fs');
|
||||
var net = require('net');
|
||||
|
||||
const BUFFER_SIZE = 1024;
|
||||
|
||||
function clone(obj) {
|
||||
return JSON.parse(JSON.stringify(obj));
|
||||
@@ -13,7 +16,7 @@ function clone(obj) {
|
||||
|
||||
module.exports.clone = clone;
|
||||
|
||||
var escapeQuotes = function(str) {
|
||||
var escapeQuotes = function (str) {
|
||||
if (typeof str === 'string') {
|
||||
return str.replace(/(["$`\\])/g, '\\$1');
|
||||
} else {
|
||||
@@ -21,7 +24,7 @@ var escapeQuotes = function(str) {
|
||||
}
|
||||
};
|
||||
|
||||
var inArray = function(arr, val) {
|
||||
var inArray = function (arr, val) {
|
||||
return arr.indexOf(val) !== -1;
|
||||
};
|
||||
|
||||
@@ -40,10 +43,12 @@ var notifySendFlags = {
|
||||
category: 'category',
|
||||
subtitle: 'category',
|
||||
h: 'hint',
|
||||
hint: 'hint'
|
||||
hint: 'hint',
|
||||
a: 'app-name',
|
||||
'app-name': 'app-name'
|
||||
};
|
||||
|
||||
module.exports.command = function(notifier, options, cb) {
|
||||
module.exports.command = function (notifier, options, cb) {
|
||||
notifier = shellwords.escape(notifier);
|
||||
if (process.env.DEBUG && process.env.DEBUG.indexOf('notifier') !== -1) {
|
||||
console.info('node-notifier debug info (command):');
|
||||
@@ -51,7 +56,7 @@ module.exports.command = function(notifier, options, cb) {
|
||||
console.info('[notifier options]', options.join(' '));
|
||||
}
|
||||
|
||||
return cp.exec(notifier + ' ' + options.join(' '), function(
|
||||
return cp.exec(notifier + ' ' + options.join(' '), function (
|
||||
error,
|
||||
stdout,
|
||||
stderr
|
||||
@@ -61,45 +66,45 @@ module.exports.command = function(notifier, options, cb) {
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.fileCommand = function(notifier, options, cb) {
|
||||
module.exports.fileCommand = function (notifier, options, cb) {
|
||||
if (process.env.DEBUG && process.env.DEBUG.indexOf('notifier') !== -1) {
|
||||
console.info('node-notifier debug info (fileCommand):');
|
||||
console.info('[notifier path]', notifier);
|
||||
console.info('[notifier options]', options.join(' '));
|
||||
}
|
||||
|
||||
return cp.execFile(notifier, options, function(error, stdout, stderr) {
|
||||
return cp.execFile(notifier, options, function (error, stdout, stderr) {
|
||||
if (error) return cb(error, stdout);
|
||||
cb(stderr, stdout);
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.fileCommandJson = function(notifier, options, cb) {
|
||||
module.exports.fileCommandJson = function (notifier, options, cb) {
|
||||
if (process.env.DEBUG && process.env.DEBUG.indexOf('notifier') !== -1) {
|
||||
console.info('node-notifier debug info (fileCommandJson):');
|
||||
console.info('[notifier path]', notifier);
|
||||
console.info('[notifier options]', options.join(' '));
|
||||
}
|
||||
return cp.execFile(notifier, options, function(error, stdout, stderr) {
|
||||
return cp.execFile(notifier, options, function (error, stdout, stderr) {
|
||||
if (error) return cb(error, stdout);
|
||||
if (!stdout) return cb(error, {});
|
||||
|
||||
try {
|
||||
var data = JSON.parse(stdout);
|
||||
cb(stderr, data);
|
||||
cb(!stderr ? null : stderr, data);
|
||||
} catch (e) {
|
||||
cb(e, stdout);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.immediateFileCommand = function(notifier, options, cb) {
|
||||
module.exports.immediateFileCommand = function (notifier, options, cb) {
|
||||
if (process.env.DEBUG && process.env.DEBUG.indexOf('notifier') !== -1) {
|
||||
console.info('node-notifier debug info (notifier):');
|
||||
console.info('[notifier path]', notifier);
|
||||
}
|
||||
|
||||
notifierExists(notifier, function(_, exists) {
|
||||
notifierExists(notifier, function (_, exists) {
|
||||
if (!exists) {
|
||||
return cb(new Error('Notifier (' + notifier + ') not found on system.'));
|
||||
}
|
||||
@@ -109,7 +114,7 @@ module.exports.immediateFileCommand = function(notifier, options, cb) {
|
||||
};
|
||||
|
||||
function notifierExists(notifier, cb) {
|
||||
return fs.stat(notifier, function(err, stat) {
|
||||
return fs.stat(notifier, function (err, stat) {
|
||||
if (!err) return cb(err, stat.isFile());
|
||||
|
||||
// Check if Windows alias
|
||||
@@ -119,14 +124,14 @@ function notifierExists(notifier, cb) {
|
||||
}
|
||||
|
||||
// Check if there is an exe file in the directory
|
||||
return fs.stat(notifier + '.exe', function(err, stat) {
|
||||
return fs.stat(notifier + '.exe', function (err, stat) {
|
||||
if (err) return cb(err, false);
|
||||
cb(err, stat.isFile());
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
var mapAppIcon = function(options) {
|
||||
var mapAppIcon = function (options) {
|
||||
if (options.appIcon) {
|
||||
options.icon = options.appIcon;
|
||||
delete options.appIcon;
|
||||
@@ -135,7 +140,7 @@ var mapAppIcon = function(options) {
|
||||
return options;
|
||||
};
|
||||
|
||||
var mapText = function(options) {
|
||||
var mapText = function (options) {
|
||||
if (options.text) {
|
||||
options.message = options.text;
|
||||
delete options.text;
|
||||
@@ -144,7 +149,7 @@ var mapText = function(options) {
|
||||
return options;
|
||||
};
|
||||
|
||||
var mapIconShorthand = function(options) {
|
||||
var mapIconShorthand = function (options) {
|
||||
if (options.i) {
|
||||
options.icon = options.i;
|
||||
delete options.i;
|
||||
@@ -153,10 +158,16 @@ var mapIconShorthand = function(options) {
|
||||
return options;
|
||||
};
|
||||
|
||||
module.exports.mapToNotifySend = function(options) {
|
||||
module.exports.mapToNotifySend = function (options) {
|
||||
options = mapAppIcon(options);
|
||||
options = mapText(options);
|
||||
|
||||
if (options.timeout === false) {
|
||||
delete options.timeout;
|
||||
}
|
||||
if (options.wait === true) {
|
||||
options['expire-time'] = 5; // 5 seconds default time (multipled below)
|
||||
}
|
||||
for (var key in options) {
|
||||
if (key === 'message' || key === 'title') continue;
|
||||
if (options.hasOwnProperty(key) && notifySendFlags[key] !== key) {
|
||||
@@ -164,11 +175,16 @@ module.exports.mapToNotifySend = function(options) {
|
||||
delete options[key];
|
||||
}
|
||||
}
|
||||
if (typeof options['expire-time'] === 'undefined') {
|
||||
options['expire-time'] = 10 * 1000; // 10 sec timeout by default
|
||||
} else if (typeof options['expire-time'] === 'number') {
|
||||
options['expire-time'] = options['expire-time'] * 1000; // notify send uses milliseconds
|
||||
}
|
||||
|
||||
return options;
|
||||
};
|
||||
|
||||
module.exports.mapToGrowl = function(options) {
|
||||
module.exports.mapToGrowl = function (options) {
|
||||
options = mapAppIcon(options);
|
||||
options = mapIconShorthand(options);
|
||||
options = mapText(options);
|
||||
@@ -182,7 +198,7 @@ module.exports.mapToGrowl = function(options) {
|
||||
return options;
|
||||
};
|
||||
|
||||
module.exports.mapToMac = function(options) {
|
||||
module.exports.mapToMac = function (options) {
|
||||
options = mapIconShorthand(options);
|
||||
options = mapText(options);
|
||||
|
||||
@@ -210,6 +226,14 @@ module.exports.mapToMac = function(options) {
|
||||
delete options.wait;
|
||||
}
|
||||
|
||||
if (!options.wait && !options.timeout) {
|
||||
if (options.timeout === false) {
|
||||
delete options.timeout;
|
||||
} else {
|
||||
options.timeout = 10;
|
||||
}
|
||||
}
|
||||
|
||||
options.json = true;
|
||||
return options;
|
||||
};
|
||||
@@ -217,9 +241,10 @@ module.exports.mapToMac = function(options) {
|
||||
function isArray(arr) {
|
||||
return Object.prototype.toString.call(arr) === '[object Array]';
|
||||
}
|
||||
module.exports.isArray = isArray;
|
||||
|
||||
function noop() {}
|
||||
module.exports.actionJackerDecorator = function(emitter, options, fn, mapper) {
|
||||
module.exports.actionJackerDecorator = function (emitter, options, fn, mapper) {
|
||||
options = clone(options);
|
||||
fn = fn || noop;
|
||||
|
||||
@@ -230,7 +255,7 @@ module.exports.actionJackerDecorator = function(emitter, options, fn, mapper) {
|
||||
);
|
||||
}
|
||||
|
||||
return function(err, data) {
|
||||
return function (err, data) {
|
||||
var resultantData = data;
|
||||
var metadata = {};
|
||||
// Allow for extra data if resultantData is an object
|
||||
@@ -245,6 +270,9 @@ module.exports.actionJackerDecorator = function(emitter, options, fn, mapper) {
|
||||
if (resultantData.match(/^activate|clicked$/)) {
|
||||
resultantData = 'activate';
|
||||
}
|
||||
if (resultantData.match(/^timedout$/)) {
|
||||
resultantData = 'timeout';
|
||||
}
|
||||
}
|
||||
|
||||
fn.apply(emitter, [err, resultantData, metadata]);
|
||||
@@ -256,7 +284,7 @@ module.exports.actionJackerDecorator = function(emitter, options, fn, mapper) {
|
||||
};
|
||||
};
|
||||
|
||||
module.exports.constructArgumentList = function(options, extra) {
|
||||
module.exports.constructArgumentList = function (options, extra) {
|
||||
var args = [];
|
||||
extra = extra || {};
|
||||
|
||||
@@ -264,13 +292,13 @@ module.exports.constructArgumentList = function(options, extra) {
|
||||
var initial = extra.initial || [];
|
||||
var keyExtra = extra.keyExtra || '';
|
||||
var allowedArguments = extra.allowedArguments || [];
|
||||
var noEscape = extra.noEscape !== void 0;
|
||||
var checkForAllowed = extra.allowedArguments !== void 0;
|
||||
var noEscape = extra.noEscape !== undefined;
|
||||
var checkForAllowed = extra.allowedArguments !== undefined;
|
||||
var explicitTrue = !!extra.explicitTrue;
|
||||
var keepNewlines = !!extra.keepNewlines;
|
||||
var wrapper = extra.wrapper === void 0 ? '"' : extra.wrapper;
|
||||
var wrapper = extra.wrapper === undefined ? '"' : extra.wrapper;
|
||||
|
||||
var escapeFn = function(arg) {
|
||||
var escapeFn = function (arg) {
|
||||
if (isArray(arg)) {
|
||||
return removeNewLines(arg.join(','));
|
||||
}
|
||||
@@ -284,7 +312,7 @@ module.exports.constructArgumentList = function(options, extra) {
|
||||
return wrapper + arg + wrapper;
|
||||
};
|
||||
|
||||
initial.forEach(function(val) {
|
||||
initial.forEach(function (val) {
|
||||
args.push(escapeFn(val));
|
||||
});
|
||||
for (var key in options) {
|
||||
@@ -310,29 +338,36 @@ function removeNewLines(str) {
|
||||
---- Options ----
|
||||
[-t] <title string> | Displayed on the first line of the toast.
|
||||
[-m] <message string> | Displayed on the remaining lines, wrapped.
|
||||
[-b] <button1;button2 string>| Displayed on the bottom line, can list multiple buttons separated by ";"
|
||||
[-tb] | Displayed a textbox on the bottom line, only if buttons are not presented.
|
||||
[-p] <image URI> | Display toast with an image, local files only.
|
||||
[-w] | Wait for toast to expire or activate.
|
||||
[-id] <id> | sets the id for a notification to be able to close it later.
|
||||
[-s] <sound URI> | Sets the sound of the notifications, for possible values see http://msdn.microsoft.com/en-us/library/windows/apps/hh761492.aspx.
|
||||
[-silent] | Don't play a sound file when showing the notifications.
|
||||
[-appID] <App.ID> | Don't create a shortcut but use the provided app id.
|
||||
-close <id> | Closes a currently displayed notification, in order to be able to close a notification the parameter -w must be used to create the notification.
|
||||
[-pid] <pid> | Query the appid for the process <pid>, use -appID as fallback. (Only relevant for applications that might be packaged for the store)
|
||||
[-pipeName] <\.\pipe\pipeName\> | Provide a name pipe which is used for callbacks.
|
||||
[-application] <C:\foo.exe> | Provide a application that might be started if the pipe does not exist.
|
||||
-close <id> | Closes a currently displayed notification.
|
||||
*/
|
||||
var allowedToasterFlags = [
|
||||
't',
|
||||
'm',
|
||||
'b',
|
||||
'tb',
|
||||
'p',
|
||||
'w',
|
||||
'id',
|
||||
's',
|
||||
'silent',
|
||||
'appID',
|
||||
'pid',
|
||||
'pipeName',
|
||||
'close',
|
||||
'install'
|
||||
];
|
||||
var toasterSoundPrefix = 'Notification.';
|
||||
var toasterDefaultSound = 'Notification.Default';
|
||||
module.exports.mapToWin8 = function(options) {
|
||||
module.exports.mapToWin8 = function (options) {
|
||||
options = mapAppIcon(options);
|
||||
options = mapText(options);
|
||||
|
||||
@@ -397,9 +432,9 @@ module.exports.mapToWin8 = function(options) {
|
||||
options.s = toasterDefaultSound;
|
||||
}
|
||||
|
||||
if (options.wait) {
|
||||
options.w = options.wait;
|
||||
delete options.wait;
|
||||
if (options.actions && isArray(options.actions)) {
|
||||
options.b = options.actions.join(';');
|
||||
delete options.actions;
|
||||
}
|
||||
|
||||
for (var key in options) {
|
||||
@@ -415,7 +450,7 @@ module.exports.mapToWin8 = function(options) {
|
||||
return options;
|
||||
};
|
||||
|
||||
module.exports.mapToNotifu = function(options) {
|
||||
module.exports.mapToNotifu = function (options) {
|
||||
options = mapAppIcon(options);
|
||||
options = mapText(options);
|
||||
|
||||
@@ -468,29 +503,29 @@ module.exports.mapToNotifu = function(options) {
|
||||
return options;
|
||||
};
|
||||
|
||||
module.exports.isMac = function() {
|
||||
module.exports.isMac = function () {
|
||||
return os.type() === 'Darwin';
|
||||
};
|
||||
|
||||
module.exports.isMountainLion = function() {
|
||||
module.exports.isMountainLion = function () {
|
||||
return (
|
||||
os.type() === 'Darwin' &&
|
||||
semver.satisfies(garanteeSemverFormat(os.release()), '>=12.0.0')
|
||||
);
|
||||
};
|
||||
|
||||
module.exports.isWin8 = function() {
|
||||
module.exports.isWin8 = function () {
|
||||
return (
|
||||
os.type() === 'Windows_NT' &&
|
||||
semver.satisfies(garanteeSemverFormat(os.release()), '>=6.2.9200')
|
||||
);
|
||||
};
|
||||
|
||||
module.exports.isWSL = function() {
|
||||
module.exports.isWSL = function () {
|
||||
return isWSL;
|
||||
};
|
||||
|
||||
module.exports.isLessThanWin8 = function() {
|
||||
module.exports.isLessThanWin8 = function () {
|
||||
return (
|
||||
os.type() === 'Windows_NT' &&
|
||||
semver.satisfies(garanteeSemverFormat(os.release()), '<6.2.9200')
|
||||
@@ -513,3 +548,21 @@ function sanitizeNotifuTypeArgument(type) {
|
||||
|
||||
return 'info';
|
||||
}
|
||||
|
||||
module.exports.createNamedPipe = (server) => {
|
||||
const buf = Buffer.alloc(BUFFER_SIZE);
|
||||
|
||||
return new Promise((resolve) => {
|
||||
server.instance = net.createServer((stream) => {
|
||||
stream.on('data', (c) => {
|
||||
buf.write(c.toString());
|
||||
});
|
||||
stream.on('end', () => {
|
||||
server.instance.close();
|
||||
});
|
||||
});
|
||||
server.instance.listen(server.namedPipe, () => {
|
||||
resolve(buf);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user