-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.fsx
118 lines (96 loc) · 2.63 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
#r "paket:
nuget FSharp.Core
nuget Fake.Core.Target
nuget Fake.DotNet.Cli //"
#load "./.fake/build.fsx/intellisense.fsx"
open System.IO
open Fake.Core
open Fake.DotNet
open Fake.IO
module DotNet =
let clean settings =
DotNet.exec settings "clean" "" |> ignore
let run settings args project =
let args =
["--project"; project] @ args
|> List.toSeq
|> String.concat " "
DotNet.exec settings "run" args |> ignore
let getFsproj directory =
DirectoryInfo.getFiles directory
|> Array.tryFind (fun file -> file.Extension = ".fsproj")
let internal getProjects directory =
DirectoryInfo.ofPath directory
|> DirectoryInfo.getSubDirectories
|> Array.choose getFsproj
let srcProjects = getProjects "src"
let testProjects = getProjects "tests"
let projects =
[|
yield! srcProjects
yield! testProjects
|]
let runOnAllProjects f (projects: FileInfo []) =
projects
|> Array.map (fun project -> project.FullName)
|> Array.iter f
Target.create "Restore" (fun _ ->
projects
|> runOnAllProjects (DotNet.restore id)
)
Target.create "Clean" (fun _ ->
DotNet.clean id
projects
|> Array.map (fun fsproj -> fsproj.Directory)
|> Array.collect (fun directory ->
[|
Path.combine directory.FullName "bin"
Path.combine directory.FullName "obj"
|]
)
|> Shell.deleteDirs
)
Target.create "Build" (fun _ ->
projects
|> Array.map (fun fsproj -> fsproj.FullName)
|> Array.iter (DotNet.build id)
)
Target.create "Test" (fun _ ->
testProjects
|> Array.map (fun fsproj -> fsproj.FullName)
|> Array.iter (DotNet.test id)
)
Target.create "Projects" (fun _ ->
projects
|> Array.map (fun project -> project.FullName)
|> Array.iter Trace.log
)
Target.create "NuGet" (fun _ ->
srcProjects
|> Array.map (fun project -> project.FullName)
|> Array.iter (
fun project ->
DotNet.pack (
fun options ->
{options with Configuration = DotNet.BuildConfiguration.Release}
) project
)
)
let getProjectFiles (project: FileInfo) =
project.Directory
|> DirectoryInfo.getMatchingFilesRecursive "*.fs"
let isEmptyLine line = String.trim line = ""
let countLOC (file: FileInfo) =
File.read file.FullName
|> Seq.filter (not << isEmptyLine)
|> Seq.length
Target.create "CountLOC" (fun _ ->
srcProjects
|> Array.collect getProjectFiles
|> Array.map countLOC
|> Array.sum
|> Trace.logf "LOC: %i\n"
)
open Fake.Core.TargetOperators
"Build" ==> "Nuget"
Target.runOrDefault "Build"