@@ -19,6 +19,16 @@ let summary = "FsToolkit.ErrorHandling is a utility library to work with the Res
1919let configuration = " Release"
2020let solutionFile = " FsToolkit.ErrorHandling.sln"
2121
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+
2232let gitOwner = " demystifyfp"
2333
2434let distDir = __ SOURCE_ DIRECTORY__ @@ " bin"
@@ -31,6 +41,63 @@ let nugetToken = Environment.environVarOrNone "NUGET_TOKEN"
3141Option.iter( TraceSecrets.register " <NUGET_TOKEN>" )
3242
3343
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+
34101Target.create " Clean" ( fun _ ->
35102 !! " bin"
36103 ++ " src/**/bin"
@@ -151,6 +218,10 @@ Target.create "NuGet" (fun _ ->
151218 ( " PackageReleaseNotes" , releaseNotes)]}}))
152219)
153220
221+
222+ Target.create " FormatCode" formatCode
223+ Target.create " CheckFormatCode" checkFormatCode
224+
154225Target.create " PublishNuget" ( fun _ ->
155226 Paket.push( fun p ->
156227 { p with
@@ -206,6 +277,7 @@ Target.create "UpdateDocs" (fun _ ->
206277 ==> " AssemblyInfo"
207278 ==> " Restore"
208279 ==> " NpmRestore"
280+ ==> " CheckFormatCode"
209281 ==> " Build"
210282 ==> " RunTests"
211283 ==> " RunFableTests"
0 commit comments