This repository has been archived by the owner on Apr 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.fsx
133 lines (108 loc) · 4.01 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
// include Fake libs
#r "./packages/FAKE/tools/FakeLib.dll"
#r "System.IO.Compression.FileSystem"
open System
open System.IO
open Fake
open Fake.NpmHelper
let yarn =
if EnvironmentHelper.isWindows then "yarn.cmd" else "yarn"
|> ProcessHelper.tryFindFileOnPath
|> function
| Some yarn -> yarn
| ex -> failwith ( sprintf "yarn not found (%A)\n" ex )
// Directories
let buildDir = "./build/"
// Filesets
let projects =
!! "src/package.json"
++ "src/*/*.fsproj"
let dotnetcliVersion = "1.0.1"
let mutable dotnetExePath = "dotnet"
let runDotnet workingDir args =
printfn "CWD: %s" workingDir
// printfn "dotnet %s" args
let result =
ExecProcess (fun info ->
info.FileName <- dotnetExePath
info.WorkingDirectory <- workingDir
info.Arguments <- args) TimeSpan.MaxValue
if result <> 0 then failwithf "Command failed: dotnet %s" args
Target "InstallDotNetCore" (fun _ ->
let dotnetSDKPath = FullName "./dotnetsdk"
let correctVersionInstalled =
try
let processResult =
ExecProcessAndReturnMessages (fun info ->
info.FileName <- dotnetExePath
info.WorkingDirectory <- Environment.CurrentDirectory
info.Arguments <- "--version") (TimeSpan.FromMinutes 30.)
processResult.Messages |> separated "" = dotnetcliVersion
with
| _ -> false
if correctVersionInstalled then
tracefn "dotnetcli %s already installed" dotnetcliVersion
else
CleanDir dotnetSDKPath
let archiveFileName =
if isWindows then
sprintf "dotnet-dev-win-x64.%s.zip" dotnetcliVersion
elif isLinux then
sprintf "dotnet-dev-ubuntu-x64.%s.tar.gz" dotnetcliVersion
else
sprintf "dotnet-dev-osx-x64.%s.tar.gz" dotnetcliVersion
let downloadPath =
sprintf "https://dotnetcli.azureedge.net/dotnet/Sdk/%s/%s" dotnetcliVersion archiveFileName
let localPath = Path.Combine(dotnetSDKPath, archiveFileName)
tracefn "Installing '%s' to '%s'" downloadPath localPath
use webclient = new Net.WebClient()
webclient.DownloadFile(downloadPath, localPath)
if not isWindows then
let assertExitCodeZero x =
if x = 0 then () else
failwithf "Command failed with exit code %i" x
Shell.Exec("tar", sprintf """-xvf "%s" -C "%s" """ localPath dotnetSDKPath)
|> assertExitCodeZero
else
Compression.ZipFile.ExtractToDirectory(localPath, dotnetSDKPath)
tracefn "dotnet cli path - %s" dotnetSDKPath
System.IO.Directory.EnumerateFiles dotnetSDKPath
|> Seq.iter (fun path -> tracefn " - %s" path)
System.IO.Directory.EnumerateDirectories dotnetSDKPath
|> Seq.iter (fun path -> tracefn " - %s%c" path System.IO.Path.DirectorySeparatorChar)
dotnetExePath <- dotnetSDKPath </> (if isWindows then "dotnet.exe" else "dotnet")
// let oldPath = System.Environment.GetEnvironmentVariable("PATH")
// System.Environment.SetEnvironmentVariable("PATH", sprintf "%s%s%s" dotnetSDKPath (System.IO.Path.PathSeparator.ToString()) oldPath)
)
Target "Install" (fun _ ->
projects
|> Seq.iter (fun s ->
let dir = IO.Path.GetDirectoryName s
printf "Installing: %s\n" dir
Npm (fun p ->
{ p with
NpmFilePath = yarn
Command = Install Standard
WorkingDirectory = dir
})
if !! (Path.Combine (dir,"*.fsproj")) |> Seq.isEmpty |> not then runDotnet dir "restore"
)
)
// Targets
Target "Clean" (fun _ ->
CleanDirs [buildDir]
)
Target "Build" (fun _ ->
projects
|> Seq.iter (fun s ->
let dir = IO.Path.GetDirectoryName s
runDotnet dir "build")
)
Target "All" ignore
// Build order
"Clean"
==> "InstallDotNetCore"
==> "Install"
==> "Build"
// start build
RunTargetOrDefault "Build"