Skip to content

Commit

Permalink
clear output directory before generations
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidVollmers committed May 5, 2024
1 parent 4e7c446 commit a7a2c11
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Doki.Output.Abstractions/IOutput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
/// </summary>
public interface IOutput
{
Task BeginAsync(CancellationToken cancellationToken = default) => Task.CompletedTask;

Task EndAsync(CancellationToken cancellationToken = default) => Task.CompletedTask;

/// <summary>
/// Writes the content list to the output.
/// </summary>
Expand Down
2 changes: 2 additions & 0 deletions src/Doki.Output.Abstractions/OutputOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ namespace Doki.Output;
public record OutputOptions<T> where T : IOutput
{
[JsonPropertyName("outputPath")] public DirectoryInfo OutputDirectory { get; init; } = null!;

[JsonPropertyName("clearOutput")] public bool ClearOutput { get; init; } = true;
}
14 changes: 14 additions & 0 deletions src/Doki.Output.Abstractions/OutputOptionsExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace Doki.Output;

public static class OutputOptionsExtensions
{
public static void ClearOutputDirectoryIfRequired<T>(this OutputOptions<T> options) where T : IOutput
{
ArgumentNullException.ThrowIfNull(options);

if (options is { ClearOutput: true, OutputDirectory.Exists: true })
{
options.OutputDirectory.Delete(true);
}
}
}
7 changes: 7 additions & 0 deletions src/Doki.Output.ClassLibrary/ClassLibraryOutput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

public sealed class ClassLibraryOutput(ClassLibraryOutputOptions options) : IOutput
{
public Task BeginAsync(CancellationToken cancellationToken = default)
{
options.ClearOutputDirectoryIfRequired();

return Task.CompletedTask;
}

public async Task WriteAsync(ContentList contentList, CancellationToken cancellationToken = default)

Check warning on line 12 in src/Doki.Output.ClassLibrary/ClassLibraryOutput.cs

View workflow job for this annotation

GitHub Actions / Test

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 12 in src/Doki.Output.ClassLibrary/ClassLibraryOutput.cs

View workflow job for this annotation

GitHub Actions / Test

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 12 in src/Doki.Output.ClassLibrary/ClassLibraryOutput.cs

View workflow job for this annotation

GitHub Actions / Test

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
ArgumentNullException.ThrowIfNull(contentList);
Expand Down
7 changes: 7 additions & 0 deletions src/Doki.Output.Markdown/MarkdownOutput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ namespace Doki.Output.Markdown;

public sealed class MarkdownOutput(OutputOptions<MarkdownOutput> options) : IOutput
{
public Task BeginAsync(CancellationToken cancellationToken = default)
{
options.ClearOutputDirectoryIfRequired();

return Task.CompletedTask;
}

public async Task WriteAsync(ContentList contentList, CancellationToken cancellationToken = default)
{
ArgumentNullException.ThrowIfNull(contentList);
Expand Down
10 changes: 10 additions & 0 deletions src/Doki/DocumentationGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ public async Task GenerateAsync(ILogger logger, CancellationToken cancellationTo

logger.LogInformation("Generating documentation for {AssemblyCount} assemblies.", _assemblies.Count);

foreach (var output in outputs)
{
await output.BeginAsync(cancellationToken);
}

var assemblies = new ContentList
{
Id = ContentList.Assemblies,
Expand Down Expand Up @@ -184,6 +189,11 @@ await GenerateAssemblyDocumentationAsync(new GeneratorContext<Assembly>
{
await output.WriteAsync(assemblies, cancellationToken);
}

foreach (var output in outputs)
{
await output.EndAsync(cancellationToken);
}
}

private async Task<AssemblyDocumentation?> GenerateAssemblyDocumentationAsync(GeneratorContext<Assembly> context,
Expand Down

0 comments on commit a7a2c11

Please sign in to comment.