@@ -3,47 +3,61 @@ namespace fsdocs
3
3
open System.IO
4
4
open CommandLine
5
5
6
+ open Spectre.Console
7
+
6
8
[<Verb( " init" , HelpText = " initialize the necessary folder structure and files for creating documentation with fsdocs." ) >]
7
9
type InitCommand () =
8
10
9
11
let dir = Path.GetDirectoryName( typeof< InitCommand>. Assembly.Location)
10
12
11
13
// 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 " ))
14
16
15
17
[<Option( " output" ,
16
18
Required = false ,
17
19
Default = " docs" ,
18
20
HelpText = " The output path for the documentation folder structure" ) >]
19
21
member val output : string = " docs" with get, set
20
22
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
+
21
29
member this.Execute () =
22
30
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)
26
33
27
34
let ensureOutputDirs () =
28
- [ outputPath ; initLocations.docs ; initLocations.docs _ img ]
35
+ [ docsOutputPath ; initLocations.DocsFolder.Path ; initLocations.img.Path ]
29
36
|> List.iter ensureDirectory
30
37
31
- if inPackageLocations.Exist () then
38
+ if inNugetPackageLocations.AllLocationsExist () then
32
39
// if the in-package locations exist, this means fsdocs is run from the nuget package.
33
- ensureOutputDirs ()
34
-
35
40
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))
47
61
48
62
printfn " "
49
63
printfn " a basic fsdocs scaffold has been created in %s ." this.output
@@ -55,22 +69,32 @@ type InitCommand() =
55
69
printfn " Error: %s " exn.Message
56
70
1
57
71
58
- elif inRepoLocations.Exist () then
72
+ elif inThisRepoLocations.AllLocationsExist () then
59
73
// if the in-repo locations exist, this means fsdocs is run from inside the FSharp.Formatting repo itself.
60
- ensureOutputDirs ()
61
74
62
75
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))
74
98
75
99
printfn " "
76
100
printfn " a basic fsdocs scaffold has been created in %s ." this.output
@@ -84,7 +108,7 @@ type InitCommand() =
84
108
else
85
109
printfn
86
110
" 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
89
113
90
114
1
0 commit comments