-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.fsx
executable file
·148 lines (126 loc) · 5.08 KB
/
build.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
141
142
143
144
145
146
147
148
#!/usr/bin/env fsharpi --exec
open System
open System.IO
open System.Net
open System.Diagnostics
open System.ComponentModel
let inline (/) p1 p2 = Path.Combine(p1, p2)
/// The version of the nuget package (bump this on each release)
let Version = "0.0.1-pre1"
// Paths of interest:
/// The root directory
let root = __SOURCE_DIRECTORY__
/// The directories, relative to `root`, that will be converted to html
let inputs = [
"docs"
"examples"
]
/// The path, relative to the above `inputs` dirs, to the template used in the html generation
let template = "tools" / "template.html"
/// The output directory into which the html files will be generated
let output = root / "html"
/// The path to the nuspec for creating the nuget package
let nuspec = root / "SharpBoomerang.nuspec"
/// The path in which nuget packages will be installed
let packages = root / "packages"
/// The URL to download nuget.exe for windows
let nugetURL = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
/// Project info for the docs
let projInfo =
[
"page-description", "SharpBoomerang documentation"
"page-author", "Alex Corrado"
"github-link", "https://github.com/chkn/SharpBoomerang"
"nuget-link", "https://www.nuget.org/packages/SharpBoomerang"
"project-name", "SharpBoomerang"
]
let quote (s : string) = "\"" + s.Replace("\"", "\\\"") + "\""
let run prog args =
try
let proc = ProcessStartInfo(prog, String.Join (" ", Array.map quote args), UseShellExecute = false)
|> Process.Start
proc.WaitForExit()
if proc.ExitCode <> 0 then
failwith "Failed."
with :? Win32Exception ->
printfn "Failed to run %s. Check that you are in a Visual Studio command prompt." prog
reraise()
let download (url : string) localPath =
use client = new WebClient()
client.DownloadFile(url, localPath)
// Tools
let git = run "git"
let msbuild = run "msbuild"
let nuget args =
try
run "nuget" args
with :? Win32Exception ->
if Environment.OSVersion.Platform <> PlatformID.Win32NT then reraise()
printfn "This script requires nuget.exe. Would you like to download it to this directory? [y/N]"
if Console.ReadKey(true).Key <> ConsoleKey.Y then printfn "Failed to run nuget:"; reraise()
printfn "Downloading nuget.exe..."
download nugetURL (root / "nuget.exe")
run "nuget" args
// Setup: Ensure F# formatting is available
let FSharpFormattingPath = packages / "FSharp.Formatting"
if not(Directory.Exists(FSharpFormattingPath)) then
nuget [| "install"; "FSharp.Formatting"; "-ExcludeVersion"; "-OutputDirectory"; packages |]
//FIXME: hardcoded path
#load @"packages/FSharp.Formatting/FSharp.Formatting.fsx"
// Tasks
let makeBuild() =
msbuild [| "/p:Configuration=Release" |]
let makeDocs() =
let fsi = FSharp.Literate.FsiEvaluator()
//fsi.EvaluationFailed.Add(fun e -> printf "%O" e)
inputs
|> List.iter (fun dir ->
let input = root / dir
let template = input / template
let output = output / dir
FSharp.Literate.Literate.ProcessDirectory(input, template, output, replacements = projInfo, fsiEvaluator = fsi)
)
FSharp.Literate.Literate.ProcessMarkdown(root / "Readme.md", root / template, output / "index.html", replacements = projInfo)
// Manually copy some files needed by the template
output / "content" |> Directory.CreateDirectory |> ignore
let copyContent src = File.Copy(src, output / "content" / Path.GetFileName(src), true)
FSharpFormattingPath / "styles" / "style.css" |> copyContent
FSharpFormattingPath / "styles" / "tips.js" |> copyContent
let makePages() =
makeDocs()
git [| "checkout"; "gh-pages" |]
let rec loop path =
for f in Directory.EnumerateFileSystemEntries(path) do
match f with
| "." | ".." | "" -> ()
| _ ->
let p = f.Replace(Path.GetFileName(output) + "/", "")
if Directory.Exists(f) then
if not(Directory.Exists(p)) then Directory.CreateDirectory(p) |> ignore
loop f
else
printfn "Copying: %s to %s" f p
File.Copy(f, p, true)
git [| "add"; p |]
loop output
git [| "status" |]
printfn "If this looks correct, type `git commit` and then `git push origin gh-pages` to push live."
let makeNupkg() =
if not(Directory.Exists(root / "bin" / "Release")) then makeBuild()
nuget [| "pack"; nuspec; "-Properties"; "version=" + Version |]
let makeClean() =
let rmrf p = try Directory.Delete(p, true) with :? DirectoryNotFoundException -> ()
rmrf (root / "bin")
rmrf (root / "obj")
rmrf (output)
Directory.EnumerateFiles(__SOURCE_DIRECTORY__, "*.nupkg")
|> Seq.iter (fun file -> File.Delete(file))
match fsi.CommandLineArgs with
| [| _; "clean" |] -> makeClean()
| [| _; "build" |] -> makeBuild()
| [| _; "docs" |] -> makeDocs()
| [| _; "pages" |] -> makePages()
| [| _; "nupkg" |] -> makeNupkg()
| [| _; "all" |]
| [| _ |] -> makeDocs(); makeNupkg()
| _ -> printf "Invalid options.\n"