@@ -12,7 +12,68 @@ const pkg = require('../package.json');
12
12
const { Command } = require ( 'commander' ) ;
13
13
const program = new Command ( ) ;
14
14
const { ProxyAgent } = require ( 'proxy-agent' ) ;
15
- const reporters = require ( '../reporters.js' ) ;
15
+
16
+ const reporters = {
17
+ default : async function defaultReporter ( err , results , opts , filenameForOutput ) {
18
+ const chalk = ( await import ( 'chalk' ) ) . default
19
+
20
+ const statusLabels = {
21
+ alive : chalk . green ( '✓' ) ,
22
+ dead : chalk . red ( '✖' ) ,
23
+ ignored : chalk . gray ( '/' ) ,
24
+ error : chalk . yellow ( '⚠' ) ,
25
+ } ;
26
+
27
+ if ( err ) {
28
+ console . error ( chalk . red ( "\n ERROR: something went wrong!" ) ) ;
29
+ console . error ( err . stack ) ;
30
+ }
31
+
32
+ if ( results . length === 0 && ! opts . quiet ) {
33
+ console . log ( chalk . yellow ( " No hyperlinks found!" ) ) ;
34
+ }
35
+ results . forEach ( function ( result ) {
36
+ // Skip messages for non-deadlinks in quiet mode.
37
+ if ( opts . quiet && result . status !== "dead" ) {
38
+ return ;
39
+ }
40
+
41
+ if ( opts . verbose ) {
42
+ if ( result . err ) {
43
+ console . log (
44
+ " [%s] %s → Status: %s %s" ,
45
+ statusLabels [ result . status ] ,
46
+ result . link ,
47
+ result . statusCode ,
48
+ result . err
49
+ ) ;
50
+ } else {
51
+ console . log ( " [%s] %s → Status: %s" , statusLabels [ result . status ] , result . link , result . statusCode ) ;
52
+ }
53
+ } else if ( ! opts . quiet ) {
54
+ console . log ( " [%s] %s" , statusLabels [ result . status ] , result . link ) ;
55
+ }
56
+ } ) ;
57
+
58
+ if ( ! opts . quiet ) {
59
+ console . log ( "\n %s links checked." , results . length ) ;
60
+ }
61
+
62
+ if ( results . some ( ( result ) => result . status === "dead" ) ) {
63
+ let deadLinks = results . filter ( ( result ) => {
64
+ return result . status === "dead" ;
65
+ } ) ;
66
+ if ( ! opts . quiet ) {
67
+ console . error ( chalk . red ( "\n ERROR: %s dead links found!" ) , deadLinks . length ) ;
68
+ } else {
69
+ console . error ( chalk . red ( "\n ERROR: %s dead links found in %s !" ) , deadLinks . length , filenameForOutput ) ;
70
+ }
71
+ deadLinks . forEach ( function ( result ) {
72
+ console . log ( " [%s] %s → Status: %s" , statusLabels [ result . status ] , result . link , result . statusCode ) ;
73
+ } ) ;
74
+ }
75
+ } ,
76
+ } ;
16
77
17
78
class Input {
18
79
constructor ( filenameForOutput , stream , opts ) {
0 commit comments