-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
16b3cfc
commit 5090b8f
Showing
4 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<PackageId>Doki.Output.Json</PackageId> | ||
<Authors>david@vollmers.org</Authors> | ||
<Copyright>David Vollmers</Copyright> | ||
<Description>Doki JSON Generator</Description> | ||
<PackageProjectUrl>https://github.com/DavidVollmers/doki</PackageProjectUrl> | ||
<PackageLicenseExpression>MIT</PackageLicenseExpression> | ||
<PackageReadmeFile>README.md</PackageReadmeFile> | ||
<PackageIcon>logo-64x64.png</PackageIcon> | ||
<RepositoryType>git</RepositoryType> | ||
<RepositoryUrl>https://github.com/DavidVollmers/doki.git</RepositoryUrl> | ||
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks> | ||
<LangVersion>12</LangVersion> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<PackageOutputPath>..\..\nuget</PackageOutputPath> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Doki.Output.Extensions\Doki.Output.Extensions.csproj"/> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Include="..\..\README.md" Pack="true" PackagePath="\"/> | ||
<None Include="..\..\LICENSE.txt" Pack="true" PackagePath="\"/> | ||
<None Include="..\..\assets\logo-64x64.png" Pack="true" PackagePath="\"/> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System.Text.Json; | ||
|
||
namespace Doki.Output.Json; | ||
|
||
public sealed class JsonOutput(OutputOptions<JsonOutput> options) : IOutput | ||
{ | ||
private static readonly JsonSerializerOptions JsonSerializerOptions = new() | ||
{ | ||
WriteIndented = true | ||
}; | ||
|
||
public Task BeginAsync(CancellationToken cancellationToken = default) | ||
{ | ||
options.ClearOutputDirectoryIfRequired(); | ||
|
||
return Task.CompletedTask; | ||
} | ||
|
||
public async Task WriteAsync(DocumentationRoot root, CancellationToken cancellationToken = default) | ||
{ | ||
ArgumentNullException.ThrowIfNull(root); | ||
|
||
foreach (var assemblyDocumentation in root.Assemblies) | ||
{ | ||
var file = new FileInfo(Path.Combine(options.OutputDirectory.FullName, $"{assemblyDocumentation.Id}.json")); | ||
|
||
if (!file.Directory!.Exists) file.Directory.Create(); | ||
|
||
await File.WriteAllTextAsync(file.FullName, | ||
JsonSerializer.Serialize(assemblyDocumentation, JsonSerializerOptions), cancellationToken); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using Doki.Output.Extensions; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace Doki.Output.Json; | ||
|
||
public static class JsonOutputExtensions | ||
{ | ||
[DokiOutputRegistration] | ||
public static IServiceCollection AddMarkdownOutput(this IServiceCollection services) | ||
{ | ||
ArgumentNullException.ThrowIfNull(services); | ||
|
||
services.AddOutputOptions<JsonOutput>("Doki.Output.Json"); | ||
|
||
services.AddSingleton<IOutput, JsonOutput>(); | ||
|
||
return services; | ||
} | ||
} |