Skip to content

Commit c3068a6

Browse files
committed
add attempt to make in-repo and in-package locations reusable across commands
1 parent 7707ea0 commit c3068a6

File tree

4 files changed

+76
-7
lines changed

4 files changed

+76
-7
lines changed

src/fsdocs-tool/BuildCommand.fs

+8-7
Original file line numberDiff line numberDiff line change
@@ -1451,11 +1451,13 @@ type CoreBuildOptions(watch) =
14511451
// to .nuget\packages\fsdocs-tool\7.1.7\templates
14521452
let dir = Path.GetDirectoryName(typeof<CoreBuildOptions>.Assembly.Location)
14531453

1454-
let defaultTemplateAttempt1 =
1455-
Path.GetFullPath(Path.Combine(dir, "..", "..", "..", "templates", "_template.html"))
1454+
// get template locations for in-package and in-repo and decide which to use later
1455+
let inPackageLocations = Common.InPackageLocations(Path.Combine(dir, "..", "..", ".."))
1456+
let inRepoLocations = Common.InRepoLocations(Path.Combine(dir, "..", "..", "..", "..", ".."))
1457+
1458+
let defaultTemplateAttempt1 = inPackageLocations.template_html
14561459
// This is in-repo only
1457-
let defaultTemplateAttempt2 =
1458-
Path.GetFullPath(Path.Combine(dir, "..", "..", "..", "..", "..", "docs", "_template.html"))
1460+
let defaultTemplateAttempt2 = inRepoLocations.template_html
14591461

14601462
let defaultTemplate =
14611463
if this.nodefaultcontent then
@@ -1482,7 +1484,7 @@ type CoreBuildOptions(watch) =
14821484
// The "extras" content goes in "."
14831485
// From .nuget\packages\fsdocs-tool\7.1.7\tools\net6.0\any
14841486
// to .nuget\packages\fsdocs-tool\7.1.7\extras
1485-
let attempt1 = Path.GetFullPath(Path.Combine(dir, "..", "..", "..", "extras"))
1487+
let attempt1 = inPackageLocations.extras
14861488

14871489
if
14881490
(try
@@ -1496,8 +1498,7 @@ type CoreBuildOptions(watch) =
14961498
// This is for in-repo use only, assuming we are executing directly from
14971499
// src\fsdocs-tool\bin\Debug\net6.0\fsdocs.exe
14981500
// src\fsdocs-tool\bin\Release\net6.0\fsdocs.exe
1499-
let attempt2 =
1500-
Path.GetFullPath(Path.Combine(dir, "..", "..", "..", "..", "..", "docs", "content"))
1501+
let attempt2 = inRepoLocations.docs_content
15011502

15021503
if
15031504
(try

src/fsdocs-tool/InitCommand.fs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace fsdocs
2+
3+
open System.IO
4+
open CommandLine
5+
6+
[<Verb("init", HelpText = "initialize the necessary folder structure and files for creating documentation with fsdocs.")>]
7+
type InitCommand() =
8+
class
9+
end

src/fsdocs-tool/Options.fs

+58
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,61 @@ module Common =
3838
if b then
3939
printf "\nPress any key to continue ..."
4040
System.Console.ReadKey() |> ignore
41+
42+
open System.IO
43+
44+
/// <summary>
45+
/// a set of default locations in this repo.
46+
/// these files are to be used in 2 scenarios assuming we are executing directly from
47+
///
48+
/// src\fsdocs-tool\bin\Debug\net6.0\fsdocs.exe
49+
///
50+
/// src\fsdocs-tool\bin\Release\net6.0\fsdocs.exe:
51+
///
52+
/// - as default styles when running watch or build when there are no user equivalents present and `nodefaultcontent` is not set to true
53+
///
54+
/// - as content of the output of the `init` command to initialize a default docs folder structure.
55+
///
56+
/// Note that the path of these files will always be combined with the given `assemblyPath` because the cli tool will query it's own path on runtime via reflection.
57+
/// </summary>
58+
type InRepoLocations(relAssemblyPath) =
59+
60+
// relAssemblyPath : relative path from assemly to repo root path
61+
62+
// default folder locations relative to the assembly path
63+
member _.docs = Path.Combine(relAssemblyPath, "docs") |> Path.GetFullPath
64+
member this.docs_content = Path.Combine(this.docs, "content") |> Path.GetFullPath
65+
member this.docs_content_image = Path.Combine(this.docs_content, "img") |> Path.GetFullPath
66+
67+
// specific files in this folder structure that might need special treatment instead of just copy pasting
68+
member this.template_html = Path.Combine(this.docs, "_template.html") |> Path.GetFullPath
69+
member this.template_ipynb = Path.Combine(this.docs, "_template.ipynb") |> Path.GetFullPath
70+
member this.template_tex = Path.Combine(this.docs, "_template.tex") |> Path.GetFullPath
71+
72+
/// <summary>
73+
/// a set of default locations in the nuget package created for fsdocs-tool.
74+
/// these files are to be used in 2 scenarios assuming the tool is invoked via cli:
75+
///
76+
/// - as default styles when running watch or build when there are no user equivalents present and `nodefaultcontent` is not set to true
77+
///
78+
/// - as content of the output of the `init` command to initialize a default docs folder structure.
79+
///
80+
/// Note that the path of these files will always be combined with the given `assemblyPath` because the cli tool will query it's own path on runtime via reflection.
81+
/// </summary>
82+
type InPackageLocations(relAssemblyPath) =
83+
84+
// relAssemblyPath : relative path from assemly to package root path
85+
86+
// From .nuget\packages\fsdocs-tool\7.1.7\tools\net6.0\any
87+
// to .nuget\packages\fsdocs-tool\7.1.7\*
88+
89+
// 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
92+
member this.extras_content = Path.Combine(this.extras, "content") |> Path.GetFullPath
93+
member this.extras_content_img = Path.Combine(this.extras_content, "img") |> Path.GetFullPath
94+
95+
// specific files in this folder structure that might need special treatment instead of just copy pasting
96+
member this.template_html = Path.Combine(this.templates, "_template.html") |> Path.GetFullPath
97+
member this.template_ipynb = Path.Combine(this.templates, "_template.ipynb") |> Path.GetFullPath
98+
member this.template_tex = Path.Combine(this.templates, "_template.tex") |> Path.GetFullPath

src/fsdocs-tool/fsdocs-tool.fsproj

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
<Compile Include="Options.fs" />
2323
<Compile Include="ProjectCracker.fs" />
2424
<Compile Include="BuildCommand.fs" />
25+
<Compile Include="InitCommand.fs" />
2526
<Compile Include="Program.fs" />
2627
</ItemGroup>
2728

0 commit comments

Comments
 (0)