From 27199f9ba27125859865955dbe791714df80c927 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Denuzi=C3=A8re?= Date: Wed, 3 Jan 2024 17:15:51 +0100 Subject: [PATCH 1/4] Version 0.24-alpha --- version.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.json b/version.json index 53b7a14..6cfe45b 100644 --- a/version.json +++ b/version.json @@ -1,6 +1,6 @@ { "$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json", - "version": "0.23", + "version": "0.24-alpha", "gitCommitIdShortAutoMinimum": 7, "nuGetPackageVersion": { "semVer": 2.0 From 1af86223056d7ed9980c498cb2a11f8035b0b39f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Denuzi=C3=A8re?= Date: Wed, 3 Jan 2024 16:40:55 +0100 Subject: [PATCH 2/4] feat: Add --render and interactive render modes --- .build/build.fs | 11 +++++++ .../.template.config/dotnetcli.host.json | 4 +++ .../.template.config/template.json | 33 +++++++++++++++++++ .../src/Bolero.Template.1.Server/Index.fs | 20 ++++++++++- .../src/Bolero.Template.1.Server/Startup.fs | 26 ++++++++++++--- 5 files changed, 88 insertions(+), 6 deletions(-) diff --git a/.build/build.fs b/.build/build.fs index 458f205..e7aa897 100644 --- a/.build/build.fs +++ b/.build/build.fs @@ -55,6 +55,17 @@ let variantsToTest = $"--html={htmlv}" $"--hotreload={reloadv}" ] + if (hostv = "bolero") then + for renderk, renderv in [("IntServer", "InteractiveServer");("IntWasm", "InteractiveWebAssembly");("IntAuto", "InteractiveAuto");] do + $"{minik}.{renderk}.{hostk}.{htmlk}.{pwak}", [ + "--server" + $"--minimal={miniv}" + $"--hostpage={hostv}" + $"--pwa={pwav}" + $"--html={htmlv}" + $"--hotreload={reloadv}" + $"--render={renderv}" + ] // Client for htmlk, htmlv in [("Html", "true"); ("NoHtml", "false")] do for minik, miniv in [("Minimal", "true"); ("Full", "false")] do diff --git a/content/application/.template.config/dotnetcli.host.json b/content/application/.template.config/dotnetcli.host.json index e24249a..b83e685 100644 --- a/content/application/.template.config/dotnetcli.host.json +++ b/content/application/.template.config/dotnetcli.host.json @@ -21,6 +21,10 @@ "longName": "hostpage", "shortName": "hp" }, + "render": { + "longName": "render", + "shortName": "r" + }, "pwa": { "longName": "pwa", "shortName": "pwa" diff --git a/content/application/.template.config/template.json b/content/application/.template.config/template.json index 5fc256e..5e6556d 100644 --- a/content/application/.template.config/template.json +++ b/content/application/.template.config/template.json @@ -52,6 +52,39 @@ ], "defaultValue":"bolero" }, + "render": { + "type": "parameter", + "isRequired": false, + "description": "The type of rendering to use (ignored if server=false or hostpage!=bolero)", + "dataType": "choice", + "replaces": "RENDER_MODE", + "choices": [ + {"choice":"InteractiveServer","description":"Use InteractiveServer render mode"}, + {"choice":"InteractiveWebAssembly","description":"Use InteractiveWebAssembly render mode"}, + {"choice":"InteractiveAuto","description":"Use InteractiveAuto render mode"}, + {"choice":"Server","description":"Use classic server-side mode"}, + {"choice":"WebAssembly","description":"Use classic client-side mode"} + ], + "defaultValue": "WebAssembly" + }, + "isInteractive": { + "type": "computed", + "dataType": "bool", + "value": "(hostpage == \"bolero\" && (render == \"InteractiveServer\" || render == \"InteractiveWebAssembly\" || render == \"InteractiveAuto\"))" + }, + "renderServer": { + "type": "generated", + "generator": "switch", + "replaces": "RENDER_SERVER", + "parameters": { + "evaluator": "C++", + "datatype": "string", + "cases": [ + {"condition": "(render == \"Server\")", "value": "true"}, + {"condition": "(render != \"Server\")", "value": "false"} + ] + } + }, "pwa": { "type": "parameter", "isRequired": false, diff --git a/content/application/src/Bolero.Template.1.Server/Index.fs b/content/application/src/Bolero.Template.1.Server/Index.fs index 19399d3..7c5f8e0 100644 --- a/content/application/src/Bolero.Template.1.Server/Index.fs +++ b/content/application/src/Bolero.Template.1.Server/Index.fs @@ -1,5 +1,9 @@ module Bolero.Template._1.Server.Index +//#if (isInteractive) +open Microsoft.AspNetCore.Components +open Microsoft.AspNetCore.Components.Web +//#endif open Bolero open Bolero.Html open Bolero.Server.Html @@ -38,10 +42,24 @@ let page = doctypeHtml { } } //#endif - div { attr.id "main"; comp } + div { + attr.id "main" +//#if (isInteractive) + comp { attr.renderMode RenderMode.RENDER_MODE } +//#else + comp +//#endif + } boleroScript //#if (pwa) script { rawHtml "navigator.serviceWorker.register('service-worker.js');" } //#endif } } +//#if (isInteractive) + +[] +type Page() = + inherit Bolero.Component() + override _.Render() = page +//#endif diff --git a/content/application/src/Bolero.Template.1.Server/Startup.fs b/content/application/src/Bolero.Template.1.Server/Startup.fs index 8c7dd3b..f784845 100644 --- a/content/application/src/Bolero.Template.1.Server/Startup.fs +++ b/content/application/src/Bolero.Template.1.Server/Startup.fs @@ -18,21 +18,28 @@ open Bolero.Templating.Server let main args = let builder = WebApplication.CreateBuilder(args) -//#if (hostpage == "razor") +//#if (isInteractive) + builder.Services.AddRazorComponents() + .AddInteractiveServerComponents() + .AddInteractiveWebAssemblyComponents() + |> ignore +//#elseif (hostpage == "razor") builder.Services.AddMvc().AddRazorRuntimeCompilation() |> ignore //#else builder.Services.AddMvc() |> ignore //#endif builder.Services.AddServerSideBlazor() |> ignore -//#if (!minimal) builder.Services.AddAuthorization() .AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) .AddCookie() |> ignore +//#if (!minimal) builder.Services.AddBoleroRemoting() |> ignore //#endif -//#if (hostpage != "html") - builder.Services.AddBoleroHost() |> ignore +//#if (isInteractive) + builder.Services.AddBoleroComponents() |> ignore +//#elseif (hostpage != "html") + builder.Services.AddBoleroHost(server = RENDER_SERVER) |> ignore //#endif //#if (hotreload_actual) #if DEBUG @@ -50,7 +57,11 @@ let main args = .UseStaticFiles() .UseRouting() .UseAuthorization() +//#if (isInteractive) + .UseAntiforgery() +//#else .UseBlazorFrameworkFiles() +//#endif |> ignore //#if (hotreload_actual) @@ -59,7 +70,12 @@ let main args = #endif //#endif app.MapBoleroRemoting() |> ignore -//#if (hostpage == "razor") +//#if (isInteractive) + app.MapRazorComponents() + .AddInteractiveServerRenderMode() + .AddInteractiveWebAssemblyRenderMode() + .AddAdditionalAssemblies(typeof.Assembly) +//#elseif (hostpage == "razor") app.MapBlazorHub() |> ignore app.MapFallbackToPage("/_Host") |> ignore //#elseif (hostpage == "bolero") From 97dcd4ac0017216d4285b29d80f0d1499f13333a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Denuzi=C3=A8re?= Date: Wed, 3 Jan 2024 16:51:57 +0100 Subject: [PATCH 3/4] doc: document --render and update changelog --- CHANGELOG.md | 10 ++++++++++ README.md | 16 ++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cb88823..45c8cbb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # Changelog +## 0.24 + +* Fix `--nightly` to use GitHub packages with `--githubUsername` and `--githubToken`. +* [#50](https://github.com/fsbolero/Template/issues/50) Add option `--render` to decide the render mode. Possible values are: + * `Server` for classic server-side mode. + * `WebAssembly` for classic client-side mode. + * `InteractiveServer` for server-side interactive render mode (see https://learn.microsoft.com/en-us/aspnet/core/blazor/components/render-modes?view=aspnetcore-8.0). + * `InteractiveWebAssembly` for client-side interactive render mode. + * `InteractiveAuto` for automatic interactive render mode (client-side if available, otherwise server-side while downloading the client-side runtime in the background). + ## 0.23 * [#41](https://github.com/fsbolero/Template/issues/41) Fix issue where, when creating a project containing a dash, the solution file uses an underscore in the project path. diff --git a/README.md b/README.md index 3658ed9..36b97c9 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,22 @@ You can use the following options to customize the project being created: This is ignored if `server=false`. + * `--render`, `-r`: + + Determines the render mode. Can be one of: + + * `Server` for classic server-side mode. + + * `WebAssembly` for classic client-side mode. + + * `InteractiveServer` for server-side interactive render mode (see https://learn.microsoft.com/en-us/aspnet/core/blazor/components/render-modes?view=aspnetcore-8.0). + + * `InteractiveWebAssembly` for client-side interactive render mode. + + * `InteractiveAuto` for automatic interactive render mode (client-side if available, otherwise server-side while downloading the client-side runtime in the background). + + This is ignored if `server=false`. Moreover, the `Interactive*` render modes are only compatible with `hostpage=bolero`. + * `--html`, `-ht`: If `true` (the default), use HTML templates. From 13c23594187e908f1bc3f34ea37d88ebc58f8556 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Denuzi=C3=A8re?= Date: Wed, 3 Jan 2024 17:57:31 +0100 Subject: [PATCH 4/4] Publish to github nuget on releases too --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6840133..9f37cb4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -49,7 +49,7 @@ jobs: prerelease: runs-on: ubuntu-latest needs: build - if: ${{ github.ref == 'refs/heads/master' }} + if: ${{ github.ref == 'refs/heads/master' || contains(github.ref, 'releases') }} steps: - name: Download nupkg uses: actions/download-artifact@v1