Skip to content

Commit

Permalink
feat($scripts): Add color highlighting for Elm compiler errors
Browse files Browse the repository at this point in the history
  • Loading branch information
halfzebra committed Sep 24, 2017
1 parent 49af44c commit f63aeeb
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions scripts/utils/formatElmCompilerErrors.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
'use strict';

var chalk = require('chalk');
var ctx = new chalk.constructor({ enabled: true });
var error = ctx.bold.red;
var filename = ctx.cyan;
var isBrowser = typeof window === 'object';

if (isBrowser) {
ctx.level = 1;
error = ctx.cyan;
filename = ctx.green;
}

function stripRedundantInfo(error) {
return error.replace(
Expand All @@ -17,9 +27,9 @@ module.exports = function formatElmCompilerErrors(messages) {
errors: errors
.map(x =>
x
.replace(/(--\s[A-Z\s]+-+\s.*\.elm\n)/g, chalk.cyan('$1'))
.replace(/(\n\s*)(\^+)/g, '$1' + chalk.red('$2'))
.replace(/(\d+\|)(>)/g, '$1' + chalk.bold(chalk.red('$2')))
.replace(/(--\s[A-Z\s]+-+\s.*\.elm\n)/g, filename('$1'))
.replace(/(\n\s*)(\^+)/g, '$1' + error('$2'))
.replace(/(\d+)(\|>)/g, '$1' + error('$2'))
)
.map(stripRedundantInfo),
warnings: warnings
Expand Down

0 comments on commit f63aeeb

Please sign in to comment.