From 112b9212923e51184538f54a5c7e09f26a17d795 Mon Sep 17 00:00:00 2001 From: Tyler Kvochick Date: Tue, 25 Jun 2024 22:22:14 -0400 Subject: [PATCH 01/15] Remove root parameter override in watch mode --- src/fsdocs-tool/BuildCommand.fs | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/src/fsdocs-tool/BuildCommand.fs b/src/fsdocs-tool/BuildCommand.fs index e00d4837..4ff4ea81 100644 --- a/src/fsdocs-tool/BuildCommand.fs +++ b/src/fsdocs-tool/BuildCommand.fs @@ -1405,24 +1405,12 @@ type CoreBuildOptions(watch) = // Adjust the user substitutions for 'watch' mode root let userRoot, userParameters = - if watch then - let userRoot = sprintf "http://localhost:%d/" this.port_option - - if userParametersDict.ContainsKey(ParamKeys.root) then - printfn "ignoring user-specified root since in watch mode, root = %s" userRoot - - let userParameters = - [ ParamKeys.root, userRoot ] - @ (userParameters |> List.filter (fun (a, _) -> a <> ParamKeys.root)) - - Some userRoot, userParameters - else - let r = - match userParametersDict.TryGetValue(ParamKeys.root) with - | true, v -> Some v - | _ -> None + let r = + match userParametersDict.TryGetValue(ParamKeys.root) with + | true, v -> Some v + | _ -> None - r, userParameters + r, userParameters let userCollectionName = match (dict userParameters).TryGetValue(ParamKeys.``fsdocs-collection-name``) with From dfa48cc762192f5542ca4c39c16a6eb457a64d3f Mon Sep 17 00:00:00 2001 From: Tyler Kvochick Date: Tue, 25 Jun 2024 22:29:07 -0400 Subject: [PATCH 02/15] Remove comment --- src/fsdocs-tool/BuildCommand.fs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/fsdocs-tool/BuildCommand.fs b/src/fsdocs-tool/BuildCommand.fs index 4ff4ea81..94a90f01 100644 --- a/src/fsdocs-tool/BuildCommand.fs +++ b/src/fsdocs-tool/BuildCommand.fs @@ -1403,7 +1403,6 @@ type CoreBuildOptions(watch) = let userParametersDict = readOnlyDict userParameters - // Adjust the user substitutions for 'watch' mode root let userRoot, userParameters = let r = match userParametersDict.TryGetValue(ParamKeys.root) with From 6cd58b9b7aed0e7b58845566e9210e93ef080181 Mon Sep 17 00:00:00 2001 From: Tyler Kvochick Date: Tue, 25 Jun 2024 22:32:42 -0400 Subject: [PATCH 03/15] Remove unnecessary reassignment --- src/fsdocs-tool/BuildCommand.fs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/fsdocs-tool/BuildCommand.fs b/src/fsdocs-tool/BuildCommand.fs index 94a90f01..0f751329 100644 --- a/src/fsdocs-tool/BuildCommand.fs +++ b/src/fsdocs-tool/BuildCommand.fs @@ -1403,13 +1403,10 @@ type CoreBuildOptions(watch) = let userParametersDict = readOnlyDict userParameters - let userRoot, userParameters = - let r = - match userParametersDict.TryGetValue(ParamKeys.root) with - | true, v -> Some v - | _ -> None - - r, userParameters + let userRoot = + match userParametersDict.TryGetValue(ParamKeys.root) with + | true, v -> Some v + | _ -> None let userCollectionName = match (dict userParameters).TryGetValue(ParamKeys.``fsdocs-collection-name``) with From 22f4feb67ec896c5a1e946ba0a60266c6d89e41c Mon Sep 17 00:00:00 2001 From: Tyler Kvochick Date: Tue, 25 Jun 2024 22:53:36 -0400 Subject: [PATCH 04/15] Add pipelines for testing dotnet tool locally --- build.fsx | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/build.fsx b/build.fsx index 6706d59d..4cc9f31e 100644 --- a/build.fsx +++ b/build.fsx @@ -50,6 +50,20 @@ let testStage = $"dotnet test {solutionFile} --configuration {configuration} --no-build --blame --logger trx --results-directory TestResults -tl" } +let nugetStage = + stage "NuGet" { run $"dotnet pack {solutionFile} --output \"{artifactsDir}\" --configuration {configuration} -tl" } + +let installToolStage = + stage "InstallFsDocsTool" { + run + $"dotnet tool install --no-cache --version %A{releaseNugetVersion} --add-source \"%s{artifactsDir}\" --tool-path \"%s{artifactsDir}\" fsdocs-tool" + + run $"\"{fsdocTool}\" build --strict --clean --properties Configuration=Release" + } + +let uninstallToolStage = + stage "UninstallFsDocsTool" { run $"dotnet tool uninstall fsdocs-tool --tool-path \"%s{artifactsDir}\"" } + pipeline "CI" { lintStage @@ -65,7 +79,7 @@ pipeline "CI" { run $"dotnet build {solutionFile} --configuration {configuration} -tl" } - stage "NuGet" { run $"dotnet pack {solutionFile} --output \"{artifactsDir}\" --configuration {configuration} -tl" } + nugetStage testStage @@ -75,11 +89,8 @@ pipeline "CI" { Shell.cleanDir ".packages") // Τhe tool has been uninstalled when the // artifacts folder was removed in the Clean stage. - run - $"dotnet tool install --no-cache --version %A{releaseNugetVersion} --add-source \"%s{artifactsDir}\" --tool-path \"%s{artifactsDir}\" fsdocs-tool" - - run $"\"{fsdocTool}\" build --strict --clean --properties Configuration=Release" - run $"dotnet tool uninstall fsdocs-tool --tool-path \"%s{artifactsDir}\"" + installToolStage + uninstallToolStage run (fun _ -> Shell.cleanDir ".packages") } @@ -93,4 +104,15 @@ pipeline "Verify" { runIfOnlySpecified true } +pipeline "InstallTool" { + nugetStage + installToolStage + runIfOnlySpecified true +} + +pipeline "UninstallTool" { + uninstallToolStage + runIfOnlySpecified true +} + tryPrintPipelineCommandHelp () From 6e6732622e9375a16e843ba853b8d42536f77621 Mon Sep 17 00:00:00 2001 From: Tyler Kvochick Date: Tue, 25 Jun 2024 23:23:24 -0400 Subject: [PATCH 05/15] Separate tool install and tool run --- build.fsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/build.fsx b/build.fsx index 4cc9f31e..89a0cac2 100644 --- a/build.fsx +++ b/build.fsx @@ -55,10 +55,12 @@ let nugetStage = let installToolStage = stage "InstallFsDocsTool" { + noStdRedirectForStep + run $"dotnet tool install --no-cache --version %A{releaseNugetVersion} --add-source \"%s{artifactsDir}\" --tool-path \"%s{artifactsDir}\" fsdocs-tool" - run $"\"{fsdocTool}\" build --strict --clean --properties Configuration=Release" + echo $"The development version of fsdocs can be invoked from:{System.Environment.NewLine}%s{fsdocTool}" } let uninstallToolStage = @@ -90,6 +92,7 @@ pipeline "CI" { // Τhe tool has been uninstalled when the // artifacts folder was removed in the Clean stage. installToolStage + run $"\"{fsdocTool}\" build --strict --clean --properties Configuration=Release" uninstallToolStage run (fun _ -> Shell.cleanDir ".packages") } From f9ac119c490d9134958afac9e8b93aeabe2475e8 Mon Sep 17 00:00:00 2001 From: Tyler Kvochick Date: Wed, 26 Jun 2024 10:31:08 -0400 Subject: [PATCH 06/15] Revert build script changes --- build.fsx | 35 +++++------------------------------ 1 file changed, 5 insertions(+), 30 deletions(-) diff --git a/build.fsx b/build.fsx index 89a0cac2..6706d59d 100644 --- a/build.fsx +++ b/build.fsx @@ -50,22 +50,6 @@ let testStage = $"dotnet test {solutionFile} --configuration {configuration} --no-build --blame --logger trx --results-directory TestResults -tl" } -let nugetStage = - stage "NuGet" { run $"dotnet pack {solutionFile} --output \"{artifactsDir}\" --configuration {configuration} -tl" } - -let installToolStage = - stage "InstallFsDocsTool" { - noStdRedirectForStep - - run - $"dotnet tool install --no-cache --version %A{releaseNugetVersion} --add-source \"%s{artifactsDir}\" --tool-path \"%s{artifactsDir}\" fsdocs-tool" - - echo $"The development version of fsdocs can be invoked from:{System.Environment.NewLine}%s{fsdocTool}" - } - -let uninstallToolStage = - stage "UninstallFsDocsTool" { run $"dotnet tool uninstall fsdocs-tool --tool-path \"%s{artifactsDir}\"" } - pipeline "CI" { lintStage @@ -81,7 +65,7 @@ pipeline "CI" { run $"dotnet build {solutionFile} --configuration {configuration} -tl" } - nugetStage + stage "NuGet" { run $"dotnet pack {solutionFile} --output \"{artifactsDir}\" --configuration {configuration} -tl" } testStage @@ -91,9 +75,11 @@ pipeline "CI" { Shell.cleanDir ".packages") // Τhe tool has been uninstalled when the // artifacts folder was removed in the Clean stage. - installToolStage + run + $"dotnet tool install --no-cache --version %A{releaseNugetVersion} --add-source \"%s{artifactsDir}\" --tool-path \"%s{artifactsDir}\" fsdocs-tool" + run $"\"{fsdocTool}\" build --strict --clean --properties Configuration=Release" - uninstallToolStage + run $"dotnet tool uninstall fsdocs-tool --tool-path \"%s{artifactsDir}\"" run (fun _ -> Shell.cleanDir ".packages") } @@ -107,15 +93,4 @@ pipeline "Verify" { runIfOnlySpecified true } -pipeline "InstallTool" { - nugetStage - installToolStage - runIfOnlySpecified true -} - -pipeline "UninstallTool" { - uninstallToolStage - runIfOnlySpecified true -} - tryPrintPipelineCommandHelp () From aa0ea071f1cbc88be5e2efd5b73ed737cfd662be Mon Sep 17 00:00:00 2001 From: Tyler Kvochick Date: Wed, 26 Jun 2024 10:40:56 -0400 Subject: [PATCH 07/15] Revert watch override removal --- src/fsdocs-tool/BuildCommand.fs | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/fsdocs-tool/BuildCommand.fs b/src/fsdocs-tool/BuildCommand.fs index 0f751329..e00d4837 100644 --- a/src/fsdocs-tool/BuildCommand.fs +++ b/src/fsdocs-tool/BuildCommand.fs @@ -1403,10 +1403,26 @@ type CoreBuildOptions(watch) = let userParametersDict = readOnlyDict userParameters - let userRoot = - match userParametersDict.TryGetValue(ParamKeys.root) with - | true, v -> Some v - | _ -> None + // Adjust the user substitutions for 'watch' mode root + let userRoot, userParameters = + if watch then + let userRoot = sprintf "http://localhost:%d/" this.port_option + + if userParametersDict.ContainsKey(ParamKeys.root) then + printfn "ignoring user-specified root since in watch mode, root = %s" userRoot + + let userParameters = + [ ParamKeys.root, userRoot ] + @ (userParameters |> List.filter (fun (a, _) -> a <> ParamKeys.root)) + + Some userRoot, userParameters + else + let r = + match userParametersDict.TryGetValue(ParamKeys.root) with + | true, v -> Some v + | _ -> None + + r, userParameters let userCollectionName = match (dict userParameters).TryGetValue(ParamKeys.``fsdocs-collection-name``) with From 0dcda558b3b9e548ae2c630de8d22e499d5abf79 Mon Sep 17 00:00:00 2001 From: Tyler Kvochick Date: Wed, 26 Jun 2024 11:08:52 -0400 Subject: [PATCH 08/15] Add relative content option --- src/fsdocs-tool/BuildCommand.fs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/fsdocs-tool/BuildCommand.fs b/src/fsdocs-tool/BuildCommand.fs index e00d4837..98e36e8a 100644 --- a/src/fsdocs-tool/BuildCommand.fs +++ b/src/fsdocs-tool/BuildCommand.fs @@ -2088,6 +2088,9 @@ type CoreBuildOptions(watch) = abstract port_option: int default x.port_option = 0 + abstract relative_content_option: bool + default x.relative_content_option = false + [] type BuildCommand() = inherit CoreBuildOptions(false) @@ -2115,3 +2118,11 @@ type WatchCommand() = [] member val port = 8901 with get, set + + [] + member val relativecontent = false + + override x.relative_content_option = x.relativecontent From 61ed808c257bbdd3b0cb00c3ae098e4f26b5996d Mon Sep 17 00:00:00 2001 From: Tyler Kvochick Date: Wed, 26 Jun 2024 11:18:17 -0400 Subject: [PATCH 09/15] Fix relativecontent option --- src/fsdocs-tool/BuildCommand.fs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fsdocs-tool/BuildCommand.fs b/src/fsdocs-tool/BuildCommand.fs index 98e36e8a..e86b4622 100644 --- a/src/fsdocs-tool/BuildCommand.fs +++ b/src/fsdocs-tool/BuildCommand.fs @@ -2122,7 +2122,7 @@ type WatchCommand() = [] - member val relativecontent = false + HelpText = "Use relative links in static content paths.")>] + member val relativecontent = false with get, set override x.relative_content_option = x.relativecontent From 2df3a2c097aae2f74b9a6d41c719ed3939aa02f3 Mon Sep 17 00:00:00 2001 From: Tyler Kvochick Date: Wed, 26 Jun 2024 11:19:31 -0400 Subject: [PATCH 10/15] Set userRoot with relative_content_option --- src/fsdocs-tool/BuildCommand.fs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/fsdocs-tool/BuildCommand.fs b/src/fsdocs-tool/BuildCommand.fs index e86b4622..d7880d8c 100644 --- a/src/fsdocs-tool/BuildCommand.fs +++ b/src/fsdocs-tool/BuildCommand.fs @@ -1406,10 +1406,13 @@ type CoreBuildOptions(watch) = // Adjust the user substitutions for 'watch' mode root let userRoot, userParameters = if watch then - let userRoot = sprintf "http://localhost:%d/" this.port_option + let userRoot = + match this.relative_content_option with + | true -> "" + | _ -> sprintf "http://localhost:%d/" this.port_option if userParametersDict.ContainsKey(ParamKeys.root) then - printfn "ignoring user-specified root since in watch mode, root = %s" userRoot + printfn "ignoring user-specified root since in watch mode, root = '%s'" userRoot let userParameters = [ ParamKeys.root, userRoot ] From f1fd7b399c2586f8d8b9beb6e0d3a57ce9e7109f Mon Sep 17 00:00:00 2001 From: Tyler Kvochick Date: Wed, 26 Jun 2024 11:51:04 -0400 Subject: [PATCH 11/15] Use browser window location in websocket watch script --- src/fsdocs-tool/BuildCommand.fs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/fsdocs-tool/BuildCommand.fs b/src/fsdocs-tool/BuildCommand.fs index d7880d8c..7897f7ed 100644 --- a/src/fsdocs-tool/BuildCommand.fs +++ b/src/fsdocs-tool/BuildCommand.fs @@ -792,11 +792,11 @@ module Serve = let refreshEvent = FSharp.Control.Event() /// generate the script to inject into html to enable hot reload during development - let generateWatchScript (port: int) = - let tag = - """ + let generateWatchScript = + """ """ - tag.Replace("{{PORT}}", string port) - let connectedClients = ConcurrentDictionary() let socketHandler (webSocket: WebSocket) (context: HttpContext) = @@ -1670,7 +1668,7 @@ type CoreBuildOptions(watch) = let getLatestWatchScript () = if watch then // if running in watch mode, inject hot reload script - [ ParamKeys.``fsdocs-watch-script``, Serve.generateWatchScript this.port_option ] + [ ParamKeys.``fsdocs-watch-script``, Serve.generateWatchScript ] else // otherwise, inject empty replacement string [ ParamKeys.``fsdocs-watch-script``, "" ] From 6a313abca782bc01de96bdaf985ba092a4b5e769 Mon Sep 17 00:00:00 2001 From: Tyler Kvochick Date: Wed, 26 Jun 2024 12:13:29 -0400 Subject: [PATCH 12/15] Use string host option flag --- src/fsdocs-tool/BuildCommand.fs | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/fsdocs-tool/BuildCommand.fs b/src/fsdocs-tool/BuildCommand.fs index 7897f7ed..48d9c716 100644 --- a/src/fsdocs-tool/BuildCommand.fs +++ b/src/fsdocs-tool/BuildCommand.fs @@ -1405,8 +1405,8 @@ type CoreBuildOptions(watch) = let userRoot, userParameters = if watch then let userRoot = - match this.relative_content_option with - | true -> "" + match this.static_content_host_option with + | Some s -> s | _ -> sprintf "http://localhost:%d/" this.port_option if userParametersDict.ContainsKey(ParamKeys.root) then @@ -2089,8 +2089,8 @@ type CoreBuildOptions(watch) = abstract port_option: int default x.port_option = 0 - abstract relative_content_option: bool - default x.relative_content_option = false + abstract static_content_host_option: string option + default x.static_content_host_option = None [] type BuildCommand() = @@ -2120,10 +2120,12 @@ type WatchCommand() = [] member val port = 8901 with get, set - [] - member val relativecontent = false with get, set + [] + member val contenthost = "" with get, set - override x.relative_content_option = x.relativecontent + override x.static_content_host_option = + match x.contenthost with + | "" -> None + | s -> + if not (s.EndsWith("/")) then $"%s{s}/" else s + |> Some From d2e196cd6979a05019409416364f951414f07129 Mon Sep 17 00:00:00 2001 From: Tyler Kvochick Date: Fri, 28 Jun 2024 10:22:36 -0400 Subject: [PATCH 13/15] Update flag name and help text --- src/fsdocs-tool/BuildCommand.fs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/fsdocs-tool/BuildCommand.fs b/src/fsdocs-tool/BuildCommand.fs index 48d9c716..1e9656c4 100644 --- a/src/fsdocs-tool/BuildCommand.fs +++ b/src/fsdocs-tool/BuildCommand.fs @@ -2120,11 +2120,14 @@ type WatchCommand() = [] member val port = 8901 with get, set - [] - member val contenthost = "" with get, set + [[:]/' to use in static content for browsers not running on localhost.")>] + member val contenturlroot = "" with get, set override x.static_content_host_option = - match x.contenthost with + match x.contenturlroot with | "" -> None | s -> if not (s.EndsWith("/")) then $"%s{s}/" else s From 4700b62d5d8a566dd7b0f9c7457c6097c58ce22f Mon Sep 17 00:00:00 2001 From: Tyler Kvochick Date: Fri, 28 Jun 2024 10:37:33 -0400 Subject: [PATCH 14/15] Use System.Uri for parsing --- src/fsdocs-tool/BuildCommand.fs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/fsdocs-tool/BuildCommand.fs b/src/fsdocs-tool/BuildCommand.fs index 1e9656c4..2ea122db 100644 --- a/src/fsdocs-tool/BuildCommand.fs +++ b/src/fsdocs-tool/BuildCommand.fs @@ -1406,7 +1406,7 @@ type CoreBuildOptions(watch) = if watch then let userRoot = match this.static_content_host_option with - | Some s -> s + | Some s -> sprintf "%O" s | _ -> sprintf "http://localhost:%d/" this.port_option if userParametersDict.ContainsKey(ParamKeys.root) then @@ -2089,7 +2089,7 @@ type CoreBuildOptions(watch) = abstract port_option: int default x.port_option = 0 - abstract static_content_host_option: string option + abstract static_content_host_option: Uri option default x.static_content_host_option = None [] @@ -2127,8 +2127,7 @@ type WatchCommand() = member val contenturlroot = "" with get, set override x.static_content_host_option = - match x.contenturlroot with - | "" -> None - | s -> - if not (s.EndsWith("/")) then $"%s{s}/" else s - |> Some + if not (String.IsNullOrEmpty x.contenturlroot) then + x.contenturlroot |> Uri |> Some + else + None From 86296aa96293da10f38380b9274754a32c3e1ffd Mon Sep 17 00:00:00 2001 From: Tyler Kvochick Date: Fri, 28 Jun 2024 10:37:57 -0400 Subject: [PATCH 15/15] Remove / --- src/fsdocs-tool/BuildCommand.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fsdocs-tool/BuildCommand.fs b/src/fsdocs-tool/BuildCommand.fs index 2ea122db..a903caa4 100644 --- a/src/fsdocs-tool/BuildCommand.fs +++ b/src/fsdocs-tool/BuildCommand.fs @@ -2123,7 +2123,7 @@ type WatchCommand() = [[:]/' to use in static content for browsers not running on localhost.")>] + "Optional URL root 'http[s]://[:]' to use in static content for browsers not running on localhost.")>] member val contenturlroot = "" with get, set override x.static_content_host_option =