Skip to content

Commit

Permalink
Added summary on warnings and errors (#2581) (#2583)
Browse files Browse the repository at this point in the history
* feat: added a message summarizing the number of errors and warnings if there are any, fix: VERSION property is readonly

* tests: added test for errors and warnings summary message

* tests: added test for errors and warnings summary message (generateJson)

* chore: added a comment

* fix: typescript errors

* fix: fixed warnings by prettier

* refactor: moved logRunSummary to cli

* fix: lint issues
  • Loading branch information
bladerunner2020 committed Jun 11, 2024
1 parent 33a34d6 commit 2baf578
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/lib/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export class Application extends ChildableComponent<
/**
* The version number of TypeDoc.
*/
static VERSION = packageInfo.version;
static readonly VERSION = packageInfo.version;

/**
* Emitted after plugins have been loaded and options have been read, but before they have been frozen.
Expand Down Expand Up @@ -525,6 +525,7 @@ export class Application extends ChildableComponent<
const start = Date.now();
out = Path.resolve(out);
await this.renderer.render(project, out);

if (this.logger.hasErrors()) {
this.logger.error(
"Documentation could not be generated due to the errors above.",
Expand All @@ -551,6 +552,7 @@ export class Application extends ChildableComponent<

const space = this.options.getValue("pretty") ? "\t" : "";
await writeFile(out, JSON.stringify(ser, null, space));

this.logger.info(`JSON written to ${nicePath(out)}`);
this.logger.verbose(`JSON rendering took ${Date.now() - start}ms`);
}
Expand Down
15 changes: 15 additions & 0 deletions src/lib/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ async function main() {
const exitCode = await run(app);
if (exitCode !== ExitCodes.Watching) {
app.logger.verbose(`Full run took ${Date.now() - start}ms`);
logRunSummary(app.logger);
process.exit(exitCode);
}
} catch (error) {
Expand Down Expand Up @@ -135,3 +136,17 @@ async function run(app: td.Application) {

return ExitCodes.Ok;
}

/**
* Generate a string with the number of errors and warnings found.
*/
function logRunSummary(logger: td.Logger): void {
const { errorCount, warningCount } = logger;
if (errorCount) {
logger.error(
`Found: ${errorCount} error(s), ${warningCount} warnings.`,
);
} else if (warningCount) {
logger.warn(`Found: ${errorCount} error(s), ${warningCount} warnings.`);
}
}

0 comments on commit 2baf578

Please sign in to comment.