-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
Build.fs
155 lines (123 loc) · 4.48 KB
/
Build.fs
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
149
150
151
152
153
154
155
open Fake.Core
open Fake.DotNet
open Fake.Tools
open Fake.IO
open Fake.IO.FileSystemOperators
open Fake.IO.Globbing.Operators
open Fake.Core.TargetOperators
open Fake.Api
open Helpers
initializeContext()
// --------------------------------------------------------------------------------------
// Information about the project to be used at NuGet and in AssemblyInfo files
// --------------------------------------------------------------------------------------
let project = "Fornax"
let summary = "Fornax is a static site generator using type safe F# DSL to define page layouts"
let nugetOrg = "https://api.nuget.org/v3/index.json"
let gitOwner = "Ionide"
let gitHome = "https://github.com/" + gitOwner
let gitName = "Fornax"
let gitRaw = Environment.environVarOrDefault "gitRaw" ("https://raw.github.com/" + gitOwner)
// --------------------------------------------------------------------------------------
// Build variables
// --------------------------------------------------------------------------------------
System.Environment.CurrentDirectory <- __SOURCE_DIRECTORY__
let packageDir = __SOURCE_DIRECTORY__ </> "out"
let buildDir = __SOURCE_DIRECTORY__ </> "temp"
// --------------------------------------------------------------------------------------
// Helpers
// --------------------------------------------------------------------------------------
let isNullOrWhiteSpace = System.String.IsNullOrWhiteSpace
let runTool cmd args workingDir =
let arguments = args |> String.split ' ' |> Arguments.OfArgs
let r =
Command.RawCommand (cmd, arguments)
|> CreateProcess.fromCommand
|> CreateProcess.withWorkingDirectory workingDir
|> Proc.run
if r.ExitCode <> 0 then
failwithf "Error while running '%s' with args: %s" cmd args
let getBuildParam = Environment.environVar
let DoNothing = ignore
// --------------------------------------------------------------------------------------
// Build Targets
// --------------------------------------------------------------------------------------
Target.create "Clean" (fun _ ->
Shell.cleanDirs [buildDir; packageDir]
)
Target.create "Restore" (fun _ ->
DotNet.restore id "Fornax.sln"
)
Target.create "Build" (fun _ ->
DotNet.build id "Fornax.sln"
)
Target.create "Publish" (fun _ ->
DotNet.publish (fun p -> {p with OutputPath = Some buildDir}) "src/Fornax"
)
Target.create "Test" (fun _ ->
runTool "dotnet" @"run --project .\test\Fornax.Core.UnitTests\Fornax.Core.UnitTests.fsproj" "."
)
Target.create "TestTemplate" (fun _ ->
let templateDir = __SOURCE_DIRECTORY__ </> "src/Fornax.Template/"
let coreDllSource = buildDir </> "Fornax.Core.dll"
let coreDllDest = templateDir </> "_lib" </> "Fornax.Core.dll"
try
System.IO.File.Copy(coreDllSource, coreDllDest, true)
let newlyBuiltFornax = buildDir </> "Fornax.dll"
printfn "templateDir: %s" templateDir
runTool "dotnet" (sprintf "%s watch" newlyBuiltFornax) templateDir
finally
File.delete coreDllDest
)
// --------------------------------------------------------------------------------------
// Release Targets
// --------------------------------------------------------------------------------------
Target.create "Pack" (fun _ ->
[
"src/Fornax"
"src/Fornax.Core"
]
|> List.iter(
DotNet.pack (fun p ->
{ p with
OutputPath = Some packageDir
Configuration = DotNet.BuildConfiguration.Release
}))
)
Target.create "Push" (fun _ ->
let key =
match getBuildParam "nuget-key" with
| s when not (isNullOrWhiteSpace s) -> s
| _ -> UserInput.getUserPassword "NuGet Key: "
DotNet.nugetPush (fun p ->
{ p with
PushParams = { p.PushParams with
ApiKey = Some key
Source = Some nugetOrg } }
) $"{packageDir}/*.nupkg"
)
// --------------------------------------------------------------------------------------
// Build order
// --------------------------------------------------------------------------------------
Target.create "Default" DoNothing
Target.create "Release" DoNothing
let dependencies = [
"Clean"
==> "Restore"
==> "Build"
==> "Publish"
==> "Test"
==> "Default"
"Restore"
==> "Build"
==> "Publish"
==> "TestTemplate"
"Default"
==> "Pack"
==> "Push"
==> "Release"
]
[<EntryPoint>]
let main args =
runOrDefault "Pack" args