UNPKG

647 BJavaScriptView Raw
1var path = require('path');
2var notifier = null;
3try {
4 notifier = require('node-notifier');
5} catch (error) {
6 notifier = null;
7}
8
9function icon(level) {
10 return path.resolve(__dirname, '../icons/node_' + level + '.png');
11}
12
13/**
14 * Displays a desktop notification and writes a message to the console.
15 */
16module.exports = function (cfg, log) {
17 return function (title, msg, level) {
18 level = level || 'info';
19 log([title, msg].filter(_ => _).join(': '), level);
20 if (notifier !== null && cfg.notify) {
21 notifier.notify({
22 title: title || 'node.js',
23 icon: icon(level),
24 message: msg
25 });
26 }
27 };
28};