|
| 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 | + |
0 commit comments