@@ -19,6 +19,16 @@ let summary = "FsToolkit.ErrorHandling is a utility library to work with the Res
19
19
let configuration = " Release"
20
20
let solutionFile = " FsToolkit.ErrorHandling.sln"
21
21
22
+ let srcCodeGlob =
23
+ !! (__ SOURCE_ DIRECTORY__ </> " src/**/*.fs" )
24
+ ++ (__ SOURCE_ DIRECTORY__ </> " src/**/*.fsx" )
25
+ -- (__ SOURCE_ DIRECTORY__ </> " src/**/obj/**/*.fs" )
26
+
27
+ let testsCodeGlob =
28
+ !! (__ SOURCE_ DIRECTORY__ </> " tests/**/*.fs" )
29
+ ++ (__ SOURCE_ DIRECTORY__ </> " tests/**/*.fsx" )
30
+ -- (__ SOURCE_ DIRECTORY__ </> " tests/**/obj/**/*.fs" )
31
+
22
32
let gitOwner = " demystifyfp"
23
33
24
34
let distDir = __ SOURCE_ DIRECTORY__ @@ " bin"
@@ -31,6 +41,63 @@ let nugetToken = Environment.environVarOrNone "NUGET_TOKEN"
31
41
Option.iter( TraceSecrets.register " <NUGET_TOKEN>" )
32
42
33
43
44
+
45
+ let failOnBadExitAndPrint ( p : ProcessResult ) =
46
+ if p.ExitCode <> 0 then
47
+ p.Errors |> Seq.iter Trace.traceError
48
+ failwithf " failed with exitcode %d " p.ExitCode
49
+ module dotnet =
50
+ let watch cmdParam program args =
51
+ DotNet.exec cmdParam ( sprintf " watch %s " program) args
52
+
53
+ let run cmdParam args =
54
+ DotNet.exec cmdParam " run" args
55
+
56
+ let tool optionConfig command args =
57
+ DotNet.exec optionConfig ( sprintf " %s " command) args
58
+ |> failOnBadExitAndPrint
59
+
60
+ let fantomas args =
61
+ DotNet.exec id " fantomas" args
62
+
63
+
64
+ let formatCode _ =
65
+ let result =
66
+ [
67
+ srcCodeGlob
68
+ testsCodeGlob
69
+ ]
70
+ |> Seq.collect id
71
+ // Ignore AssemblyInfo
72
+ |> Seq.filter( fun f -> f.EndsWith( " AssemblyInfo.fs" ) |> not )
73
+ |> String.concat " "
74
+ |> dotnet.fantomas
75
+
76
+ if not result.OK then
77
+ printfn " Errors while formatting all files: %A " result.Messages
78
+
79
+
80
+ let checkFormatCode _ =
81
+ let result =
82
+ [
83
+ srcCodeGlob
84
+ testsCodeGlob
85
+ ]
86
+ |> Seq.collect id
87
+ // Ignore AssemblyInfo
88
+ |> Seq.filter( fun f -> f.EndsWith( " AssemblyInfo.fs" ) |> not )
89
+ |> String.concat " "
90
+ |> sprintf " %s --check"
91
+ |> dotnet.fantomas
92
+
93
+ if result.ExitCode = 0 then
94
+ Trace.log " No files need formatting"
95
+ elif result.ExitCode = 99 then
96
+ failwith " Some files need formatting, check output for more info"
97
+ else
98
+ Trace.logf " Errors while formatting: %A " result.Errors
99
+
100
+
34
101
Target.create " Clean" ( fun _ ->
35
102
!! " bin"
36
103
++ " src/**/bin"
@@ -151,6 +218,10 @@ Target.create "NuGet" (fun _ ->
151
218
( " PackageReleaseNotes" , releaseNotes)]}}))
152
219
)
153
220
221
+
222
+ Target.create " FormatCode" formatCode
223
+ Target.create " CheckFormatCode" checkFormatCode
224
+
154
225
Target.create " PublishNuget" ( fun _ ->
155
226
Paket.push( fun p ->
156
227
{ p with
@@ -206,6 +277,7 @@ Target.create "UpdateDocs" (fun _ ->
206
277
==> " AssemblyInfo"
207
278
==> " Restore"
208
279
==> " NpmRestore"
280
+ ==> " CheckFormatCode"
209
281
==> " Build"
210
282
==> " RunTests"
211
283
==> " RunFableTests"
0 commit comments