Skip to content

Commit

Permalink
Further refactoring of build command using new locations
Browse files Browse the repository at this point in the history
  • Loading branch information
kMutagene committed Nov 18, 2023
1 parent c3068a6 commit 9820686
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 33 deletions.
45 changes: 12 additions & 33 deletions src/fsdocs-tool/BuildCommand.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down
28 changes: 28 additions & 0 deletions src/fsdocs-tool/Options.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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

/// <summary>
/// returns true if all special files and folders of this location exist.
/// </summary>
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

/// <summary>
/// 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:
Expand Down Expand Up @@ -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

/// <summary>
/// returns true if all special files and folders of this location exist.
/// </summary>
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

0 comments on commit 9820686

Please sign in to comment.