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 3b00528
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 45 deletions.
60 changes: 18 additions & 42 deletions src/fsdocs-tool/BuildCommand.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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

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

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

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

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

/// <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 All @@ -82,17 +97,33 @@ 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

// specific files in this folder structure that might need special treatment instead of just copy pasting
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.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

0 comments on commit 3b00528

Please sign in to comment.