From 98206860966ffce95d97e794f7df192744aa32ce Mon Sep 17 00:00:00 2001 From: Kevin Schneider Date: Sat, 18 Nov 2023 14:09:06 +0100 Subject: [PATCH] Further refactoring of build command using new locations --- src/fsdocs-tool/BuildCommand.fs | 45 +++++++++------------------------ src/fsdocs-tool/Options.fs | 28 ++++++++++++++++++++ 2 files changed, 40 insertions(+), 33 deletions(-) diff --git a/src/fsdocs-tool/BuildCommand.fs b/src/fsdocs-tool/BuildCommand.fs index 61ab1b5f7..961b7d49d 100644 --- a/src/fsdocs-tool/BuildCommand.fs +++ b/src/fsdocs-tool/BuildCommand.fs @@ -1455,27 +1455,17 @@ type CoreBuildOptions(watch) = let inPackageLocations = Common.InPackageLocations(Path.Combine(dir, "..", "..", "..")) let inRepoLocations = Common.InRepoLocations(Path.Combine(dir, "..", "..", "..", "..", "..")) - let defaultTemplateAttempt1 = inPackageLocations.template_html - // This is in-repo only - let defaultTemplateAttempt2 = inRepoLocations.template_html - let defaultTemplate = if this.nodefaultcontent then None else if - (try - File.Exists(defaultTemplateAttempt1) - with _ -> - false) + inPackageLocations.Exists() then - Some defaultTemplateAttempt1 + Some inPackageLocations.template_html elif - (try - File.Exists(defaultTemplateAttempt2) - with _ -> - false) + inRepoLocations.Exists() then - Some defaultTemplateAttempt2 + Some inRepoLocations.template_html else None @@ -1484,32 +1474,21 @@ type CoreBuildOptions(watch) = // The "extras" content goes in "." // From .nuget\packages\fsdocs-tool\7.1.7\tools\net6.0\any // to .nuget\packages\fsdocs-tool\7.1.7\extras - let attempt1 = inPackageLocations.extras - - if - (try - Directory.Exists(attempt1) - with _ -> - false) + if inPackageLocations.Exists() then - printfn "using extra content from %s" attempt1 - (attempt1, ".") + printfn "using extra content from %s" inPackageLocations.extras + (inPackageLocations.extras, ".") else // This is for in-repo use only, assuming we are executing directly from // src\fsdocs-tool\bin\Debug\net6.0\fsdocs.exe // src\fsdocs-tool\bin\Release\net6.0\fsdocs.exe - let attempt2 = inRepoLocations.docs_content - if - (try - Directory.Exists(attempt2) - with _ -> - false) + inRepoLocations.Exists() then - printfn "using extra content from %s" attempt2 - (attempt2, "content") + printfn "using extra content from %s" inRepoLocations.docs_content + (inRepoLocations.docs_content, "content") else - printfn "no extra content found at %s or %s" attempt1 attempt2 ] + printfn "no extra content found at %s or %s" inPackageLocations.extras inRepoLocations.docs_content ] // The incremental state (as well as the files written to disk) let mutable latestApiDocModel = None @@ -1573,7 +1552,7 @@ type CoreBuildOptions(watch) = printfn "note, no template file '%s' found, and no default template at '%s'" templateFiles - defaultTemplateAttempt1 + inRepoLocations.template_html OutputKind.Html, None diff --git a/src/fsdocs-tool/Options.fs b/src/fsdocs-tool/Options.fs index 077d6fc96..93721cb6d 100644 --- a/src/fsdocs-tool/Options.fs +++ b/src/fsdocs-tool/Options.fs @@ -64,11 +64,25 @@ module Common = member this.docs_content = Path.Combine(this.docs, "content") |> Path.GetFullPath member this.docs_content_image = Path.Combine(this.docs_content, "img") |> Path.GetFullPath + // specific files in this folder structure that might need special treatment instead of just copy pasting member this.template_html = Path.Combine(this.docs, "_template.html") |> Path.GetFullPath member this.template_ipynb = Path.Combine(this.docs, "_template.ipynb") |> Path.GetFullPath member this.template_tex = Path.Combine(this.docs, "_template.tex") |> Path.GetFullPath + /// + /// returns true if all special files and folders of this location exist. + /// + member this.Exists() = + try + Directory.Exists(this.docs) && + Directory.Exists(this.docs_content) && + Directory.Exists(this.docs_content_image) && + File.Exists(this.template_html) && + File.Exists(this.template_ipynb) && + File.Exists(this.template_tex) + with _ -> false + /// /// a set of default locations in the nuget package created for fsdocs-tool. /// these files are to be used in 2 scenarios assuming the tool is invoked via cli: @@ -96,3 +110,17 @@ module Common = member this.template_html = Path.Combine(this.templates, "_template.html") |> Path.GetFullPath member this.template_ipynb = Path.Combine(this.templates, "_template.ipynb") |> Path.GetFullPath member this.template_tex = Path.Combine(this.templates, "_template.tex") |> Path.GetFullPath + + /// + /// returns true if all special files and folders of this location exist. + /// + member this.Exists() = + try + Directory.Exists(this.templates) && + Directory.Exists(this.extras) && + Directory.Exists(this.extras_content) && + Directory.Exists(this.extras_content_img) && + File.Exists(this.template_html) && + File.Exists(this.template_ipynb) && + File.Exists(this.template_tex) + with _ -> false \ No newline at end of file