From 28d1a4765c0ab69ffda84a5e0751d7ad81f0e803 Mon Sep 17 00:00:00 2001 From: Robin Stevens Date: Fri, 14 Feb 2020 14:36:44 +0100 Subject: [PATCH 1/4] Logger: also count the warning messages If you want to make your build fail on error messages, you currently can do ``` const result = app.generateDocs(project, OUTPUT_DIR); if (!result || app.logger.hasErrors() ) { console.log("Errors were logged during the generation of the documentation. Check the log for more information"); process.exit(1); } ``` However, warning messages typically indicate a problem as well. If you want to make your build fail on those as well, you need a custom logger to keep track of the warning messages yourself. This PR makes this easier by counting the warning messages in a similar fashion as the error messages. --- src/lib/utils/loggers.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/lib/utils/loggers.ts b/src/lib/utils/loggers.ts index f5312e0cc..cae9e8088 100644 --- a/src/lib/utils/loggers.ts +++ b/src/lib/utils/loggers.ts @@ -23,6 +23,11 @@ export class Logger { * How many error messages have been logged? */ errorCount = 0; + + /** + * How many warning messages have been logged? + */ + warningCount = 0; /** * Has an error been raised through the log method? @@ -30,6 +35,13 @@ export class Logger { public hasErrors(): boolean { return this.errorCount > 0; } + + /** + * Has a warning been raised through the log method? + */ + public hasErrors(): boolean { + return this.warningCount > 0; + } /** * Reset the error counter. @@ -37,6 +49,13 @@ export class Logger { public resetErrors() { this.errorCount = 0; } + + /** + * Reset the warning counter. + */ + public resetWarnings() { + this.warningCount = 0; + } /** * Log the given message. @@ -109,6 +128,9 @@ export class Logger { if (level === LogLevel.Error) { this.errorCount += 1; } + if (level === LogLevel.Warning) { + this.warningCount += 1; + } } /** From 60c52e662a78080b2930e64ce8ed734e6f465d5c Mon Sep 17 00:00:00 2001 From: Robin Stevens Date: Fri, 14 Feb 2020 14:40:15 +0100 Subject: [PATCH 2/4] Fixed compile error --- src/lib/utils/loggers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/utils/loggers.ts b/src/lib/utils/loggers.ts index cae9e8088..da0ae949c 100644 --- a/src/lib/utils/loggers.ts +++ b/src/lib/utils/loggers.ts @@ -128,7 +128,7 @@ export class Logger { if (level === LogLevel.Error) { this.errorCount += 1; } - if (level === LogLevel.Warning) { + if (level === LogLevel.Warn) { this.warningCount += 1; } } From fc863c600f7790c205c9405521c489f2e4354f67 Mon Sep 17 00:00:00 2001 From: Robin Stevens Date: Fri, 14 Feb 2020 14:42:29 +0100 Subject: [PATCH 3/4] Fixed another compile error --- src/lib/utils/loggers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/utils/loggers.ts b/src/lib/utils/loggers.ts index da0ae949c..c461d8002 100644 --- a/src/lib/utils/loggers.ts +++ b/src/lib/utils/loggers.ts @@ -39,7 +39,7 @@ export class Logger { /** * Has a warning been raised through the log method? */ - public hasErrors(): boolean { + public hasWarnings(): boolean { return this.warningCount > 0; } From 10bedfd0dcb997038302f1ad3488fc7c925e4c04 Mon Sep 17 00:00:00 2001 From: Robin Stevens Date: Fri, 14 Feb 2020 14:56:43 +0100 Subject: [PATCH 4/4] Fixed tslint errors Removing some trailing whitespace --- src/lib/utils/loggers.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib/utils/loggers.ts b/src/lib/utils/loggers.ts index c461d8002..38057d31c 100644 --- a/src/lib/utils/loggers.ts +++ b/src/lib/utils/loggers.ts @@ -23,7 +23,7 @@ export class Logger { * How many error messages have been logged? */ errorCount = 0; - + /** * How many warning messages have been logged? */ @@ -35,7 +35,7 @@ export class Logger { public hasErrors(): boolean { return this.errorCount > 0; } - + /** * Has a warning been raised through the log method? */ @@ -49,7 +49,7 @@ export class Logger { public resetErrors() { this.errorCount = 0; } - + /** * Reset the warning counter. */