-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.fsx
More file actions
151 lines (126 loc) · 4.17 KB
/
build.fsx
File metadata and controls
151 lines (126 loc) · 4.17 KB
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
// include Fake lib
#I "packages/FAKE/tools/"
#r "FakeLib.dll"
open System
open System.IO
open Fake
open Fake.AssemblyInfoFile
open System.Diagnostics
let title = "FSharping.Website"
let project = "FSharping Website"
let summary = "Website source for fsharping.cz"
// Directories
let buildAppDir = "./build/app/"
let buildTestDir = "./build/tests/"
let appSrcDir = sprintf "./src/%s/" title
let testSrcDir = sprintf "./tests/%s.Tests/" title
// Read release notes & version info from RELEASE_NOTES.md
let release = File.ReadLines "RELEASE_NOTES.md" |> ReleaseNotesHelper.parseReleaseNotes
// Targets
Target "?" (fun _ ->
printfn " *********************************************************"
printfn " * Avaliable options (call 'build <Target>') *"
printfn " *********************************************************"
printfn " [Build]"
printfn " > BuildTests"
printfn " > BuildApp"
printfn " "
printfn " [Run]"
printfn " > RunTests"
printfn " > RunApp"
printfn " > RunAppWatcher"
printfn " "
printfn " [Help]"
printfn " > ?"
printfn " "
printfn " *********************************************************"
)
Target "AssemblyInfo" <| fun () ->
for file in !! (appSrcDir + "AssemblyInfo*.fs") do
let version = release.AssemblyVersion
CreateFSharpAssemblyInfo file
[ Attribute.Title title
Attribute.Product project
Attribute.Description summary
Attribute.Version version
Attribute.FileVersion version]
Target "CleanApp" (fun _ ->
CleanDir buildAppDir
)
Target "CleanTests" (fun _ ->
CleanDir buildAppDir
)
Target "PreBuildWww" (fun _ ->
let npm = tryFindFileOnPath (if isUnix then "npm" else "npm.cmd")
let errorCode = match npm with
| Some g -> Shell.Exec(g, "install", appSrcDir)
| None -> -1
()
)
Target "BuildWww" (fun _ ->
let gulp = tryFindFileOnPath (if isUnix then "npm" else "npm.cmd")
let errorCode = match gulp with
| Some g -> Shell.Exec(g, "run gulp", appSrcDir)
| None -> -1
()
)
Target "BuildApp" (fun _ ->
!! (appSrcDir + "**/*.fsproj")
|> MSBuildRelease buildAppDir "Build"
|> Log "AppBuild-Output: "
)
Target "BuildTests" (fun _ ->
!! (testSrcDir + "**/*.fsproj")
|> MSBuildDebug buildTestDir "Build"
|> Log "TestBuild-Output: "
)
Target "RunTests" (fun _ ->
!! (buildTestDir + sprintf "/%s.Tests.dll" title)
|> NUnit (fun p ->
{p with
DisableShadowCopy = true;
OutputFile = buildTestDir + "TestResults.xml" })
)
let runApp() =
execProcess (fun info ->
info.WorkingDirectory <- buildAppDir
info.FileName <- Path.Combine(buildAppDir, sprintf "%s.exe" title)
info.Arguments <- "") TimeSpan.MaxValue
let rec runAppWithWatcher() =
use watcher = new FileSystemWatcher(appSrcDir, "*.*")
watcher.EnableRaisingEvents <- true
watcher.IncludeSubdirectories <- true
watcher.Changed.Add(handleWatcherEvents)
watcher.Created.Add(handleWatcherEvents)
watcher.Renamed.Add(handleWatcherEvents)
let appRunning = runApp()
if not appRunning then tracefn "Application shut down."
watcher.Dispose()
and handleWatcherEvents (e:IO.FileSystemEventArgs) =
let killProcess = (fun _ -> Process.GetProcessesByName(title) |> Seq.iter (fun p -> p.Kill()))
match Path.GetExtension e.Name with
| ".fs" | ".fsx" ->
killProcess()
runSingleTarget (getTarget "BuildApp")
runAppWithWatcher()
| ".html" | ".js" | ".css" | ".json" | ".less" | ".md" ->
killProcess()
runSingleTarget (getTarget "BuildWww")
runAppWithWatcher()
| ".fsproj" -> ignore()
| _ -> ignore()
Target "RunApp" (fun _ ->
runApp() |> ignore
)
Target "RunAppWatcher" (fun _ ->
runAppWithWatcher()
)
// Dependencies
"PreBuildWww" ==> "BuildWww"
"CleanTests" ==> "BuildTests"
"CleanApp" ==> "AssemblyInfo" ==> "BuildWww" ==> "BuildApp"
"BuildApp" ==> "BuildTests" ==> "RunTests"
"BuildApp" ==> "RunApp"
"BuildApp" ==> "RunAppWatcher"
// start build
RunTargetOrDefault "?"