Skip to content

Commit f63aeeb

Browse files
committed
feat($scripts): Add color highlighting for Elm compiler errors
1 parent 49af44c commit f63aeeb

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

scripts/utils/formatElmCompilerErrors.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
'use strict';
22

33
var chalk = require('chalk');
4+
var ctx = new chalk.constructor({ enabled: true });
5+
var error = ctx.bold.red;
6+
var filename = ctx.cyan;
7+
var isBrowser = typeof window === 'object';
8+
9+
if (isBrowser) {
10+
ctx.level = 1;
11+
error = ctx.cyan;
12+
filename = ctx.green;
13+
}
414

515
function stripRedundantInfo(error) {
616
return error.replace(
@@ -17,9 +27,9 @@ module.exports = function formatElmCompilerErrors(messages) {
1727
errors: errors
1828
.map(x =>
1929
x
20-
.replace(/(--\s[A-Z\s]+-+\s.*\.elm\n)/g, chalk.cyan('$1'))
21-
.replace(/(\n\s*)(\^+)/g, '$1' + chalk.red('$2'))
22-
.replace(/(\d+\|)(>)/g, '$1' + chalk.bold(chalk.red('$2')))
30+
.replace(/(--\s[A-Z\s]+-+\s.*\.elm\n)/g, filename('$1'))
31+
.replace(/(\n\s*)(\^+)/g, '$1' + error('$2'))
32+
.replace(/(\d+)(\|>)/g, '$1' + error('$2'))
2333
)
2434
.map(stripRedundantInfo),
2535
warnings: warnings

0 commit comments

Comments
 (0)