Skip to content

Commit dad627a

Browse files
committed
Merge pull request #1251 from shortsn/feature/#1177_docfx_helper
Feature/#1177 docfx helper
2 parents 8c077f3 + 847e946 commit dad627a

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

src/app/FakeLib/DocFxHelper.fs

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
[<AutoOpen>]
2+
/// Contains helper functions to run the documentation tool "docfx".
3+
module Fake.DocFxHelper
4+
5+
open System
6+
7+
/// The parameter type for DocFx.
8+
type DocFxParams =
9+
{ /// The tool path - FAKE tries to find docfx.exe automatically in any sub folder.
10+
ToolPath : string
11+
/// the DocFxJson Config-File. Default: docs/docfx.json
12+
DocFxJson : string
13+
/// DocFx WorkingDirectory. Default: docs
14+
WorkingDirectory : string
15+
/// Allows to specify a timeout for DocFx. Default: 5 min
16+
Timeout : TimeSpan
17+
/// Serves the generated documentation on localhost. Default: false
18+
Serve : bool
19+
}
20+
21+
/// The default parameters
22+
let DocFxDefaults =
23+
let toolPath = findToolInSubPath "docfx.exe" (currentDirectory @@ "tools" @@ "docfx.msbuild")
24+
let docsPath = currentDirectory @@ "docs"
25+
{ ToolPath = toolPath
26+
DocFxJson = docsPath @@ "docfx.json"
27+
WorkingDirectory = docsPath
28+
Timeout = TimeSpan.FromMinutes 5.
29+
Serve = false
30+
}
31+
32+
/// Generates a DocFx documentation.
33+
/// ## Parameters
34+
/// - `setParams` - Function used to manipulate the default DocFx parameters. See `DocFxDefaults`
35+
/// ## Sample
36+
///
37+
/// DocFx (fun p ->
38+
/// { p with
39+
/// DocFxJson = "foo" @@ "bar" @@ "docfx.json"
40+
/// Timeout = TimeSpan.FromMinutes 10.
41+
/// })
42+
let DocFx setParams =
43+
let parameters = DocFxDefaults |> setParams
44+
45+
traceStartTask "DocFx" parameters.DocFxJson
46+
47+
let serveArg = if parameters.Serve then "--serve" else ""
48+
let configArg = parameters.DocFxJson |> FullName
49+
50+
let args = sprintf "%s %s" configArg serveArg
51+
52+
if 0 <> ExecProcess (fun info ->
53+
info.FileName <- parameters.ToolPath |> FullName
54+
info.Arguments <- args
55+
info.WorkingDirectory <- parameters.WorkingDirectory
56+
) parameters.Timeout
57+
then failwith "DocFx generation failed."
58+
59+
traceEndTask "DocFx" parameters.DocFxJson
60+

src/app/FakeLib/FakeLib.fsproj

+1
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@
180180
<Compile Include="SlackNotificationHelper.fs" />
181181
<Compile Include="SonarQubeHelper.fs" />
182182
<Compile Include="AzureKudu.fs" />
183+
<Compile Include="DocFxHelper.fs" />
183184
</ItemGroup>
184185
<ItemGroup>
185186
<Reference Include="ICSharpCode.SharpZipLib">

0 commit comments

Comments
 (0)