forked from nikitalita/cwtools-vscode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.fsx
244 lines (196 loc) · 8.44 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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
// --------------------------------------------------------------------------------------
// FAKE build script
// --------------------------------------------------------------------------------------
// #I "packages/build/FAKE/tools"
// #r "FakeLib.dll"
// #r "paket: groupref build //"
// cache .././nupkgs versions: current
#r "paket:
nuget Fake.Core
nuget Fake.Core.Target
nuget Fake.IO.FileSystem
nuget Fake.DotNet.Cli
nuget Fake.DotNet.Paket
nuget Fake.JavaScript.Npm
nuget Fake.Core.UserInput //"
#load "./.fake/build.fsx/intellisense.fsx"
open System.Diagnostics
open Fake.Core
open Fake.DotNet
open Fake.JavaScript
open Fake.IO
open Fake.IO.Globbing.Operators
// open Fake.BuildServer
// BuildServer.install [ GitLab.Installer ]
let run cmd args dir =
if Process.execSimple( fun info ->
let info = { info with FileName = cmd; Arguments = args }
if not( String.isNullOrWhiteSpace dir) then
{ info with WorkingDirectory = dir } else info
) System.TimeSpan.MaxValue <> 0 then
failwithf "Error while running '%s' with args: %s" cmd args
let platformTool tool path =
match Environment.isUnix with
| true -> tool
| _ -> match Process.tryFindFileOnPath path with
| None -> failwithf "can't find tool %s on PATH" tool
| Some v -> v
let npmTool =
platformTool "npm" "npm.cmd"
let vsceTool = lazy (platformTool "vsce" "vsce.cmd")
let releaseBin = "release/bin"
let fsacBin = "paket-files/github.com/fsharp/FsAutoComplete/bin/release"
let releaseBinNetcore = releaseBin + "_netcore"
let fsacBinNetcore = fsacBin + "_netcore"
let cwtoolsPath = ""
let cwtoolsProjectName = "Main.fsproj"
let cwtoolsLinuxProjectName = "Main.Linux.fsproj"
// --------------------------------------------------------------------------------------
// Build the Generator project and run it
// --------------------------------------------------------------------------------------
Target.create "Clean" (fun _ ->
Shell.cleanDir "./temp"
Shell.cleanDir "./out/server"
Shell.cleanDir "./out/client"
// CopyFiles "release" ["README.md"; "LICENSE.md"]
// CopyFile "release/CHANGELOG.md" "RELEASE_NOTES.md"
)
Target.create "YarnInstall" <| fun _ ->
Npm.install id
Target.create "DotNetRestore" <| fun _ ->
DotNet.restore (fun p -> { p with Common = { p.Common with WorkingDirectory = "src/Main" }} ) cwtoolsProjectName
DotNet.restore (fun p -> { p with Common = { p.Common with WorkingDirectory = "src/Main" }} ) cwtoolsLinuxProjectName
let publishParams (framework : string) (release : bool) =
(fun (p : DotNet.PublishOptions) ->
{ p with
Common =
{
p.Common with
WorkingDirectory = "src/Main"
CustomParams = Some ("--self-contained true" + (if release then " " else " /p:LinkDuringPublish=false"))
}
OutputPath = Some ("../../out/server/" + framework)
Runtime = Some framework
Configuration = DotNet.BuildConfiguration.Release
})
let buildParams (release : bool) =
(fun (b : DotNet.BuildOptions) ->
{ b with
Common =
{
b.Common with
WorkingDirectory = "src/Main"
CustomParams = Some ((if release then "" else " /p:LinkDuringPublish=false"))
}
OutputPath = Some ("../../out/server/local")
Configuration = if release then DotNet.BuildConfiguration.Release else DotNet.BuildConfiguration.Debug
})
Target.create "BuildDll" <| fun _ ->
DotNet.build (buildParams true) cwtoolsProjectName
Target.create "BuildServer" <| fun _ ->
match Environment.isWindows with
|true -> DotNet.publish (publishParams "win-x64" false) cwtoolsProjectName
|false -> DotNet.publish (publishParams "linux-x64" false) cwtoolsLinuxProjectName
// DotNetCli.Publish (fun p -> {p with WorkingDir = "src/Main"; AdditionalArgs = ["--self-contained"; "true"; "/p:LinkDuringPublish=false"]; Output = "../../out/server/win-x64"; Runtime = "win-x64"; Configuration = "Release"})
// DotNet.publish (publishParams "linux-x64" false) cwtoolsProjectName //(fun p -> {p with Common = { p.Common with WorkingDirectory = "src/Main"; CustomParams = Some "--self-contained true /p:LinkDuringPublish=false";}; OutputPath = Some "../../out/server/linux-x64"; Runtime = Some "linux-x64"; Configuration = DotNet.BuildConfiguration.Release }) cwtoolsProjectName
Target.create "PublishServer" <| fun _ ->
DotNet.publish (publishParams "win-x64" true) cwtoolsProjectName
DotNet.publish (publishParams "linux-x64" true) cwtoolsLinuxProjectName
DotNet.publish (publishParams "osx.10.11-x64" true) cwtoolsProjectName
let runTsc additionalArgs noTimeout =
let cmd = "tsc"
// let timeout = if noTimeout then System.TimeSpan.MaxValue else System.TimeSpan.FromMinutes 30.
run cmd additionalArgs ""
Target.create "RunScript" (fun _ ->
match Process.tryFindFileOnPath "tsc" with
|Some tsc -> Process.directExec (fun (p : ProcStartInfo) -> p.WithFileName(tsc).WithArguments("-p ./tsconfig.extension.json")) |> ignore
|_ -> ()
match Process.tryFindFileOnPath "rollup" with
|Some tsc -> Process.directExec (fun (p : ProcStartInfo) -> p.WithFileName(tsc).WithArguments("-c -o ./out/client/webview/graph.js") ) |> ignore
|_ -> ()
// Process.directExec (fun (p : ProcStartInfo) -> p.WithFileName("tsc").WithLoadUserProfile(true).WithUseShellExecute(false)) |> ignore
)
Target.create "CopyHtml" (fun _ ->
!!("client/webview/*.css")
|> Shell.copyFiles "out/client/webview"
)
// Target "Watch" (fun _ ->
// runFable "--watch" true
// )
// Target "CompileTypeScript" (fun _ ->
// // !! "**/*.ts"
// // |> TypeScriptCompiler (fun p -> { p with OutputPath = "./out/client", Projec })
// //let cmd = "tsc -p ./"
// //DotNetCli.RunCommand id cmd
// ExecProcess (fun p -> p. <- "tsc" ;p.Arguments <- "-p ./") (TimeSpan.FromMinutes 5.0) |> ignore
// )
Target.create "PaketRestore" (fun _ ->
Shell.replaceInFiles ["../cwtools",Path.getFullName("../cwtools")] ["paket.lock"]
// match Environment.isWindows with
// |true -> Paket.restore (fun _ -> Paket.PaketRestoreDefaults())
// |_ -> Shell.Exec( "mono", @"./.paket/paket.exe restore") |> ignore
Paket.restore (fun _ -> Paket.PaketRestoreDefaults())
// Paket.PaketRestoreDefaults |> ignore
Shell.replaceInFiles [Path.getFullName("../cwtools"),"../cwtools"] ["paket.lock"]
)
Target.create "CopyFSAC" (fun _ ->
Directory.ensure releaseBin
Shell.cleanDir releaseBin
!!(fsacBin + "/*")
|> Shell.copyFiles releaseBin
)
Target.create "CopyFSACNetcore" (fun _ ->
Directory.ensure releaseBinNetcore
Shell.cleanDir releaseBinNetcore
Shell.copyDir releaseBinNetcore fsacBinNetcore (fun _ -> true)
)
Target.create "InstallVSCE" ( fun _ ->
Process.killAllByName "npm"
run npmTool "install -g vsce" ""
)
Target.create "BuildPackage" ( fun _ ->
Process.killAllByName "vsce"
run vsceTool.Value "package" ""
Process.killAllByName "vsce"
!!("*.vsix")
|> Seq.iter(Shell.moveFile "./temp/")
)
Target.create "PublishToGallery" ( fun _ ->
let token =
match Environment.environVarOrDefault "VSCE_TOKEN" System.String.Empty with
| s when not (String.isNullOrWhiteSpace s) -> s
| _ -> UserInput.getUserPassword "VSCE Token: "
Process.killAllByName "vsce"
run vsceTool.Value (sprintf "publish patch -p %s" token) ""
)
// --------------------------------------------------------------------------------------
// Run generator by default. Invoke 'build <Target>' to override
// --------------------------------------------------------------------------------------
Target.create "QuickBuild" ignore
Target.create "Build" ignore
Target.create "Release" ignore
Target.create "DryRelease" ignore
open Fake.Core.TargetOperators
"CopyHtml" ==> "QuickBuild"
"RunScript" ==> "QuickBuild"
"BuildDll" ==> "QuickBuild"
"Clean"
==> "BuildServer"
==> "Build"
"Clean" ?=> "RunScript"
"Clean" ?=> "CopyHtml"
"Clean" ?=> "BuildDll"
"CopyHtml" ==> "BuildPackage"
"RunScript" ==> "Build"
"RunScript" ==> "PublishServer"
//"PaketRestore" ==> "BuildServer"
//"PaketRestore" ==> "PublishServer"
"Clean"
==> "PublishServer"
==> "BuildPackage"
==> "PublishToGallery"
==> "Release"
"PublishServer"
==>"BuildPackage"
==> "DryRelease"
Target.runOrDefaultWithArguments "Build"