Skip to content

Commit

Permalink
json output
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidVollmers committed May 7, 2024
1 parent 16b3cfc commit 5090b8f
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Doki.sln
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Output", "Output", "{568576
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Doki.Output.Extensions", "src\Doki.Output.Extensions\Doki.Output.Extensions.csproj", "{A89D22B2-2427-4863-A2D9-9E1BEFF37C61}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Doki.Output.Json", "src\Doki.Output.Json\Doki.Output.Json.csproj", "{00BCCBC0-A719-489C-A746-559B4D055B56}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -40,6 +42,7 @@ Global
{57EF4554-C84D-4988-94CF-9D6E908BE10C} = {568576F3-3D48-459E-B4D2-1790DAE80E7A}
{33DFFEBE-DB9E-4960-BB4E-3B58399E132C} = {568576F3-3D48-459E-B4D2-1790DAE80E7A}
{A89D22B2-2427-4863-A2D9-9E1BEFF37C61} = {568576F3-3D48-459E-B4D2-1790DAE80E7A}
{00BCCBC0-A719-489C-A746-559B4D055B56} = {568576F3-3D48-459E-B4D2-1790DAE80E7A}
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{6F31B87A-2BD3-4FB4-8C08-7E059A338D4A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -82,5 +85,9 @@ Global
{A89D22B2-2427-4863-A2D9-9E1BEFF37C61}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A89D22B2-2427-4863-A2D9-9E1BEFF37C61}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A89D22B2-2427-4863-A2D9-9E1BEFF37C61}.Release|Any CPU.Build.0 = Release|Any CPU
{00BCCBC0-A719-489C-A746-559B4D055B56}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{00BCCBC0-A719-489C-A746-559B4D055B56}.Debug|Any CPU.Build.0 = Debug|Any CPU
{00BCCBC0-A719-489C-A746-559B4D055B56}.Release|Any CPU.ActiveCfg = Release|Any CPU
{00BCCBC0-A719-489C-A746-559B4D055B56}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
31 changes: 31 additions & 0 deletions src/Doki.Output.Json/Doki.Output.Json.csproj
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>
33 changes: 33 additions & 0 deletions src/Doki.Output.Json/JsonOutput.cs
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);
}
}
}
19 changes: 19 additions & 0 deletions src/Doki.Output.Json/JsonOutputExtensions.cs
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;
}
}

0 comments on commit 5090b8f

Please sign in to comment.