Skip to content

Commit 9820686

Browse files
committed
Further refactoring of build command using new locations
1 parent c3068a6 commit 9820686

File tree

2 files changed

+40
-33
lines changed

2 files changed

+40
-33
lines changed

src/fsdocs-tool/BuildCommand.fs

+12-33
Original file line numberDiff line numberDiff line change
@@ -1455,27 +1455,17 @@ type CoreBuildOptions(watch) =
14551455
let inPackageLocations = Common.InPackageLocations(Path.Combine(dir, "..", "..", ".."))
14561456
let inRepoLocations = Common.InRepoLocations(Path.Combine(dir, "..", "..", "..", "..", ".."))
14571457

1458-
let defaultTemplateAttempt1 = inPackageLocations.template_html
1459-
// This is in-repo only
1460-
let defaultTemplateAttempt2 = inRepoLocations.template_html
1461-
14621458
let defaultTemplate =
14631459
if this.nodefaultcontent then
14641460
None
14651461
else if
1466-
(try
1467-
File.Exists(defaultTemplateAttempt1)
1468-
with _ ->
1469-
false)
1462+
inPackageLocations.Exists()
14701463
then
1471-
Some defaultTemplateAttempt1
1464+
Some inPackageLocations.template_html
14721465
elif
1473-
(try
1474-
File.Exists(defaultTemplateAttempt2)
1475-
with _ ->
1476-
false)
1466+
inRepoLocations.Exists()
14771467
then
1478-
Some defaultTemplateAttempt2
1468+
Some inRepoLocations.template_html
14791469
else
14801470
None
14811471

@@ -1484,32 +1474,21 @@ type CoreBuildOptions(watch) =
14841474
// The "extras" content goes in "."
14851475
// From .nuget\packages\fsdocs-tool\7.1.7\tools\net6.0\any
14861476
// to .nuget\packages\fsdocs-tool\7.1.7\extras
1487-
let attempt1 = inPackageLocations.extras
1488-
1489-
if
1490-
(try
1491-
Directory.Exists(attempt1)
1492-
with _ ->
1493-
false)
1477+
if inPackageLocations.Exists()
14941478
then
1495-
printfn "using extra content from %s" attempt1
1496-
(attempt1, ".")
1479+
printfn "using extra content from %s" inPackageLocations.extras
1480+
(inPackageLocations.extras, ".")
14971481
else
14981482
// This is for in-repo use only, assuming we are executing directly from
14991483
// src\fsdocs-tool\bin\Debug\net6.0\fsdocs.exe
15001484
// src\fsdocs-tool\bin\Release\net6.0\fsdocs.exe
1501-
let attempt2 = inRepoLocations.docs_content
1502-
15031485
if
1504-
(try
1505-
Directory.Exists(attempt2)
1506-
with _ ->
1507-
false)
1486+
inRepoLocations.Exists()
15081487
then
1509-
printfn "using extra content from %s" attempt2
1510-
(attempt2, "content")
1488+
printfn "using extra content from %s" inRepoLocations.docs_content
1489+
(inRepoLocations.docs_content, "content")
15111490
else
1512-
printfn "no extra content found at %s or %s" attempt1 attempt2 ]
1491+
printfn "no extra content found at %s or %s" inPackageLocations.extras inRepoLocations.docs_content ]
15131492

15141493
// The incremental state (as well as the files written to disk)
15151494
let mutable latestApiDocModel = None
@@ -1573,7 +1552,7 @@ type CoreBuildOptions(watch) =
15731552
printfn
15741553
"note, no template file '%s' found, and no default template at '%s'"
15751554
templateFiles
1576-
defaultTemplateAttempt1
1555+
inRepoLocations.template_html
15771556

15781557
OutputKind.Html, None
15791558

src/fsdocs-tool/Options.fs

+28
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,25 @@ module Common =
6464
member this.docs_content = Path.Combine(this.docs, "content") |> Path.GetFullPath
6565
member this.docs_content_image = Path.Combine(this.docs_content, "img") |> Path.GetFullPath
6666

67+
6768
// specific files in this folder structure that might need special treatment instead of just copy pasting
6869
member this.template_html = Path.Combine(this.docs, "_template.html") |> Path.GetFullPath
6970
member this.template_ipynb = Path.Combine(this.docs, "_template.ipynb") |> Path.GetFullPath
7071
member this.template_tex = Path.Combine(this.docs, "_template.tex") |> Path.GetFullPath
7172

73+
/// <summary>
74+
/// returns true if all special files and folders of this location exist.
75+
/// </summary>
76+
member this.Exists() =
77+
try
78+
Directory.Exists(this.docs) &&
79+
Directory.Exists(this.docs_content) &&
80+
Directory.Exists(this.docs_content_image) &&
81+
File.Exists(this.template_html) &&
82+
File.Exists(this.template_ipynb) &&
83+
File.Exists(this.template_tex)
84+
with _ -> false
85+
7286
/// <summary>
7387
/// a set of default locations in the nuget package created for fsdocs-tool.
7488
/// these files are to be used in 2 scenarios assuming the tool is invoked via cli:
@@ -96,3 +110,17 @@ module Common =
96110
member this.template_html = Path.Combine(this.templates, "_template.html") |> Path.GetFullPath
97111
member this.template_ipynb = Path.Combine(this.templates, "_template.ipynb") |> Path.GetFullPath
98112
member this.template_tex = Path.Combine(this.templates, "_template.tex") |> Path.GetFullPath
113+
114+
/// <summary>
115+
/// returns true if all special files and folders of this location exist.
116+
/// </summary>
117+
member this.Exists() =
118+
try
119+
Directory.Exists(this.templates) &&
120+
Directory.Exists(this.extras) &&
121+
Directory.Exists(this.extras_content) &&
122+
Directory.Exists(this.extras_content_img) &&
123+
File.Exists(this.template_html) &&
124+
File.Exists(this.template_ipynb) &&
125+
File.Exists(this.template_tex)
126+
with _ -> false

0 commit comments

Comments
 (0)