33// --------------------------------------------------------------------------------------
44
55#r " paket: groupref FakeBuild //"
6- open Fake.IO
76
87#load " ./.fake/build.fsx/intellisense.fsx"
98
@@ -13,10 +12,68 @@ open Fake.Core.TargetOperators
1312open Fake.DotNet
1413open Fake.IO
1514open Fake.IO .FileSystemOperators
15+ open Fake.IO .Globbing
1616open Fake.IO .Globbing .Operators
1717open Fake.DotNet .Testing
1818open Fake.Tools
1919open Fake.Api
20+ open Fake.Tools .Git
21+
22+ [<AutoOpen>]
23+ module TemporaryDocumentationHelpers =
24+
25+ type LiterateArguments =
26+ { ToolPath : string
27+ Source : string
28+ OutputDirectory : string
29+ Template : string
30+ ProjectParameters : ( string * string ) list
31+ LayoutRoots : string list
32+ FsiEval : bool }
33+
34+
35+ let private run toolPath command =
36+ if 0 <> Process.execSimple (( fun info ->
37+ { info with
38+ FileName = toolPath
39+ Arguments = command }) >> Process.withFramework) System.TimeSpan.MaxValue
40+
41+ then failwithf " FSharp.Formatting %s failed." command
42+
43+ let createDocs p =
44+ let toolPath = Tools.findToolInSubPath " fsformatting.exe" ( Directory.GetCurrentDirectory() @@ " lib/Formatting" )
45+
46+ let defaultLiterateArguments =
47+ { ToolPath = toolPath
48+ Source = " "
49+ OutputDirectory = " "
50+ Template = " "
51+ ProjectParameters = []
52+ LayoutRoots = []
53+ FsiEval = false }
54+
55+ let arguments = ( p: LiterateArguments-> LiterateArguments) defaultLiterateArguments
56+ let layoutroots =
57+ if arguments.LayoutRoots.IsEmpty then []
58+ else [ " --layoutRoots" ] @ arguments.LayoutRoots
59+ let source = arguments.Source
60+ let template = arguments.Template
61+ let outputDir = arguments.OutputDirectory
62+ let fsiEval = if arguments.FsiEval then [ " --fsieval" ] else []
63+
64+ let command =
65+ arguments.ProjectParameters
66+ |> Seq.map ( fun ( k , v ) -> [ k; v ])
67+ |> Seq.concat
68+ |> Seq.append
69+ ([ " literate" ; " --processdirectory" ] @ layoutroots @ [ " --inputdirectory" ; source; " --templatefile" ; template;
70+ " --outputDirectory" ; outputDir] @ fsiEval @ [ " --replacements" ])
71+ |> Seq.map ( fun s ->
72+ if s.StartsWith " \" " then s
73+ else sprintf " \" %s \" " s)
74+ |> String.separated " "
75+ run arguments.ToolPath command
76+ printfn " Successfully generated docs for %s " source
2077
2178// --------------------------------------------------------------------------------------
2279// START TODO: Provide project-specific details below
@@ -319,20 +376,43 @@ Target.create "Docs" (fun _ ->
319376 | Some lang -> layoutRootsAll.[ lang]
320377 | None -> layoutRootsAll.[ " en" ] // "en" is the default language
321378
322- FSFormatting. createDocs ( fun args ->
379+ createDocs ( fun args ->
323380 { args with
324381 Source = content
325382 OutputDirectory = output
326383 LayoutRoots = layoutRoots
327384 ProjectParameters = ( " root" , root):: info
328- Template = docTemplate } )
385+ Template = docTemplate
386+ FsiEval = true
387+ } )
329388)
330389
331390// --------------------------------------------------------------------------------------
332391// Release Scripts
333392
393+
334394//#load "paket-files/fsharp/FAKE/modules/Octokit/Octokit.fsx"
335395//open Octokit
396+ Target.create " ReleaseDocs" ( fun _ ->
397+ let tempDocsDir = " temp/gh-pages"
398+ Shell.cleanDir tempDocsDir |> ignore
399+ Git.Repository.cloneSingleBranch " " ( gitHome + " /" + gitName + " .git" ) " gh-pages" tempDocsDir
400+ Shell.copyRecursive " docs" tempDocsDir true |> printfn " %A "
401+ Git.Staging.stageAll tempDocsDir
402+ Git.Commit.exec tempDocsDir ( sprintf " Update generated documentation for version %s " release.NugetVersion)
403+ Git.Branches.push tempDocsDir
404+ )
405+
406+ Target.create " ReleaseLocal" ( fun _ ->
407+ let tempDocsDir = " temp/gh-pages"
408+ Shell.cleanDir tempDocsDir |> ignore
409+ Shell.copyRecursive " docs" tempDocsDir true |> printfn " %A "
410+ Shell.replaceInFiles
411+ ( seq {
412+ yield " href=\" /" + project + " /" , " href=\" "
413+ yield " src=\" /" + project + " /" , " src=\" " })
414+ ( Directory.EnumerateFiles tempDocsDir |> Seq.filter ( fun x -> x.EndsWith( " .html" )))
415+ )
336416
337417Target.create " Release" ( fun _ ->
338418 // not fully converted from FAKE 4
@@ -400,16 +480,16 @@ Target.create "All" ignore
400480 ==> " Build"
401481 ==> " CopyBinaries"
402482 ==> " RunTests"
403- // ==> "GenerateDocs"
483+ ==> " GenerateDocs"
404484 ==> " NuGet"
405485 ==> " All"
406486
407487" RunTests" ?=> " CleanDocs"
408488
409489" CleanDocs"
410490 ==> " Docs"
411- // ==> "ReferenceDocs"
412- // ==> "GenerateDocs"
491+ ==> " ReferenceDocs"
492+ ==> " GenerateDocs"
413493
414494" Clean"
415495 ==> " Release"
@@ -418,6 +498,11 @@ Target.create "All" ignore
418498 ==> " PublishNuget"
419499 ==> " Release"
420500
501+ " GenerateDocs"
502+ ==> " ReleaseDocs"
503+
504+ " All"
505+ ==> " ReleaseLocal"
421506
422507" Clean"
423508 ==> " AssemblyInfo"
@@ -427,4 +512,4 @@ Target.create "All" ignore
427512 ==> " NuGet"
428513 ==> " GitReleaseNuget"
429514
430- Target.runOrDefault " All"
515+ Target.runOrDefaultWithArguments " All"
0 commit comments