forked from ionide/ionide-atom-fsharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.fsx
116 lines (97 loc) · 4.22 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
// --------------------------------------------------------------------------------------
// FAKE build script
// --------------------------------------------------------------------------------------
#I "packages/FAKE/tools"
#r "packages/FAKE/tools/FakeLib.dll"
open System
open System.IO
open Fake
open Fake.Git
open Fake.ProcessHelper
open Fake.ZipHelper
#if MONO
#else
#load "src/atom-bindings.fsx"
#load "src/atom-extra.fs"
#load "src/core.fs"
#load "src/paket.fs"
#load "src/main.fs"
#endif
// --------------------------------------------------------------------------------------
// Build the Generator project and run it
// --------------------------------------------------------------------------------------
Target "BuildGenerator" (fun () ->
[ __SOURCE_DIRECTORY__ @@ "src" @@ "FSharp.Atom.Generator.fsproj" ]
|> MSBuildDebug "" "Rebuild"
|> Log "AppBuild-Output: "
)
Target "RunGenerator" (fun () ->
(TimeSpan.FromMinutes 5.0)
|> ProcessHelper.ExecProcess (fun p ->
p.FileName <- __SOURCE_DIRECTORY__ @@ "src" @@ "bin" @@ "Debug" @@ "FSharp.Atom.Generator.exe" )
|> ignore
)
#if MONO
#else
Target "RunScript" (fun () ->
FSharp.Atom.Generator.translateModules()
)
#endif
// --------------------------------------------------------------------------------------
// Generate FunScript bindings from the *.d.ts files in the 'typings' folder
// --------------------------------------------------------------------------------------
let typings = __SOURCE_DIRECTORY__ @@ "typings"
let typesZip = typings @@ "FunScript.TypeScript" @@ "Types.zip"
let noInline = set [ "jquery.d.ts"; "node.d.ts"; "atom.d.ts" ]
let fsharpBin =
[ "/Library/Frameworks/Mono.framework/Versions/3.10.0/lib/mono/4.0"
(* TODO: This needs to list many more locations where fsc.exe can be? *) ]
|> List.tryFind (fun p -> File.Exists(p @@ "fsc.exe"))
Target "GenerateBindings" (fun () ->
// Clean the 'temp' filder and 'Types.zip' file for FunScript
DeleteFile typesZip
CleanDir (typings @@ "temp")
// Get all definitions and their dependencies (and source code without <reference> tags)
let tsDefinitions =
let reg = System.Text.RegularExpressions.Regex("reference.*path=\"([^\"]*)\"") // "
let defs = Directory.EnumerateFiles(typings, "*.d.ts", SearchOption.AllDirectories)
[ for def in defs ->
let lines = File.ReadAllLines(def)
let deps, lines =
[ for line in lines do
let mtch = reg.Match(line)
if mtch.Success then
let depName = Path.GetFileName(mtch.Groups.[1].Value)
if not (noInline.Contains depName) then yield true, depName
else yield false, line ] |> List.partition fst
Path.GetFileName(def), List.map snd lines :> seq<_>, List.map snd deps ]
// Inline all dependencies, except for those that are in 'noInline' set
let sources = dict [ for fn, src, _ in tsDefinitions -> fn, src ]
for fn, src, deps in tsDefinitions do
if noInline.Contains fn then
let lines =
[| yield! src
for dep in deps do yield! sources.[dep] |]
File.WriteAllLines(typings @@ "temp" @@ fn, lines)
// ZIP everything in the temp folder (inlined definitions)
Directory.EnumerateFiles(typings @@ "temp", "*.d.ts")
|> CreateZip (typings @@ "temp") (typings @@ "FunScript.TypeScript" @@ "Types.zip") "" 1 false
CleanDir (typings @@ "temp")
// Set the FSHARP_BIN variable and run FunScript codegen!
fsharpBin |> Option.iter (fun fsharpBin ->
System.Environment.SetEnvironmentVariable("FSHARP_BIN", fsharpBin))
(TimeSpan.FromMinutes 15.0)
|> ProcessHelper.ExecProcess (fun p ->
p.FileName <- typings @@ "FunScript.TypeScript" @@ "FunScript.TypeScript.exe"
p.WorkingDirectory <- typings @@ "FunScript.TypeScript")
|> ignore
)
// --------------------------------------------------------------------------------------
// Run generator by default. Invoke 'build <Target>' to override
// --------------------------------------------------------------------------------------
#if MONO
"BuildGenerator" ==> "RunGenerator"
RunTargetOrDefault "RunGenerator"
#else
RunTargetOrDefault "RunScript"
#endif