-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.fsx
139 lines (114 loc) · 3.54 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
open Fake.Core
open Fake.Core
#r "paket: groupref build //"
#load "./.fake/build.fsx/intellisense.fsx"
#if !FAKE
#r "netstandard"
#r "Facades/netstandard" // https://github.com/ionide/ionide-vscode-fsharp/issues/839#issuecomment-396296095
#endif
open ASeward.MiscTools
open ASeward.MiscTools.ActivePatterns
open Fake.DotNet
open Fake.IO
open Fake.IO.Globbing.Operators
open Fake.Core.TargetOperators
open System
let appPath = Path.getFullName "./src/HabitsApp"
let migrationPath = Path.getFullName "./src/Migrations"
let deployDir = Path.getFullName "./deploy"
let private _getOrPromptAndSetRequiredEnvar name =
let rec promptIfNecessaryUntilProvided =
function
| Some str -> str
| None ->
Trace.traceImportantfn "Missing env var '%s'" name
Trace.tracef "Please provide a value now: "
Console.ReadLine ()
|> function
| NullOrWhiteSpace -> promptIfNecessaryUntilProvided None
| str -> str
let value =
name
|> Environment.environVar
|> Option.ofString
|> promptIfNecessaryUntilProvided
// Will be unnecessary in some cases but oh well for now
Environment.setEnvironVar name value
value
module Util =
let runDotNet cmd workingDir =
let result = DotNet.exec (DotNet.Options.withWorkingDirectory workingDir) cmd ""
if result.ExitCode <> 0 then failwithf "'dotnet %s' failed in %s" cmd workingDir
let runTool cmd args workingDir =
let result =
Process.execSimple (fun info ->
{ info with
FileName = cmd
WorkingDirectory = workingDir
Arguments = args })
TimeSpan.MaxValue
if result <> 0 then failwithf "'%s %s' failed" cmd args
let openBrowser url =
let result =
//https://github.com/dotnet/corefx/issues/10361
Process.execSimple (fun info ->
{ info with
FileName = url
UseShellExecute = true })
TimeSpan.MaxValue
if result <> 0 then failwithf "opening browser failed"
open Util
Target.create "Clean" (fun _ ->
!! "src/**/bin"
++ "src/**/obj"
++ deployDir
|> Shell.cleanDirs
)
Target.create "Build" (fun _ ->
!! "src/**/*.*proj"
|> Seq.iter (DotNet.build id)
)
Target.create "Run" (fun _ ->
let server = async {
runDotNet "watch run" appPath
}
let browser = async {
do! Async.Sleep 5000
openBrowser "http://localhost:8085"
}
[server; browser]
|> Async.Parallel
|> Async.RunSynchronously
|> ignore
)
Target.create "Bundle:Web" (fun _ ->
let appDeployDir = Path.combine deployDir "HabitsApp"
runDotNet (sprintf "publish -c Release -o \"%s\"" appDeployDir) appPath
)
Target.create "Bundle:Migrations" (fun _ ->
let migrationDeployDir = Path.combine deployDir "Migrations"
runDotNet (sprintf "publish -c Release -o \"%s\"" migrationDeployDir ) migrationPath
)
Target.create "Heroku:Web" (fun _ ->
let remote = _getOrPromptAndSetRequiredEnvar "HEROKU_REMOTE"
let heroku args = runTool "heroku" (sprintf "%s --remote=%s" args remote) "."
heroku "container:push web --recursive"
heroku "container:release web"
heroku "open"
)
Target.create "Heroku:Migrations" (fun _ ->
let remote = _getOrPromptAndSetRequiredEnvar "HEROKU_REMOTE"
let heroku args = runTool "heroku" (sprintf "%s --remote=%s" args remote) "."
heroku "container:push migrations --recursive"
heroku "container:release migrations"
heroku "run \"dotnet Migrations.dll\" --type=migrations"
)
"Clean"
==> "Build"
==> "Bundle:Web"
==> "Heroku:Web"
"Clean"
==> "Build"
==> "Bundle:Migrations"
==> "Heroku:Migrations"
Target.runOrList ()