@@ -3,47 +3,61 @@ namespace fsdocs
33open System.IO
44open CommandLine
55
6+ open Spectre.Console
7+
68[<Verb( " init" , HelpText = " initialize the necessary folder structure and files for creating documentation with fsdocs." ) >]
79type 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