diff --git a/src/fsdocs-tool/BuildCommand.fs b/src/fsdocs-tool/BuildCommand.fs
index 61ab1b5f7..9920ad846 100644
--- a/src/fsdocs-tool/BuildCommand.fs
+++ b/src/fsdocs-tool/BuildCommand.fs
@@ -1455,27 +1455,13 @@ 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)
- then
- Some defaultTemplateAttempt1
- elif
- (try
- File.Exists(defaultTemplateAttempt2)
- with _ ->
- false)
- then
- Some defaultTemplateAttempt2
+ else if inPackageLocations.Exist() then
+ Some inPackageLocations.template_html
+ elif inRepoLocations.Exist() then
+ Some inRepoLocations.template_html
else
None
@@ -1484,32 +1470,22 @@ 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)
- then
- printfn "using extra content from %s" attempt1
- (attempt1, ".")
- else
+ if inPackageLocations.Exist() then
+ printfn "using extra content from %s" inPackageLocations.extras
+ (inPackageLocations.extras, ".")
+ else if
// 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)
- then
- printfn "using extra content from %s" attempt2
- (attempt2, "content")
- else
- printfn "no extra content found at %s or %s" attempt1 attempt2 ]
+ inRepoLocations.Exist()
+ then
+ printfn "using extra content from %s" inRepoLocations.docs_content
+ (inRepoLocations.docs_content, "content")
+ else
+ 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 +1549,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..80630b66c 100644
--- a/src/fsdocs-tool/Options.fs
+++ b/src/fsdocs-tool/Options.fs
@@ -58,9 +58,10 @@ module Common =
type InRepoLocations(relAssemblyPath) =
// relAssemblyPath : relative path from assemly to repo root path
+ member _.RelAssemblyPath = relAssemblyPath
// default folder locations relative to the assembly path
- member _.docs = Path.Combine(relAssemblyPath, "docs") |> Path.GetFullPath
+ member this.docs = Path.Combine(this.RelAssemblyPath, "docs") |> Path.GetFullPath
member this.docs_content = Path.Combine(this.docs, "content") |> Path.GetFullPath
member this.docs_content_image = Path.Combine(this.docs_content, "img") |> Path.GetFullPath
@@ -69,6 +70,20 @@ module Common =
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.Exist() =
+ 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:
@@ -82,13 +97,14 @@ module Common =
type InPackageLocations(relAssemblyPath) =
// relAssemblyPath : relative path from assemly to package root path
+ member _.RelAssemblyPath = relAssemblyPath
// From .nuget\packages\fsdocs-tool\7.1.7\tools\net6.0\any
// to .nuget\packages\fsdocs-tool\7.1.7\*
// default folder locations relative to the assembly path
- member _.templates = Path.Combine(relAssemblyPath, "templates") |> Path.GetFullPath
- member _.extras = Path.Combine(relAssemblyPath, "extras") |> Path.GetFullPath
+ member this.templates = Path.Combine(this.RelAssemblyPath, "templates") |> Path.GetFullPath
+ member this.extras = Path.Combine(this.RelAssemblyPath, "extras") |> Path.GetFullPath
member this.extras_content = Path.Combine(this.extras, "content") |> Path.GetFullPath
member this.extras_content_img = Path.Combine(this.extras_content, "img") |> Path.GetFullPath
@@ -96,3 +112,18 @@ 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.Exist() =
+ 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