Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<PropertyGroup>
<!-- Enable central package management, https://learn.microsoft.com/en-us/nuget/consume-packages/Central-Package-Management -->
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<MinVerSkip Condition="'$(Configuration)' == 'Debug'">true</MinVerSkip>
</PropertyGroup>
<ItemGroup>
<GlobalPackageReference Include="MinVer" Version="6.0.0" PrivateAssets="All" />
Expand Down Expand Up @@ -42,7 +43,7 @@
<PackageVersion Include="Markdig" Version="0.41.1" />
<PackageVersion Include="NetEscapades.EnumGenerators" Version="1.0.0-beta12" PrivateAssets="all" ExcludeAssets="runtime" />
<PackageVersion Include="Proc" Version="0.9.1" />
<PackageVersion Include="RazorSlices" Version="0.9.2" />
<PackageVersion Include="RazorSlices" Version="0.9.4" />
<PackageVersion Include="Samboy063.Tomlet" Version="6.0.0" />
<PackageVersion Include="Slugify.Core" Version="4.0.1" />
<PackageVersion Include="SoftCircuits.IniFileParser" Version="2.7.0" />
Expand Down Expand Up @@ -70,4 +71,4 @@
</PackageVersion>
<PackageVersion Include="xunit.v3" Version="2.0.2" />
</ItemGroup>
</Project>
</Project>
2 changes: 1 addition & 1 deletion build/Targets.fs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ let private version _ =

let private format _ = exec { run "dotnet" "format" "--verbosity" "quiet" }

let private watch _ = exec { run "dotnet" "watch" "--project" "src/tooling/docs-builder" "--no-hot-reload" "--" "serve" }
let private watch _ = exec { run "dotnet" "watch" "--project" "src/tooling/docs-builder" "--configuration" "debug" "--" "serve" }

let private lint _ =
match exec {
Expand Down
3 changes: 2 additions & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@

<!-- TODO ENABLE to document our code properly <GenerateDocumentationFile>true</GenerateDocumentationFile> -->
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<StartupHookSupport Condition="'$(Configuration)' == 'Debug'">true</StartupHookSupport>
</PropertyGroup>
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
<EnableRequestDelegateGenerator>true</EnableRequestDelegateGenerator>
<InterceptorsPreviewNamespaces>$(InterceptorsPreviewNamespaces);Microsoft.AspNetCore.Http.Generated</InterceptorsPreviewNamespaces>
<IsPublishable>true</IsPublishable>
<StartupHookSupport Condition="'$(Configuration)' == 'Debug'">true</StartupHookSupport>
</PropertyGroup>

<ItemGroup>
Expand Down
30 changes: 30 additions & 0 deletions src/tooling/docs-builder/Http/ReloadGeneratorService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,24 @@
using Microsoft.Extensions.Logging;
using Westwind.AspNetCore.LiveReload;

[assembly: System.Reflection.Metadata.MetadataUpdateHandler(typeof(Documentation.Builder.Http.HotReloadManager))]

namespace Documentation.Builder.Http;

public static class HotReloadManager
{
public static void ClearCache(Type[]? _) => LiveReloadMiddleware.RefreshWebSocketRequest();

public static void UpdateApplication(Type[]? _) => Task.Run(async () =>
{
await Task.Delay(1000);
var __ = LiveReloadMiddleware.RefreshWebSocketRequest();
Console.WriteLine("UpdateApplication");
});

}


public sealed class ReloadGeneratorService(ReloadableGeneratorState reloadableGenerator, ILogger<ReloadGeneratorService> logger) : IHostedService, IDisposable
{
private FileSystemWatcher? _watcher;
Expand All @@ -22,6 +38,9 @@ public async Task StartAsync(Cancel cancellationToken)
await ReloadableGenerator.ReloadAsync(cancellationToken);

var directory = ReloadableGenerator.Generator.DocumentationSet.SourceDirectory.FullName;
#if DEBUG
directory = ReloadableGenerator.Generator.Context.DocumentationCheckoutDirectory?.FullName ?? throw new InvalidOperationException("No checkout directory");
#endif
Logger.LogInformation("Start file watch on: {Directory}", directory);
var watcher = new FileSystemWatcher(directory)
{
Expand All @@ -40,6 +59,9 @@ public async Task StartAsync(Cancel cancellationToken)
watcher.Renamed += OnRenamed;
watcher.Error += OnError;

#if DEBUG
watcher.Filters.Add("*.cshtml");
#endif
watcher.Filters.Add("*.md");
watcher.Filters.Add("docset.yml");
watcher.IncludeSubdirectories = true;
Expand Down Expand Up @@ -73,6 +95,10 @@ private void OnChanged(object sender, FileSystemEventArgs e)
Reload();
if (e.FullPath.EndsWith(".md"))
Reload();
#if DEBUG
if (e.FullPath.EndsWith(".cshtml"))
_ = LiveReloadMiddleware.RefreshWebSocketRequest();
#endif

}

Expand All @@ -97,6 +123,10 @@ private void OnRenamed(object sender, RenamedEventArgs e)
Logger.LogInformation(" New: {NewFullPath}", e.FullPath);
if (e.FullPath.EndsWith(".md"))
Reload();
#if DEBUG
if (e.FullPath.EndsWith(".cshtml"))
_ = LiveReloadMiddleware.RefreshWebSocketRequest();
#endif
}

private void OnError(object sender, ErrorEventArgs e) =>
Expand Down
Loading