From 4fd134bafc3175ee38a3384d322fb7f5b7d0af51 Mon Sep 17 00:00:00 2001 From: Andrii Chebukin Date: Wed, 29 Nov 2023 01:41:28 +0400 Subject: [PATCH 1/2] Update `Paket` to `8.0.0` --- .config/dotnet-tools.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index 0cbc674..9cc1a0c 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -3,13 +3,13 @@ "isRoot": true, "tools": { "nbgv": { - "version": "3.4.244", + "version": "3.6.133", "commands": [ "nbgv" ] }, "paket": { - "version": "7.1.4", + "version": "8.0.0", "commands": [ "paket" ] From 0b60da2e958da6f13ecfda80fe909886bd2de341 Mon Sep 17 00:00:00 2001 From: Andrii Chebukin Date: Wed, 29 Nov 2023 02:02:48 +0400 Subject: [PATCH 2/2] Implement C# friendly API --- src/Bolero.Templating.Server/Attributes.fs | 9 ++++++ .../Bolero.Templating.Server.fsproj | 1 + src/Bolero.Templating.Server/Templating.fs | 30 +++++++++++++------ src/Bolero.Templating/Settings.fs | 10 +++++-- 4 files changed, 39 insertions(+), 11 deletions(-) create mode 100644 src/Bolero.Templating.Server/Attributes.fs diff --git a/src/Bolero.Templating.Server/Attributes.fs b/src/Bolero.Templating.Server/Attributes.fs new file mode 100644 index 0000000..1fc091d --- /dev/null +++ b/src/Bolero.Templating.Server/Attributes.fs @@ -0,0 +1,9 @@ +namespace Bolero.Templating.Server + +open System + +[] +type internal TimeSpanConstantAttribute(miliseconds) = + inherit Attribute() + member _.Value = TimeSpan.FromMilliseconds miliseconds + diff --git a/src/Bolero.Templating.Server/Bolero.Templating.Server.fsproj b/src/Bolero.Templating.Server/Bolero.Templating.Server.fsproj index 6e7dad9..7b97904 100644 --- a/src/Bolero.Templating.Server/Bolero.Templating.Server.fsproj +++ b/src/Bolero.Templating.Server/Bolero.Templating.Server.fsproj @@ -7,6 +7,7 @@ Library + diff --git a/src/Bolero.Templating.Server/Templating.fs b/src/Bolero.Templating.Server/Templating.fs index ca690c8..e8e258a 100644 --- a/src/Bolero.Templating.Server/Templating.fs +++ b/src/Bolero.Templating.Server/Templating.fs @@ -24,6 +24,7 @@ open System.Collections.Concurrent open System.IO open System.Threading.Tasks open System.Runtime.CompilerServices +open System.Runtime.InteropServices open Microsoft.AspNetCore.Builder open Microsoft.AspNetCore.Routing open Microsoft.AspNetCore.SignalR @@ -178,27 +179,38 @@ module Impl = for handler in handlers do handler.Dispose() -[] -type ServerTemplatingExtensions = +[] +module private Constants = + + let [] DefaultTemplateDir = "." + let [] DefaultDelay = 100. + + +[] +type ServerTemplatingExtensions() = [] - static member AddHotReload(this: IServiceCollection, configure: WatcherConfig -> WatcherConfig) : IServiceCollection = + static member AddHotReload(this: IServiceCollection, configure: Func) : IServiceCollection = this.AddSignalR().AddJsonProtocol() |> ignore - let config = configure { Directory = "."; Delay = TimeSpan.FromMilliseconds 100. } + let config = configure.Invoke { Directory = DefaultTemplateDir; Delay = TimeSpan.FromMilliseconds DefaultDelay } this.AddSingleton(config) .AddSingleton() .AddTransient() [] - static member AddHotReload(this: IServiceCollection, ?templateDir: string, ?delay: TimeSpan) : IServiceCollection = + static member AddHotReload( + this: IServiceCollection, + [] templateDir: string, + [] delay: TimeSpan) + : IServiceCollection = ServerTemplatingExtensions.AddHotReload(this, fun config -> { - Directory = defaultArg templateDir config.Directory - Delay = defaultArg delay config.Delay + Directory = templateDir + Delay = delay }) [] - static member UseHotReload(this: IEndpointRouteBuilder, ?urlPath: string) : unit = + static member UseHotReload(this: IEndpointRouteBuilder, [] urlPath: string) : unit = this.ServiceProvider.GetService().Start() - let urlPath = defaultArg urlPath HotReloadSettings.Default.Url + let urlPath = urlPath this.MapHub(urlPath) |> ignore diff --git a/src/Bolero.Templating/Settings.fs b/src/Bolero.Templating/Settings.fs index 6b57fd3..082ec41 100644 --- a/src/Bolero.Templating/Settings.fs +++ b/src/Bolero.Templating/Settings.fs @@ -20,6 +20,12 @@ namespace Bolero.Templating +[] +module HotReloadConstants = + + let [] DefaultUrl = "/bolero-reload" + let [] DefaultReconnectDelay = 5000 + type HotReloadSettings = { Url: string @@ -28,6 +34,6 @@ type HotReloadSettings = static member Default = { - Url = "/bolero-reload" - ReconnectDelayInMs = 5000 + Url = HotReloadConstants.DefaultUrl + ReconnectDelayInMs = HotReloadConstants.DefaultReconnectDelay }