-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.fsx
More file actions
138 lines (114 loc) · 5.13 KB
/
Copy pathbuild.fsx
File metadata and controls
138 lines (114 loc) · 5.13 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
// --------------------------------------------------------------------------------------
// Build script — plain F# / dotnet fsi (no FAKE dependency)
// Run with: dotnet fsi build.fsx [target]
// Targets: Clean, BuildSetup, Build, RunXTS, Zip (default: Zip)
// --------------------------------------------------------------------------------------
open System
open System.IO
open System.IO.Compression
open System.Diagnostics
Environment.CurrentDirectory <- __SOURCE_DIRECTORY__
let getGitTag () =
let psi = ProcessStartInfo(fileName = "git", arguments = "describe --tags --abbrev=0")
psi.RedirectStandardOutput <- true
psi.UseShellExecute <- false
let p: Process = Process.Start(psi)
let output = p.StandardOutput.ReadToEnd().Trim()
p.WaitForExit()
if p.ExitCode <> 0 || output = "" then failwith "Could not read git tag. Make sure a tag exists."
output
// --------------------------------------------------------------------------------------
// Helpers
// --------------------------------------------------------------------------------------
let run exe args workDir =
let psi = ProcessStartInfo(fileName = exe, arguments = (args: string))
psi.WorkingDirectory <- workDir
psi.UseShellExecute <- false
let p: Process = Process.Start(psi)
p.WaitForExit()
if p.ExitCode <> 0 then
failwithf $"'{exe} {args}' exited with code {p.ExitCode}"
let cleanDir dir =
if Directory.Exists dir then
Directory.Delete(dir, recursive = true)
Directory.CreateDirectory dir |> ignore
let copyFiles destDir (files: string seq) =
for f in files do
File.Copy(f, $"{destDir}/{Path.GetFileName f}", overwrite = true)
let zipDirectory (sourceDir: string) (zipFilePath: string) =
let sourceDirFull = Path.GetFullPath sourceDir
let zipFileFull = Path.GetFullPath zipFilePath
if File.Exists zipFileFull then File.Delete zipFileFull
let zipParent = Path.GetDirectoryName zipFileFull
if not (String.IsNullOrWhiteSpace zipParent) then
Directory.CreateDirectory zipParent |> ignore
ZipFile.CreateFromDirectory(sourceDirFull, zipFileFull, CompressionLevel.Optimal, includeBaseDirectory = false)
// --------------------------------------------------------------------------------------
// Targets
// --------------------------------------------------------------------------------------
let clean () =
for dir in [ "bin"; "temp"; "src/bin"; "test/typings/XRM" ] do
printfn $"Cleaning {dir}"
cleanDir dir
let buildSetup () =
let envInfoPath = Path.GetFullPath "src/EnvInfo.config"
if not (File.Exists envInfoPath) then
File.WriteAllLines(envInfoPath, [|
"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
"<appSettings>"
"</appSettings>"
|])
let build ver =
let args =
$"build XrmTypeScript.sln -c Release " +
$"-p:Version={ver} " +
"-p:NoWarn=NU5100"
run "dotnet" args Environment.CurrentDirectory
let runXts () =
let pathToRelease = Path.GetFullPath "src/bin/Release/net462"
let args =
[ "load", "../../../XdtData.json"
// "save", "../../../XdtData.json"
"out", "../../../../test/typings/XRM"
"web", "true"
"entities", "account,contact" ]
|> List.map (fun (k, v) -> $"-{k}:{v}")
|> String.concat " "
run $"{pathToRelease}/XrmTypeScript.exe" args pathToRelease
let zip tag =
let buildOutDir = "src/bin/Release/net462"
let stageDir = "temp/zipstage"
let libDir = $"{stageDir}/lib"
let zipPath = $"bin/XrmTypeScript-{tag}-bin.zip"
cleanDir stageDir
Directory.CreateDirectory libDir |> ignore
for f in [ "files/Run.ps1"; "files/Run.fsx"; "files/XrmTypeScript.exe.config" ] do
File.Copy(f, $"{stageDir}/{Path.GetFileName f}", overwrite = true)
let dlls = Directory.GetFiles(buildOutDir, "*.dll")
copyFiles libDir (dlls |> Array.filter (fun f -> Path.GetFileName f <> "FSharp.Core.dll"))
copyFiles stageDir (dlls |> Array.filter (fun f -> Path.GetFileName f = "FSharp.Core.dll"))
copyFiles stageDir (Directory.GetFiles(buildOutDir, "*.exe"))
File.Copy($"{buildOutDir}/XrmTypeScript.xml", $"{libDir}/XrmTypeScript.xml", overwrite = true)
zipDirectory stageDir zipPath
printfn "Created %s" (Path.GetFullPath zipPath)
Directory.Delete(stageDir, recursive = true)
// --------------------------------------------------------------------------------------
// Target dispatch
// --------------------------------------------------------------------------------------
let runTarget name =
printfn ""
printfn "=== %s ===" name
match name with
| "Clean" -> clean ()
| "BuildSetup" -> clean (); buildSetup ()
| "Build" -> clean (); buildSetup (); build "0.0.0"
| "RunXTS" -> clean (); buildSetup (); build "0.0.0"; runXts ()
| "Zip" ->
let tag = getGitTag ()
clean (); buildSetup (); build (tag.TrimStart 'v'); runXts (); zip tag
| other -> failwithf $"Unknown target: {other}"
let target =
match fsi.CommandLineArgs |> Array.toList with
| _ :: t :: _ -> t
| _ -> "Zip"
runTarget target