Skip to content

Commit

Permalink
#1: add more file info to Mac/Win error notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
brendanfalkowski committed Mar 16, 2019
1 parent 532a16f commit dbadd47
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions gulp/error-formatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var beeper = require('beeper');
var color = require('ansi-colors');
var minimist = require('minimist');
var notify = require('gulp-notify');
var path = require('path');
var PluginError = require('plugin-error');


Expand All @@ -48,53 +49,58 @@ module.exports = function (error) {
// [log] Uncomment to show the full error object
//console.log(error);

var report = ['\n'];
var notifyMessage = '';
var notifyTitle = '';

// ----------------------------------------------
// Normalize error responses

var report = ['\n'];
var notifyMessage = '';

if (error.plugin == 'gulp-eslint') {
notifyTitle = 'Lint JS';
notifyMessage = path.basename(error.fileName) + '\n' + error.lineNumber;

report.push(color.red('Plugin: ') + error.plugin + '\n');
report.push(color.red('File: ') + error.fileName + '\n');
report.push(color.red('Line: ') + error.lineNumber + '\n');
report.push(color.red('Note: ') + error.message + '\n');

notifyMessage = 'JS linter found errors.';
}

if (error.plugin === 'gulp-sass') {
notifyTitle = 'CSS';
notifyMessage = error.relativePath + '\n' + error.line + ' : ' + error.column;

report.push(color.red('Plugin: ') + error.plugin + '\n');
report.push(color.red('File: ') + error.relativePath + '\n');
report.push(color.red('Line: ') + error.line + '\n');
report.push(color.red('Column: ') + error.column + '\n');
report.push(color.red('Note: ') + error.messageOriginal + '\n');

notifyMessage = error.relativePath + '\n' + error.line + ' : ' + error.column;
}

if (error.plugin == 'gulp-stylelint') {
notifyMessage = 'CSS linter found errors.';
notifyTitle = 'Lint CSS';
notifyMessage = 'See the console.';
}

if (error.plugin === 'gulp-uglify') {
notifyTitle = 'JS';
notifyMessage = error.cause.filename + '\n' + error.cause.line + ' : ' + error.cause.col;

report.push(color.red('Plugin: ') + error.plugin + '\n');
report.push(color.red('Path: ') + error.fileName + '\n');
report.push(color.red('File: ') + error.cause.filename + '\n');
report.push(color.red('Line: ') + error.cause.line + '\n');
report.push(color.red('Column: ') + error.cause.col + '\n');
report.push(color.red('Note: ') + error.cause.message + '\n');

notifyMessage = error.cause.filename + '\n' + error.cause.line + ' : ' + error.cause.col;
}

// ----------------------------------------------
// Show Mac/Windows notification

notify({
title: 'Failed Gulp — See Console',
message: notifyMessage,
sound: 'Sosumi' // Sound for Mac. See: https://github.com/mikaelbr/node-notifier#all-notification-options-with-their-defaults
sound: 'Sosumi', // Sound for Mac. See: https://github.com/mikaelbr/node-notifier#all-notification-options-with-their-defaults
title: 'Gulp Error — ' + notifyTitle
}).write(error);

beeper(); // Fallback to system sound (for Windows).
Expand Down

0 comments on commit dbadd47

Please sign in to comment.