Skip to content

Commit 3b00528

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

File tree

2 files changed

+52
-45
lines changed

2 files changed

+52
-45
lines changed

src/fsdocs-tool/BuildCommand.fs

Lines changed: 18 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,27 +1455,13 @@ 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
1465-
else if
1466-
(try
1467-
File.Exists(defaultTemplateAttempt1)
1468-
with _ ->
1469-
false)
1470-
then
1471-
Some defaultTemplateAttempt1
1472-
elif
1473-
(try
1474-
File.Exists(defaultTemplateAttempt2)
1475-
with _ ->
1476-
false)
1477-
then
1478-
Some defaultTemplateAttempt2
1461+
else if inPackageLocations.Exist() then
1462+
Some inPackageLocations.template_html
1463+
elif inRepoLocations.Exist() then
1464+
Some inRepoLocations.template_html
14791465
else
14801466
None
14811467

@@ -1484,32 +1470,22 @@ type CoreBuildOptions(watch) =
14841470
// The "extras" content goes in "."
14851471
// From .nuget\packages\fsdocs-tool\7.1.7\tools\net6.0\any
14861472
// 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)
1494-
then
1495-
printfn "using extra content from %s" attempt1
1496-
(attempt1, ".")
1497-
else
1473+
if inPackageLocations.Exist() then
1474+
printfn "using extra content from %s" inPackageLocations.extras
1475+
(inPackageLocations.extras, ".")
1476+
else if
14981477
// This is for in-repo use only, assuming we are executing directly from
14991478
// src\fsdocs-tool\bin\Debug\net6.0\fsdocs.exe
15001479
// src\fsdocs-tool\bin\Release\net6.0\fsdocs.exe
1501-
let attempt2 = inRepoLocations.docs_content
1502-
1503-
if
1504-
(try
1505-
Directory.Exists(attempt2)
1506-
with _ ->
1507-
false)
1508-
then
1509-
printfn "using extra content from %s" attempt2
1510-
(attempt2, "content")
1511-
else
1512-
printfn "no extra content found at %s or %s" attempt1 attempt2 ]
1480+
inRepoLocations.Exist()
1481+
then
1482+
printfn "using extra content from %s" inRepoLocations.docs_content
1483+
(inRepoLocations.docs_content, "content")
1484+
else
1485+
printfn
1486+
"no extra content found at %s or %s"
1487+
inPackageLocations.extras
1488+
inRepoLocations.docs_content ]
15131489

15141490
// The incremental state (as well as the files written to disk)
15151491
let mutable latestApiDocModel = None
@@ -1573,7 +1549,7 @@ type CoreBuildOptions(watch) =
15731549
printfn
15741550
"note, no template file '%s' found, and no default template at '%s'"
15751551
templateFiles
1576-
defaultTemplateAttempt1
1552+
inRepoLocations.template_html
15771553

15781554
OutputKind.Html, None
15791555

src/fsdocs-tool/Options.fs

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,10 @@ module Common =
5858
type InRepoLocations(relAssemblyPath) =
5959

6060
// relAssemblyPath : relative path from assemly to repo root path
61+
member _.RelAssemblyPath = relAssemblyPath
6162

6263
// default folder locations relative to the assembly path
63-
member _.docs = Path.Combine(relAssemblyPath, "docs") |> Path.GetFullPath
64+
member this.docs = Path.Combine(this.RelAssemblyPath, "docs") |> Path.GetFullPath
6465
member this.docs_content = Path.Combine(this.docs, "content") |> Path.GetFullPath
6566
member this.docs_content_image = Path.Combine(this.docs_content, "img") |> Path.GetFullPath
6667

@@ -69,6 +70,20 @@ module Common =
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.Exist() =
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 _ ->
85+
false
86+
7287
/// <summary>
7388
/// a set of default locations in the nuget package created for fsdocs-tool.
7489
/// these files are to be used in 2 scenarios assuming the tool is invoked via cli:
@@ -82,17 +97,33 @@ module Common =
8297
type InPackageLocations(relAssemblyPath) =
8398

8499
// relAssemblyPath : relative path from assemly to package root path
100+
member _.RelAssemblyPath = relAssemblyPath
85101

86102
// From .nuget\packages\fsdocs-tool\7.1.7\tools\net6.0\any
87103
// to .nuget\packages\fsdocs-tool\7.1.7\*
88104

89105
// default folder locations relative to the assembly path
90-
member _.templates = Path.Combine(relAssemblyPath, "templates") |> Path.GetFullPath
91-
member _.extras = Path.Combine(relAssemblyPath, "extras") |> Path.GetFullPath
106+
member this.templates = Path.Combine(this.RelAssemblyPath, "templates") |> Path.GetFullPath
107+
member this.extras = Path.Combine(this.RelAssemblyPath, "extras") |> Path.GetFullPath
92108
member this.extras_content = Path.Combine(this.extras, "content") |> Path.GetFullPath
93109
member this.extras_content_img = Path.Combine(this.extras_content, "img") |> Path.GetFullPath
94110

95111
// specific files in this folder structure that might need special treatment instead of just copy pasting
96112
member this.template_html = Path.Combine(this.templates, "_template.html") |> Path.GetFullPath
97113
member this.template_ipynb = Path.Combine(this.templates, "_template.ipynb") |> Path.GetFullPath
98114
member this.template_tex = Path.Combine(this.templates, "_template.tex") |> Path.GetFullPath
115+
116+
/// <summary>
117+
/// returns true if all special files and folders of this location exist.
118+
/// </summary>
119+
member this.Exist() =
120+
try
121+
Directory.Exists(this.templates)
122+
&& Directory.Exists(this.extras)
123+
&& Directory.Exists(this.extras_content)
124+
&& Directory.Exists(this.extras_content_img)
125+
&& File.Exists(this.template_html)
126+
&& File.Exists(this.template_ipynb)
127+
&& File.Exists(this.template_tex)
128+
with _ ->
129+
false

0 commit comments

Comments
 (0)