diff --git a/docs/source/index.md b/docs/source/index.md index 7495ae5..bc23f96 100644 --- a/docs/source/index.md +++ b/docs/source/index.md @@ -9,10 +9,11 @@ This repository is host to: * *`docs-builder`* command line tool to generate single doc-sets (13mb native code, no dependencies) * *`docs-assembler`* command line tool to assemble all the doc sets. (IN PROGRESS) * `elastic/docs-builder@main` Github Action to build and validate a repositories documentation +* *`docs-generator`* command line tool to deterministically generate a docset and incremental updates to generated content ## Command line interface -``` +```bash $ docs-builder --help Usage: [command] [options...] [-h|--help] [--version] @@ -130,16 +131,13 @@ https://github.com/elastic/{your-repository}/settings/pages ## Run without docker If you have dotnet 8 installed you can use its CLI to publish a self-contained `docs-builder` native code -binary. (On my M2 Pro mac the binary is currently 13mb) +binary. (On my M2 Pro mac the binary is currently 16mb) ```bash -$ dotnet publish "src/docs-builder/docs-builder.csproj" -c Release -o .artifacts/publish \ - --self-contained true /p:PublishTrimmed=true /p:PublishSingleFile=false /p:PublishAot=true -a arm64 +$ dotnet publish "src/docs-builder/docs-builder.csproj" ``` -**Note**: `-a` should be the machines CPU architecture - -The resulting binary `./.artifacts/publish/docs-builder` will run on machines without .NET installed +The resulting binary `./.artifacts/publish/docs-builder/release/docs-builder` will run on machines without .NET installed # Performance diff --git a/src/docs-builder/ConsoleApp.cs b/src/docs-builder/ConsoleApp.cs index 159ff50..bf80c8e 100644 --- a/src/docs-builder/ConsoleApp.cs +++ b/src/docs-builder/ConsoleApp.cs @@ -11,9 +11,7 @@ // ReSharper disable once CheckNamespace namespace ConsoleAppFramework; -[UnconditionalSuppressMessage("AssemblyLoadTrimming", "IL2026:RequiresUnreferencedCode", - Justification = "Everything referenced in the loaded assembly is manually preserved, so it's safe")] -[UnconditionalSuppressMessage("AssemblyLoadTrimming", "IL3050:RequiresUnreferencedCode", - Justification = "Everything referenced in the loaded assembly is manually preserved, so it's safe")] +[UnconditionalSuppressMessage("AssemblyLoadTrimming", "IL2026:RequiresUnreferencedCode", Justification = "Manually verified")] +[UnconditionalSuppressMessage("AssemblyLoadTrimming", "IL3050:RequiresDynamicCode", Justification = "Manually verified")] internal static partial class ConsoleApp; diff --git a/src/docs-builder/Http/DocumentationWebHost.cs b/src/docs-builder/Http/DocumentationWebHost.cs index 656e9bb..416b3f2 100644 --- a/src/docs-builder/Http/DocumentationWebHost.cs +++ b/src/docs-builder/Http/DocumentationWebHost.cs @@ -32,7 +32,7 @@ public DocumentationWebHost(string? path, ILoggerFactory logger, IFileSystem fil { Collector = new ConsoleDiagnosticsCollector(logger) }; - builder.Services.AddLiveReload(s => + builder.Services.AddAotLiveReload(s => { s.FolderToMonitor = context.SourcePath.FullName; s.ClientFileExtensions = ".md,.yml"; diff --git a/src/docs-builder/Http/LiveReload.cs b/src/docs-builder/Http/LiveReload.cs new file mode 100644 index 0000000..904e37d --- /dev/null +++ b/src/docs-builder/Http/LiveReload.cs @@ -0,0 +1,57 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information + +using System.Diagnostics.CodeAnalysis; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; + +namespace Westwind.AspNetCore.LiveReload; + +[UnconditionalSuppressMessage("AssemblyLoadTrimming", "IL2026:RequiresUnreferencedCode", Justification = "Manually verified")] +[UnconditionalSuppressMessage("AssemblyLoadTrimming", "IL3050:RequiresDynamicCode", Justification = "Manually verified")] +public static class LiveReloadMiddlewareExtensions +{ + + public static IServiceCollection AddAotLiveReload(this IServiceCollection services, + Action configAction) + { + + var provider = services.BuildServiceProvider(); + var configuration = provider.GetService(); + + var config = new LiveReloadConfiguration(); + configuration!.Bind("LiveReload", config); + + LiveReloadConfiguration.Current = config; + + if (config.LiveReloadEnabled) + { + var env = provider.GetService(); + if (string.IsNullOrEmpty(config.FolderToMonitor)) + { + config.FolderToMonitor = env!.ContentRootPath; + } + else if (config.FolderToMonitor.StartsWith("~")) + { + if (config.FolderToMonitor.Length > 1) + { + var folder = config.FolderToMonitor.Substring(1); + if (folder.StartsWith('/') || folder.StartsWith("\\")) + folder = folder.Substring(1); + config.FolderToMonitor = Path.Combine(env!.ContentRootPath, folder); + config.FolderToMonitor = Path.GetFullPath(config.FolderToMonitor); + } + else + config.FolderToMonitor = env!.ContentRootPath; + } + + configAction.Invoke(config); + + LiveReloadConfiguration.Current = config; + } + + return services; + } +} diff --git a/src/docs-builder/docs-builder.csproj b/src/docs-builder/docs-builder.csproj index 6d97afc..17d1bd6 100644 --- a/src/docs-builder/docs-builder.csproj +++ b/src/docs-builder/docs-builder.csproj @@ -6,12 +6,14 @@ docs-builder Documentation.Builder true + true - true true $(InterceptorsPreviewNamespaces);Microsoft.AspNetCore.Http.Generated true + true + true true false @@ -25,7 +27,6 @@ -