forked from jgrund/fable-react_native-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.fsx
More file actions
139 lines (109 loc) · 4.42 KB
/
Copy pathbuild.fsx
File metadata and controls
139 lines (109 loc) · 4.42 KB
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
// --------------------------------------------------------------------------------------
// FAKE build script
// --------------------------------------------------------------------------------------
#r @"packages/build/FAKE/tools/FakeLib.dll"
open System
open System.Diagnostics
open System.IO
open Fake
open Fake.Git
open Fake.ProcessHelper
open Fake.ReleaseNotesHelper
open Fake.ZipHelper
// Read additional information from the release notes document
let releaseNotes = File.ReadAllLines "RELEASE_NOTES.md"
let releaseNotesData =
releaseNotes
|> parseAllReleaseNotes
let deployDir = "./deploy"
let release = List.head releaseNotesData
let msg = release.Notes |> List.fold (fun r s -> r + s + "\n") ""
let releaseMsg = (sprintf "Release %s\n" release.NugetVersion) + msg
let run cmd args dir =
if execProcess( fun info ->
info.FileName <- cmd
if not( String.IsNullOrWhiteSpace dir) then
info.WorkingDirectory <- dir
info.Arguments <- args
) System.TimeSpan.MaxValue |> not then
failwithf "Error while running '%s' with args: %s" cmd args
let platformTool tool path =
isUnix |> function | true -> tool | _ -> path
let nodePath = @"C:\Program Files\nodejs\node.exe" |> FullName
let npmTool = platformTool "npm" (@"C:\Program Files\nodejs\npm.cmd" |> FullName)
let fableTool = platformTool "fable" ("node_modules" </> ".bin" </> "fable.cmd" |> FullName)
let gradleTool = platformTool "android/gradlew" ("android" </> "gradlew.bat" |> FullName)
let reactNativeTool = platformTool "react-native" ("node_modules" </> ".bin" </> "react-native.cmd" |> FullName)
let scpTool = @"C:\Program Files (x86)\Git\usr\bin\scp.exe"
let sshTool = @"C:\Program Files (x86)\Git\usr\bin\ssh.exe"
let androidSDKPath =
let p1 = ProgramFilesX86 </> "Android" </> "android-sdk"
if Directory.Exists p1 then FullName p1 else
let p2 = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) </> "Android" </> "sdk"
if Directory.Exists p2 then FullName p2 else
failwithf "Can't find Android SDK in %s or %s" p1 p2
Target "Clean" (fun _ ->
CleanDir deployDir
)
Target "NPMInstall" (fun _ ->
setEnvironVar "ANDROID_HOME" androidSDKPath
run npmTool "install" ""
)
Target "SetVersionAndroid" (fun _ ->
let fileName = "./android/app/build.gradle"
let v = SemVerHelper.parse release.NugetVersion
let lines =
File.ReadAllLines fileName
|> Seq.map (fun line ->
if line.TrimStart().StartsWith("versionCode ") then
let currentVersionCode = line.Replace("versionCode","").Trim() |> int
let indent = line.Substring(0,line.IndexOf("versionCode"))
sprintf "%sversionCode %d" indent (currentVersionCode + 1)
elif line.TrimStart().StartsWith("versionName ") then
let indent = line.Substring(0,line.IndexOf("versionName"))
sprintf "%sversionName \"%O\"" indent release.NugetVersion
else line)
File.WriteAllLines(fileName,lines)
)
Target "SetVersion" (fun _ ->
let fileName = "./package.json"
let lines =
File.ReadAllLines fileName
|> Seq.map (fun line ->
if line.TrimStart().StartsWith("\"version\":") then
let indent = line.Substring(0,line.IndexOf("\""))
sprintf "%s\"version\": \"%O\"," indent release.NugetVersion
else line)
File.WriteAllLines(fileName,lines)
)
Target "Build" (fun _ ->
if buildServer = BuildServer.GitLabCI then
let newPATH = environVar "PATH" + @";C:\Program Files (x86)\Microsoft F#\v4.0"
setEnvironVar "PATH" newPATH
run fableTool "--verbose --symbols PRODUCTION" ""
run gradleTool "assembleRelease" "android"
let outFile = "android" </> "app" </> "build" </> "outputs" </> "apk" </> "app-release-unsigned.apk"
Copy deployDir [outFile]
let fi = FileInfo (deployDir </> "app-release-unsigned.apk")
fi.MoveTo (deployDir </> sprintf "Nightwatch.%s.apk" release.NugetVersion)
)
Target "Debug" (fun _ ->
run fableTool "" ""
run reactNativeTool "run-android" ""
Process.Start("chrome.exe","http://localhost:8081/debugger-ui") |> ignore
run fableTool "--watch" ""
)
Target "Deploy" (fun _ ->
() // TODO:
)
Target "Default" DoNothing
"Clean"
==> "NPMInstall"
==> "SetVersion"
==> "SetVersionAndroid"
==> "Build"
==> "Default"
==> "Deploy"
"SetVersion"
==> "Debug"
RunTargetOrDefault "Default"