Skip to content

Commit

Permalink
doki output extensions concept
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidVollmers committed May 4, 2024
1 parent 9dc6978 commit 5f7d54a
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 7 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.ClassLibrary", "src\Doki.Output.ClassLibrary\Doki.Output.ClassLibrary.csproj", "{9619825A-9DD5-4D82-9BBA-6747A8313275}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Doki.Output.Extensions", "src\Doki.Output.Extensions\Doki.Output.Extensions.csproj", "{A89D22B2-2427-4863-A2D9-9E1BEFF37C61}"
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}
{9619825A-9DD5-4D82-9BBA-6747A8313275} = {568576F3-3D48-459E-B4D2-1790DAE80E7A}
{A89D22B2-2427-4863-A2D9-9E1BEFF37C61} = {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
{9619825A-9DD5-4D82-9BBA-6747A8313275}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9619825A-9DD5-4D82-9BBA-6747A8313275}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9619825A-9DD5-4D82-9BBA-6747A8313275}.Release|Any CPU.Build.0 = Release|Any CPU
{A89D22B2-2427-4863-A2D9-9E1BEFF37C61}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{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
EndGlobalSection
EndGlobal
16 changes: 12 additions & 4 deletions src/Doki.CommandLine/Commands/GenerateCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Text.Json;
using System.Xml.XPath;
using Doki.Output;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.FileSystemGlobbing;
using Microsoft.Extensions.FileSystemGlobbing.Abstractions;
using Microsoft.Extensions.Logging;
Expand Down Expand Up @@ -92,7 +93,16 @@ private async Task<int> HandleCommandAsync(InvocationContext context)
return -1;
}

var generator = new DocumentationGenerator();
var serviceCollection = new ServiceCollection();
serviceCollection.AddSingleton(_logger);
serviceCollection.AddSingleton(provider =>
new DocumentationGenerator(provider.GetRequiredService<IServiceProvider>()));

//TODO load outputs

var serviceProvider = serviceCollection.BuildServiceProvider();

var generator = serviceProvider.GetRequiredService<DocumentationGenerator>();

var configureResult = await ConfigureDocumentationGeneratorAsync(new GenerateContext
{
Expand Down Expand Up @@ -214,7 +224,7 @@ private async Task<int> LoadOutputsAsync(GenerateContext context, CancellationTo
}

//TODO refactor output loading

var outputType = await LoadOutputAsync(context.Directory, output, context.AllowPreview, cancellationToken);

if (outputType == null)
Expand All @@ -226,8 +236,6 @@ private async Task<int> LoadOutputsAsync(GenerateContext context, CancellationTo
_logger.LogDebug("Adding output: {OutputType}", outputType);

var outputAttribute = outputType.GetCustomAttribute<DokiOutputAttribute>();


}

return 0;
Expand Down
2 changes: 1 addition & 1 deletion src/Doki.Output.ClassLibrary/ClassLibraryOutput.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Doki.Output.ClassLibrary;

public sealed class ClassLibraryOutput(IOutputOptions<ClassLibraryOutput> options) : IOutput
internal class ClassLibraryOutput(IOutputOptions<ClassLibraryOutput> options) : IOutput

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

View workflow job for this annotation

GitHub Actions / Test

Parameter 'options' is unread.

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

View workflow job for this annotation

GitHub Actions / Test

Parameter 'options' is unread.

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

View workflow job for this annotation

GitHub Actions / Test

Parameter 'options' is unread.
{
public async Task WriteAsync(ContentList contentList, CancellationToken cancellationToken = default)

Check warning on line 5 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 5 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 5 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.
{
Expand Down
19 changes: 19 additions & 0 deletions src/Doki.Output.ClassLibrary/ClassLibraryOutputExtensions.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.ClassLibrary;

public static class ClassLibraryOutputExtensions
{
[DokiOutputRegistration]
public static IServiceCollection AddClassLibraryOutput(this IServiceCollection services)
{
ArgumentNullException.ThrowIfNull(services);

//TODO add options

services.AddSingleton<IOutput, ClassLibraryOutput>();

return services;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

<ItemGroup>
<ProjectReference Include="..\Doki.Output.Abstractions\Doki.Output.Abstractions.csproj"/>
<ProjectReference Include="..\Doki.Output.Extensions\Doki.Output.Extensions.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
25 changes: 25 additions & 0 deletions src/Doki.Output.Extensions/Doki.Output.Extensions.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<PackageId>Doki.Output.Extensions</PackageId>
<Authors>david@vollmers.org</Authors>
<Copyright>David Vollmers</Copyright>
<Description>Doki Output Extensions</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>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.1" />
</ItemGroup>

</Project>
6 changes: 6 additions & 0 deletions src/Doki.Output.Extensions/DokiOutputRegistrationAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Doki.Output.Extensions;

[AttributeUsage(AttributeTargets.Method)]
public sealed class DokiOutputRegistrationAttribute : Attribute
{
}
1 change: 1 addition & 0 deletions src/Doki.Output.Markdown/Doki.Output.Markdown.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

<ItemGroup>
<ProjectReference Include="..\Doki.Output.Abstractions\Doki.Output.Abstractions.csproj"/>
<ProjectReference Include="..\Doki.Output.Extensions\Doki.Output.Extensions.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Doki.Output.Markdown/MarkdownOutput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Doki.Output.Markdown;

public sealed class MarkdownOutput(IOutputOptions<MarkdownOutput> options) : IOutput
internal class MarkdownOutput(IOutputOptions<MarkdownOutput> options) : IOutput
{
public async Task WriteAsync(ContentList contentList, CancellationToken cancellationToken = default)
{
Expand Down
19 changes: 19 additions & 0 deletions src/Doki.Output.Markdown/MarkdownOutputExtensions.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.Markdown;

public static class MarkdownOutputExtensions
{
[DokiOutputRegistration]
public static IServiceCollection AddMarkdownOutput(this IServiceCollection services)
{
ArgumentNullException.ThrowIfNull(services);

//TODO add options

services.AddSingleton<IOutput, MarkdownOutput>();

return services;
}
}
2 changes: 1 addition & 1 deletion src/Doki/Doki.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0"/>
</ItemGroup>

Expand Down

0 comments on commit 5f7d54a

Please sign in to comment.