forked from Antaris/RazorEngine
-
Notifications
You must be signed in to change notification settings - Fork 1
/
generateDocs.fsx
140 lines (117 loc) · 6.03 KB
/
generateDocs.fsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
// ----------------------------------------------------------------------------
// This file is subject to the terms and conditions defined in
// file 'LICENSE.txt', which is part of this source code package.
// ----------------------------------------------------------------------------
(*
This file handles the generation of the docs (it is called by the build automatically).
*)
#I @".nuget/Build/FAKE/tools/" // FAKE
#I @"lib/FSharp.Formatting" // Custom build with the FSharp.Compiler.Service from below
#I @"build/net40" // dependency
#I @"lib/FSharp.Compiler.Service" // because we want C# support, nuget version doesnt have it (https://github.com/matthid/FSharp.Compiler.Service/commit/c5dfd4dd488f6dcd1024b0ed2b564ce9d2d414fa?diff=unified)
#r @"FakeLib.dll" //FAKE
#load @"buildConfig.fsx"
open BuildConfig
// Documentation
#r "FSharp.Compiler.Service.dll"
#r "System.Web.Razor.dll"
#r "RazorEngine.dll"
#r "FSharp.Literate.dll"
#r "FSharp.CodeFormat.dll"
#r "FSharp.MetadataFormat.dll"
open System.Collections.Generic
open System.IO
open Fake
open Fake.Git
open Fake.FSharpFormatting
open AssemblyInfoFile
open FSharp.Literate
open FSharp.MetadataFormat
open RazorEngine.Compilation
// Documentation
/// Processes an entire directory containing multiple script files
/// (*.fsx) and Markdown documents (*.md) and it specifies additional
/// replacements for the template file
//let website_root = "file://" + Path.GetFullPath (outDocDir @@ "html")
let buildAllDocumentation outDocDir website_root =
let references =
if isMono then
// Workaround compiler errors in Razor-ViewEngine
let d = RazorEngine.Compilation.ReferenceResolver.UseCurrentAssembliesReferenceResolver()
let loadedList = d.GetReferences() |> Seq.map (fun c -> c.GetFile()) |> Seq.cache
//// We replace the list and add required items manually as mcs doesn't like duplicates...
let getItem name =
loadedList |> Seq.find (fun l -> l.Contains name)
[ (getItem "FSharp.Core").Replace("4.3.0.0", "4.3.1.0") // (if isMono then "/usr/lib64/mono/gac/FSharp.Core/4.3.1.0__b03f5f7f11d50a3a/FSharp.Core.dll" else "FSharp.Core")
Path.GetFullPath "./lib/FSharp.Compiler.Service/FSharp.Compiler.Service.dll"
Path.GetFullPath "./build/net40/System.Web.Razor.dll"
Path.GetFullPath "./build/net40/RazorEngine.dll"
Path.GetFullPath "./lib/FSharp.Formatting/FSharp.Literate.dll"
Path.GetFullPath "./lib/FSharp.Formatting/FSharp.CodeFormat.dll"
Path.GetFullPath "./lib/FSharp.Formatting/FSharp.MetadataFormat.dll" ]
|> Some
else None
let projInfo =
[ "root", website_root
"page-description", projectDescription
"page-author", page_author
"github-link", github_url
"project-name", projectName
"project-summary", projectSummary
"project-commit", commitHash
"project-author", authors |> Seq.head
"project-github", github_url
"project-issues", sprintf "%s/issues" github_url
"project-new-issue", sprintf "%s/issues/new" github_url
"project-nuget", nuget_url]
// Copy static files and CSS + JS from F# Formatting
let copyDocContentFiles () =
CopyRecursive "./doc/content" (outDocDir @@ "html" @@ "content") true |> Log "Copying file: "
//ensureDirectory (outDocDir @@ "html" @@ "content")
//CopyRecursive (formatting @@ "styles") (output @@ "content") true
// |> Log "Copying styles and scripts: "
let processDirectory(outputKind) =
let indexTemplate, template, outDirName, indexName =
match outputKind with
| OutputKind.Html -> docTemplatesDir @@ "docpage-index.cshtml", docTemplatesDir @@ "docpage.cshtml", "html", "index.html"
| OutputKind.Latex -> docTemplatesDir @@ "template-color.tex", docTemplatesDir @@ "template-color.tex", "latex", "Readme.tex"
let outDir = outDocDir @@ outDirName
Literate.ProcessDirectory
( "./doc", template, outDir,
outputKind, replacements = projInfo, layoutRoots = layoutRoots, generateAnchors = true, ?assemblyReferences = references)
Literate.ProcessMarkdown("./readme.md", indexTemplate, outDir @@ indexName, outputKind, replacements = projInfo, layoutRoots = layoutRoots, generateAnchors = true, ?assemblyReferences = references)
// Build API reference from XML comments
let referenceBinaries =
[
"RazorEngine.dll"
"RazorEngine.Roslyn.dll"
]
let buildReference () =
let referenceDir = outDocDir @@ "html"
let outDir = referenceDir @@ "references"
ensureDirectory referenceDir
ensureDirectory outDir
let binaries =
referenceBinaries
|> List.map (fun lib-> Path.GetFullPath( buildDir @@ "net45" @@ lib ))
MetadataFormat.Generate
(binaries, Path.GetFullPath outDir, layoutRoots,
parameters = projInfo,
libDirs = [ Path.GetFullPath ("./build/net45") ],
otherFlags = [ "-r:System";"-r:System.Core";"-r:System.Xml";"-r:System.Xml.Linq"],
sourceRepo = github_url + "/blob/master/",
sourceFolder = "./",
publicOnly = true,
markDownComments = false, // <see cref=""/> support
?assemblyReferences = references )
CleanDirs [ outDocDir ]
copyDocContentFiles()
processDirectory OutputKind.Html
processDirectory OutputKind.Latex
buildReference()
MyTarget "GithubDoc" (fun _ -> buildAllDocumentation (outDocDir @@ sprintf "%s.github.io" github_user) (sprintf "https://%s.github.io/%s" github_user github_project))
MyTarget "LocalDoc" (fun _ ->
buildAllDocumentation (outDocDir @@ "local") ("file://" + Path.GetFullPath (outDocDir @@ "local" @@ "html"))
trace (sprintf "Local documentation has been finished, you can view it by opening %s in your browser!" (Path.GetFullPath (outDocDir @@ "local" @@ "html" @@ "index.html")))
)
RunTargetOrDefault "LocalDoc"