forked from geowarin/friendly-errors-webpack-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoutput.js
More file actions
89 lines (74 loc) · 1.74 KB
/
output.js
File metadata and controls
89 lines (74 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
'use strict';
const colors = require('./utils/colors');
const chalk = require('chalk');
class Debugger {
constructor () {
this.enabled = true;
this.capturing = false;
this.capturedMessages = [];
}
enable () {
this.enabled = true;
}
capture () {
this.enabled = true;
this.capturing = true;
}
endCapture () {
this.enabled = false;
this.capturing = false;
this.capturedMessages = [];
}
log () {
if (this.enabled) {
this.captureConsole(Array.from(arguments), console.log);
}
}
info (message) {
if (this.enabled) {
const titleFormatted = colors.formatTitle('info', 'I');
this.log(titleFormatted, message);
}
}
note (message) {
if (this.enabled) {
const titleFormatted = colors.formatTitle('note', 'N');
this.log(titleFormatted, message);
}
}
title (severity, title, subtitle) {
if (this.enabled) {
const titleFormatted = colors.formatTitle(severity, title);
const subTitleFormatted = colors.formatText(severity, subtitle);
this.log(titleFormatted, subTitleFormatted);
this.log();
}
}
clearConsole () {
if (!this.capturing && this.enabled) {
process.stdout.write('\x1bc');
}
}
captureLogs (fun) {
try {
this.capture();
fun.call();
return this.capturedMessages;
} catch (e) {
throw e;
} finally {
this.endCapture();
}
}
captureConsole (args, method) {
if (this.capturing) {
this.capturedMessages.push(chalk.stripColor(args.join(' ').trim()));
} else {
method.apply(console, args);
}
}
}
function capitalizeFirstLetter (string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
module.exports = new Debugger();