forked from fable-compiler/Fable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.fsx
208 lines (177 loc) · 6.82 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#r "packages/FAKE/tools/FakeLib.dll"
open System
open System.IO
open System.Text.RegularExpressions
open Fake
// version info
let version = "0.2.12"
module Util =
open System.Net
let join pathParts =
Path.Combine(Array.ofSeq pathParts)
let run workingDir fileName args =
let ok =
execProcess (fun info ->
info.FileName <- fileName
info.WorkingDirectory <- workingDir
info.Arguments <- args) TimeSpan.MaxValue
if not ok then failwith (sprintf "'%s> %s %s' task failed" workingDir fileName args)
let downloadArtifact path =
let url = "https://ci.appveyor.com/api/projects/alfonsogarciacaro/fable/artifacts/build/fable.zip"
let tempFile = Path.ChangeExtension(Path.GetTempFileName(), ".zip")
use client = new WebClient()
use stream = client.OpenRead(url)
use writer = new StreamWriter(tempFile)
stream.CopyTo(writer.BaseStream)
FileUtils.mkdir path
CleanDir path
run path "unzip" (sprintf "-q %s" tempFile)
File.Delete tempFile
let rmdir dir =
if EnvironmentHelper.isUnix
then FileUtils.rm_rf dir
// Use this in Windows to prevent conflicts with paths too long
else run "." "cmd" ("/C rmdir /s /q " + Path.GetFullPath dir)
/// Reads a file line by line and rewrites it using unix line breaks
/// - uses a temp file to store the contents in order to prevent OutOfMemory exceptions
let convertFileToUnixLineBreaks(fileName : string) =
use reader = new StreamReader(fileName, encoding)
let tempFileName = Path.GetTempFileName()
use writer = new StreamWriter(tempFileName, false, encoding)
while not reader.EndOfStream do
writer.Write (reader.ReadLine() + "\n")
reader.Close()
writer.Close()
File.Delete(fileName)
File.Move(tempFileName, fileName)
module Npm =
let npmFilePath args =
if EnvironmentHelper.isUnix
then "npm", args
else "cmd", ("/C npm " + args)
let script workingDir script args =
sprintf "run %s -- %s" script (String.concat " " args)
|> npmFilePath ||> Util.run workingDir
let install workingDir modules =
sprintf "install %s" (String.concat " " modules)
|> npmFilePath ||> Util.run workingDir
let command workingDir command args =
sprintf "%s %s" command (String.concat " " args)
|> npmFilePath ||> Util.run workingDir
module Node =
let run workingDir script args =
let args = sprintf "%s %s" script (String.concat " " args)
Util.run workingDir "node" args
// Directories
let fableBuildDir = Util.join ["build";"fable";"bin"]
let testsBuildDir = Util.join ["build";"tests"]
let pluginsBuildDir = Util.join ["build";"plugins"]
// Targets
Target "Clean" (fun _ ->
!! fableBuildDir ++ pluginsBuildDir
++ "src/**/bin/" ++ "src/**/obj/"
|> CleanDirs
// Exclude node_modules
!! "build/fable/**/*.*" -- "build/fable/node_modules/**/*.*"
|> Seq.iter FileUtils.rm
!! "build/tests/**/*.*" -- "build/tests/node_modules/**/*.*"
|> Seq.iter FileUtils.rm
)
Target "FableRelease" (fun _ ->
let xmlPath = Path.Combine(Path.GetFullPath fableBuildDir, "Fable.xml")
!! "src/fable-fsharp/Fable.fsproj"
|> MSBuild fableBuildDir "Build"
["Configuration","Release"; "DocumentationFile", xmlPath]
|> Log "Release-Output: "
// For some reason, ProjectCracker targets are not working after updating the package
!! "packages/FSharp.Compiler.Service.ProjectCracker/utilities/net45/FSharp.Compiler.Service.ProjectCrackerTool.exe*"
|> Seq.iter (fun x -> FileUtils.cp x "build/fable/bin")
)
Target "FableDebug" (fun _ ->
!! "src/fable-fsharp/Fable.fsproj"
|> MSBuildDebug fableBuildDir "Build"
|> Log "Debug-Output: "
let targetDir = "build/fable"
FileUtils.cp_r "src/fable-js" targetDir
Npm.command targetDir "version" [version]
)
Target "FableJs" (fun _ ->
let targetDir = "build/fable"
FileUtils.cp_r "src/fable-js" targetDir
FileUtils.cp "README.md" targetDir
Npm.command targetDir "version" [version]
Npm.install targetDir []
)
Target "NUnitTest" (fun _ ->
!! "src/tests/Fable.Tests.fsproj"
|> MSBuildRelease testsBuildDir "Build"
|> Log "Release-Output: "
[Path.Combine(testsBuildDir, "Fable.Tests.dll")]
|> NUnit (fun p -> { p with DisableShadowCopy = true
OutputFile = Path.Combine(testsBuildDir, "TestResult.xml") })
)
Target "MochaTest" (fun _ ->
Node.run "." "build/fable" ["src/tests/Other"]
Node.run "." "build/fable" ["src/tests/"]
FileUtils.cp "src/tests/package.json" testsBuildDir
Npm.install testsBuildDir []
// Copy the development version of fable-core.js
if environVar "DEV_MACHINE" = "1" then
FileUtils.cp "import/core/fable-core.js" "build/tests/node_modules/fable-core/"
Npm.script testsBuildDir "test" []
)
Target "Plugins" (fun _ ->
CreateDir pluginsBuildDir
[ "src/plugins/Fable.Plugins.NUnit.fsx"; "src/plugins/Fable.Plugins.VisualStudio.UnitTests.fsx"; "src/plugins/Fable.Plugins.BitwiseWrap.fsx" ]
|> Seq.iter (fun fsx ->
let dllFile = Path.ChangeExtension(Path.GetFileName fsx, ".dll")
[fsx]
|> FscHelper.compile [
FscHelper.Out (Path.Combine(pluginsBuildDir, dllFile))
FscHelper.Target FscHelper.TargetType.Library
]
|> function 0 -> () | _ -> failwithf "Cannot compile %s" fsx)
)
Target "MakeArtifactLighter" (fun _ ->
Util.rmdir "build/fable/node_modules"
!! "build/fable/bin/*.pdb" ++ "build/fable/bin/*.xml"
|> Seq.iter FileUtils.rm
)
Target "Publish" (fun _ ->
let workingDir = "temp/build"
Util.downloadArtifact workingDir
Util.convertFileToUnixLineBreaks (Path.Combine(workingDir, "index.js"))
// Npm.command workingDir "version" [version]
Npm.command workingDir "publish" []
)
Target "Import" (fun _ ->
Util.run "." "uglifyjs" "import/core/fable-core.js -c -m -o import/core/fable-core.min.js"
!! "import/core/Fable.Core.fsproj"
|> MSBuildRelease "import/core" "Build"
|> Log "Import-Output: "
)
Target "Samples" (fun _ ->
let fableDir = Util.join ["build";"fable"] |> Path.GetFullPath
!! "samples/**/out/" |> CleanDirs
!! "samples/**/fableconfig.json"
|> Seq.iter (fun path ->
let pathDir = Path.GetDirectoryName path
Node.run pathDir fableDir [])
)
Target "LineCount" (fun _ ->
!! "src/fable-fsharp/**/*.fs"
|> Seq.map (File.ReadLines >> Seq.length)
|> Seq.sum
|> printfn "Line count: %i"
)
Target "All" ignore
// Build order
"Clean"
==> "FableRelease"
==> "FableJs"
==> "Plugins"
==> "MochaTest"
=?> ("MakeArtifactLighter", environVar "APPVEYOR" = "True")
==> "All"
// Start build
RunTargetOrDefault "All"