Skip to content

Commit e28ee79

Browse files
committed
improve default location abstractions
- more descriptive class names - member names now reflect paths exactly - add badge svg file paths - add location descriptions
1 parent f5bd211 commit e28ee79

File tree

6 files changed

+313
-148
lines changed

6 files changed

+313
-148
lines changed

Directory.Packages.props

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<PackageVersion Include="Ionide.ProjInfo" Version="0.62.0" />
1717
<PackageVersion Include="Ionide.ProjInfo.Sln" Version="0.62.0" />
1818
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
19+
<PackageVersion Include="Spectre.Console" Version="0.48.0" />
1920
<PackageVersion Include="Suave" Version="2.6.2" />
2021
<PackageVersion Include="System.Memory" Version="4.5.5" />
2122
<PackageVersion Include="System.Text.Json" Version="8.0.0" />

build.fsx

+19-7
Original file line numberDiff line numberDiff line change
@@ -50,23 +50,28 @@ let testStage =
5050
$"dotnet test {solutionFile} --configuration {configuration} --no-build --blame --logger trx --results-directory TestResults -tl"
5151
}
5252

53-
pipeline "CI" {
54-
lintStage
53+
let buildStage =
54+
stage "Build" {
55+
run $"dotnet restore {solutionFile} -tl"
56+
run $"dotnet build {solutionFile} --configuration {configuration} -tl"
57+
}
5558

59+
let cleanStage =
5660
stage "Clean" {
5761
run (fun _ ->
5862
!!artifactsDir ++ "temp" |> Shell.cleanDirs
5963
// in case the above pattern is empty as it only matches existing stuff
6064
[ "bin"; "temp"; "tests/bin" ] |> Seq.iter Directory.ensure)
6165
}
6266

63-
stage "Build" {
64-
run $"dotnet restore {solutionFile} -tl"
65-
run $"dotnet build {solutionFile} --configuration {configuration} -tl"
66-
}
67-
67+
let nugetStage =
6868
stage "NuGet" { run $"dotnet pack {solutionFile} --output \"{artifactsDir}\" --configuration {configuration} -tl" }
6969

70+
pipeline "CI" {
71+
lintStage
72+
cleanStage
73+
buildStage
74+
nugetStage
7075
testStage
7176

7277
stage "GenerateDocs" {
@@ -93,4 +98,11 @@ pipeline "Verify" {
9398
runIfOnlySpecified true
9499
}
95100

101+
pipeline "BuildAndPack" {
102+
cleanStage
103+
buildStage
104+
nugetStage
105+
runIfOnlySpecified true
106+
}
107+
96108
tryPrintPipelineCommandHelp ()

src/fsdocs-tool/BuildCommand.fs

+21-20
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ namespace fsdocs
22

33
open System.Collections.Concurrent
44
open CommandLine
5+
open Spectre.Console
56

67
open System
78
open System.Diagnostics
@@ -1580,16 +1581,16 @@ type CoreBuildOptions(watch) =
15801581
let dir = Path.GetDirectoryName(typeof<CoreBuildOptions>.Assembly.Location)
15811582

15821583
// get template locations for in-package and in-repo and decide which to use later
1583-
let inPackageLocations = Common.InPackageLocations(Path.Combine(dir, "..", "..", ".."))
1584-
let inRepoLocations = Common.InRepoLocations(Path.Combine(dir, "..", "..", "..", "..", ".."))
1584+
let inNugetPackageLocations = Common.InNugetPackageLocations(Path.Combine(dir, "..", "..", ".."))
1585+
let inThisRepoLocations = Common.InDocsFolderLocations(Path.Combine(dir, "..", "..", "..", "..", "..", "docs"))
15851586

15861587
let defaultTemplate =
15871588
if this.nodefaultcontent then
15881589
None
1589-
else if inPackageLocations.Exist() then
1590-
Some inPackageLocations.template_html
1591-
elif inRepoLocations.Exist() then
1592-
Some inRepoLocations.template_html
1590+
else if inNugetPackageLocations.AllLocationsExist() then
1591+
Some inNugetPackageLocations.``templates/template.html``.Path
1592+
elif inThisRepoLocations.AllLocationsExist() then
1593+
Some inThisRepoLocations.``template.html``.Path
15931594
else
15941595
None
15951596

@@ -1598,22 +1599,22 @@ type CoreBuildOptions(watch) =
15981599
// The "extras" content goes in "."
15991600
// From .nuget\packages\fsdocs-tool\7.1.7\tools\net6.0\any
16001601
// to .nuget\packages\fsdocs-tool\7.1.7\extras
1601-
if inPackageLocations.Exist() then
1602-
printfn "using extra content from %s" inPackageLocations.extras
1603-
(inPackageLocations.extras, ".")
1602+
if inNugetPackageLocations.AllLocationsExist() then
1603+
printfn "using extra content from %s" inNugetPackageLocations.extras.Path
1604+
(inNugetPackageLocations.extras.Path, ".")
16041605
else if
16051606
// This is for in-repo use only, assuming we are executing directly from
16061607
// src\fsdocs-tool\bin\Debug\net6.0\fsdocs.exe
16071608
// src\fsdocs-tool\bin\Release\net6.0\fsdocs.exe
1608-
inRepoLocations.Exist()
1609+
inThisRepoLocations.AllLocationsExist()
16091610
then
1610-
printfn "using extra content from %s" inRepoLocations.docs_content
1611-
(inRepoLocations.docs_content, "content")
1611+
printfn "using extra content from %s" inThisRepoLocations.content.Path
1612+
(inThisRepoLocations.content.Path, "content")
16121613
else
16131614
printfn
16141615
"no extra content found at %s or %s"
1615-
inPackageLocations.extras
1616-
inRepoLocations.docs_content ]
1616+
inNugetPackageLocations.extras.Path
1617+
inThisRepoLocations.content.Path ]
16171618

16181619
// The incremental state (as well as the files written to disk)
16191620
let mutable latestApiDocModel = None
@@ -1671,12 +1672,12 @@ type CoreBuildOptions(watch) =
16711672
templateFiles
16721673
d
16731674

1674-
OutputKind.Html, Some d
1675-
| None ->
1676-
printfn
1677-
"note, no template file '%s' found, and no default template at '%s'"
1678-
templateFiles
1679-
inRepoLocations.template_html
1675+
OutputKind.Html, Some d
1676+
| None ->
1677+
printfn
1678+
"note, no template file '%s' found, and no default template at '%s'"
1679+
templateFiles
1680+
inThisRepoLocations.``template.html``.Path
16801681

16811682
OutputKind.Html, None
16821683

src/fsdocs-tool/InitCommand.fs

+59-35
Original file line numberDiff line numberDiff line change
@@ -3,47 +3,61 @@ namespace fsdocs
33
open System.IO
44
open CommandLine
55

6+
open Spectre.Console
7+
68
[<Verb("init", HelpText = "initialize the necessary folder structure and files for creating documentation with fsdocs.")>]
79
type InitCommand() =
810

911
let dir = Path.GetDirectoryName(typeof<InitCommand>.Assembly.Location)
1012

1113
// get template locations for in-package and in-repo files and decide which to use later
12-
let inPackageLocations = Common.InPackageLocations(Path.Combine(dir, "..", "..", ".."))
13-
let inRepoLocations = Common.InRepoLocations(Path.Combine(dir, "..", "..", "..", "..", ".."))
14+
let inNugetPackageLocations = Common.InNugetPackageLocations(Path.Combine(dir, "..", "..", ".."))
15+
let inThisRepoLocations = Common.InDocsFolderLocations(Path.Combine(dir, "..", "..", "..", "..", "..", "docs"))
1416

1517
[<Option("output",
1618
Required = false,
1719
Default = "docs",
1820
HelpText = "The output path for the documentation folder structure")>]
1921
member val output: string = "docs" with get, set
2022

23+
[<Option("force",
24+
Required = false,
25+
Default = false,
26+
HelpText = "Whether to force-overwrite existing files in the output folder.")>]
27+
member val force: bool = false with get, set
28+
2129
member this.Execute() =
2230

23-
let outputPath = Path.GetFullPath(this.output)
24-
let repoRoot = Path.GetFullPath(Path.Combine(outputPath, ".."))
25-
let initLocations = Common.InRepoLocations(repoRoot)
31+
let docsOutputPath = Path.GetFullPath(this.output)
32+
let initLocations = Common.InDocsFolderLocations(docsOutputPath)
2633

2734
let ensureOutputDirs () =
28-
[ outputPath; initLocations.docs; initLocations.docs_img ]
35+
[ docsOutputPath; initLocations.DocsFolder.Path; initLocations.img.Path ]
2936
|> List.iter ensureDirectory
3037

31-
if inPackageLocations.Exist() then
38+
if inNugetPackageLocations.AllLocationsExist() then
3239
// if the in-package locations exist, this means fsdocs is run from the nuget package.
33-
ensureOutputDirs ()
34-
3540
try
36-
[ (inPackageLocations.template_html, initLocations.template_html)
37-
(inPackageLocations.template_ipynb, initLocations.template_ipynb)
38-
(inPackageLocations.template_tex, initLocations.template_tex)
39-
(inPackageLocations.dockerfile, initLocations.dockerfile)
40-
(inPackageLocations.nuget_config, initLocations.nuget_config)
41-
// these files must be renamed, because files prefixed with a dot are otherwise ignored by fsdocs. We want this in the source repo, but not in the output of this command.
42-
(inPackageLocations.logo_template, Path.GetFullPath(Path.Combine(initLocations.docs_img, "logo.png")))
43-
(inPackageLocations.index_md_template, Path.GetFullPath(Path.Combine(initLocations.docs, "index.md")))
44-
(inPackageLocations.literate_sample_template,
45-
Path.GetFullPath(Path.Combine(initLocations.docs, "literate_sample.fsx"))) ]
46-
|> List.iter (fun (src, dst) -> File.Copy(src, dst, true))
41+
ensureOutputDirs ()
42+
43+
let fileMap =
44+
[ inNugetPackageLocations.``templates/template.html``, initLocations.``template.html``.Path
45+
inNugetPackageLocations.``templates/template.ipynb``, initLocations.``template.ipynb``.Path
46+
inNugetPackageLocations.``templates/template.tex``, initLocations.``template.tex``.Path
47+
inNugetPackageLocations.Dockerfile, initLocations.Dockerfile.Path
48+
inNugetPackageLocations.``Nuget.config``, initLocations.``Nuget.config``.Path
49+
inNugetPackageLocations.``extras/content/img/badge-binder.svg``, initLocations.``img/badge-binder.svg``.Path
50+
inNugetPackageLocations.``extras/content/img/badge-notebook.svg``, initLocations.``img/badge-notebook.svg``.Path
51+
inNugetPackageLocations.``extras/content/img/badge-script.svg``, initLocations.``img/badge-script.svg``.Path
52+
// these files must be renamed, because files prefixed with a dot are otherwise ignored by fsdocs. We want this in the source repo, but not in the output of this command.
53+
inNugetPackageLocations.``templates/init/.logo.png``,
54+
Path.GetFullPath(Path.Combine(initLocations.img.Path, "logo.png"))
55+
inNugetPackageLocations.``templates/init/.index_md_template.md``,
56+
Path.GetFullPath(Path.Combine(initLocations.DocsFolder.Path, "index.md"))
57+
inNugetPackageLocations.``templates/init/.literate_sample_template.fsx``,
58+
Path.GetFullPath(Path.Combine(initLocations.DocsFolder.Path, "literate_sample.fsx")) ]
59+
60+
fileMap |> List.iter (fun (src, dst) -> File.Copy(src.Path, dst, this.force))
4761

4862
printfn ""
4963
printfn "a basic fsdocs scaffold has been created in %s." this.output
@@ -55,22 +69,32 @@ type InitCommand() =
5569
printfn "Error: %s" exn.Message
5670
1
5771

58-
elif inRepoLocations.Exist() then
72+
elif inThisRepoLocations.AllLocationsExist() then
5973
// if the in-repo locations exist, this means fsdocs is run from inside the FSharp.Formatting repo itself.
60-
ensureOutputDirs ()
6174

6275
try
63-
[ (inRepoLocations.template_html, initLocations.template_html)
64-
(inRepoLocations.template_ipynb, initLocations.template_ipynb)
65-
(inRepoLocations.template_tex, initLocations.template_tex)
66-
(inRepoLocations.dockerfile, initLocations.dockerfile)
67-
(inRepoLocations.nuget_config, initLocations.nuget_config)
68-
// these files must be renamed, because files prefixed with a dot are otherwise ignored by fsdocs. We want this in the source repo, but not in the output of this command.
69-
(inRepoLocations.logo_template, Path.GetFullPath(Path.Combine(initLocations.docs_img, "logo.png")))
70-
(inRepoLocations.index_md_template, Path.GetFullPath(Path.Combine(initLocations.docs, "index.md")))
71-
(inRepoLocations.literate_sample_template,
72-
Path.GetFullPath(Path.Combine(initLocations.docs, "literate_sample.fsx"))) ]
73-
|> List.iter (fun (src, dst) -> File.Copy(src, dst, true))
76+
ensureOutputDirs ()
77+
78+
let fileMap =
79+
[ (inThisRepoLocations.``template.html``, initLocations.``template.html``.Path)
80+
(inThisRepoLocations.``template.ipynb``, initLocations.``template.ipynb``.Path)
81+
(inThisRepoLocations.``template.tex``, initLocations.``template.tex``.Path)
82+
(inThisRepoLocations.Dockerfile, initLocations.Dockerfile.Path)
83+
(inThisRepoLocations.``Nuget.config``, initLocations.``Nuget.config``.Path)
84+
(inThisRepoLocations.``img/badge-binder.svg``, initLocations.``img/badge-binder.svg``.Path)
85+
(inThisRepoLocations.``img/badge-notebook.svg``, initLocations.``img/badge-notebook.svg``.Path)
86+
(inThisRepoLocations.``img/badge-script.svg``, initLocations.``img/badge-script.svg``.Path)
87+
// these files must be renamed, because files prefixed with a dot are otherwise ignored by fsdocs. We want this in the source repo, but not in the output of this command.
88+
(inThisRepoLocations.``templates/init/.logo.png``,
89+
Path.GetFullPath(Path.Combine(initLocations.img.Path, "logo.png")))
90+
(inThisRepoLocations.``templates/init/.index_md_template.md``,
91+
Path.GetFullPath(Path.Combine(initLocations.DocsFolder.Path, "index.md")))
92+
(inThisRepoLocations.``templates/init/.literate_sample_template.fsx``,
93+
Path.GetFullPath(Path.Combine(initLocations.DocsFolder.Path, "literate_sample.fsx"))) ]
94+
95+
fileMap
96+
// |> List.map (fun (src, dst) -> )
97+
|> List.iter (fun (src, dst) -> File.Copy(src.Path, dst, this.force))
7498

7599
printfn ""
76100
printfn "a basic fsdocs scaffold has been created in %s." this.output
@@ -84,7 +108,7 @@ type InitCommand() =
84108
else
85109
printfn
86110
"no sources for default files found from either %s or %s"
87-
inPackageLocations.RelAssemblyPath
88-
inRepoLocations.RelAssemblyPath
111+
inNugetPackageLocations.NugetPackageRootPath.Path
112+
inThisRepoLocations.DocsFolder.Path
89113

90114
1

0 commit comments

Comments
 (0)