From c12fa2df461ef2c5879ee7dada3497991ddff962 Mon Sep 17 00:00:00 2001 From: Florian Verdonck Date: Fri, 8 Oct 2021 11:24:03 +0200 Subject: [PATCH] Update FAKE sample to format out of process. Fixes #686. (#1911) --- fake-sample/.config/dotnet-tools.json | 8 +- fake-sample/README.md | 9 +- fake-sample/script.fsx | 56 ++++--- fake-sample/script.fsx.lock | 213 ++++++++++++++++++++------ 4 files changed, 211 insertions(+), 75 deletions(-) diff --git a/fake-sample/.config/dotnet-tools.json b/fake-sample/.config/dotnet-tools.json index 3dc104b041..7b12fabfe3 100644 --- a/fake-sample/.config/dotnet-tools.json +++ b/fake-sample/.config/dotnet-tools.json @@ -3,10 +3,16 @@ "isRoot": true, "tools": { "fake-cli": { - "version": "5.20.3", + "version": "5.20.4", "commands": [ "fake" ] + }, + "fantomas-tool": { + "version": "4.5.4", + "commands": [ + "fantomas" + ] } } } \ No newline at end of file diff --git a/fake-sample/README.md b/fake-sample/README.md index 6f9333b351..744c397b20 100644 --- a/fake-sample/README.md +++ b/fake-sample/README.md @@ -1,4 +1,4 @@ -# FAKE sample - .NET Core 3 +# FAKE sample 1. Restore FAKE locally: @@ -8,7 +8,12 @@ This was installed by: > dotnet new tool-manifest > dotnet tool install fake-cli +> dotnet tool install fantomas-tool 2. Execute script: -> dotnet fake run script.fsx -t Format \ No newline at end of file +> dotnet fake run script.fsx -t Format + +Check the format afterwards: + +> dotnet fake run script.fsx -t CheckFormat \ No newline at end of file diff --git a/fake-sample/script.fsx b/fake-sample/script.fsx index a5fdadeeef..440903232c 100644 --- a/fake-sample/script.fsx +++ b/fake-sample/script.fsx @@ -1,35 +1,43 @@ #r "paket: -nuget Fantomas.Extras 4.3.0 -nuget Fake.Core.Target //" +nuget Fake.Core.Target +nuget Fake.DotNet.Cli +nuget FSharp.Core 5.0.2 //" #load "./.fake/script.fsx/intellisense.fsx" open Fake.Core open Fake.IO open Fake.IO.Globbing.Operators -open Fantomas -open Fantomas.Extras -open Fantomas.FormatConfig +open Fake.DotNet -Target.create "CheckCodeFormat" (fun _ -> - let result = - !!"*.fs" - |> FakeHelpers.checkCode - |> Async.RunSynchronously +let sourceFiles = !! "*.fs" - if result.IsValid then - Trace.log "No files need formatting" - elif result.NeedsFormatting then - Trace.log "The following files need formatting:" - List.iter Trace.log result.Formatted - failwith "Some files need formatting, check output for more info" - else - Trace.logf "Errors while formatting: %A" result.Errors) +Target.create + "CheckFormat" + (fun _ -> + let result = + sourceFiles + |> Seq.map (sprintf "\"%s\"") + |> String.concat " " + |> sprintf "%s --check" + |> DotNet.exec id "fantomas" -Target.create "Format" (fun _ -> - !!"*.fs" - |> FakeHelpers.formatCode - |> Async.RunSynchronously - |> printfn "Formatted files: %A") + if result.ExitCode = 0 then + Trace.log "No files need formatting" + elif result.ExitCode = 99 then + failwith "Some files need formatting, check output for more info" + else + Trace.logf "Errors while formatting: %A" result.Errors) -Target.runOrList() +Target.create + "Format" + (fun _ -> + let result = + sourceFiles + |> Seq.map (sprintf "\"%s\"") + |> String.concat " " + |> DotNet.exec id "fantomas" + if not result.OK then + printfn "Errors while formatting all files: %A" result.Messages) + +Target.runOrList () diff --git a/fake-sample/script.fsx.lock b/fake-sample/script.fsx.lock index dca6671754..3c6221e072 100644 --- a/fake-sample/script.fsx.lock +++ b/fake-sample/script.fsx.lock @@ -2,69 +2,162 @@ STORAGE: NONE RESTRICTION: == netstandard2.0 NUGET remote: https://api.nuget.org/v3/index.json - editorconfig (0.12.2) - Fake.Core.CommandLineParsing (5.20.3) + BlackFox.VsWhere (1.1) + FSharp.Core (>= 4.2.3) + Microsoft.Win32.Registry (>= 4.7) + Fake.Core.CommandLineParsing (5.20.4) FParsec (>= 1.1.1) FSharp.Core (>= 4.7.2) - Fake.Core.Context (5.20.3) + Fake.Core.Context (5.20.4) FSharp.Core (>= 4.7.2) - Fake.Core.Environment (5.20.3) + Fake.Core.Environment (5.20.4) FSharp.Core (>= 4.7.2) - Fake.Core.FakeVar (5.20.3) - Fake.Core.Context (>= 5.20.3) + Fake.Core.FakeVar (5.20.4) + Fake.Core.Context (>= 5.20.4) FSharp.Core (>= 4.7.2) - Fake.Core.Process (5.20.3) - Fake.Core.Environment (>= 5.20.3) - Fake.Core.FakeVar (>= 5.20.3) - Fake.Core.String (>= 5.20.3) - Fake.Core.Trace (>= 5.20.3) - Fake.IO.FileSystem (>= 5.20.3) + Fake.Core.Process (5.20.4) + Fake.Core.Environment (>= 5.20.4) + Fake.Core.FakeVar (>= 5.20.4) + Fake.Core.String (>= 5.20.4) + Fake.Core.Trace (>= 5.20.4) + Fake.IO.FileSystem (>= 5.20.4) FSharp.Core (>= 4.7.2) System.Collections.Immutable (>= 1.7.1) - Fake.Core.String (5.20.3) - FSharp.Core (>= 4.7.2) - Fake.Core.Target (5.20.3) - Fake.Core.CommandLineParsing (>= 5.20.3) - Fake.Core.Context (>= 5.20.3) - Fake.Core.Environment (>= 5.20.3) - Fake.Core.FakeVar (>= 5.20.3) - Fake.Core.Process (>= 5.20.3) - Fake.Core.String (>= 5.20.3) - Fake.Core.Trace (>= 5.20.3) + Fake.Core.SemVer (5.20.4) + FSharp.Core (>= 4.7.2) + Fake.Core.String (5.20.4) + FSharp.Core (>= 4.7.2) + Fake.Core.Target (5.20.4) + Fake.Core.CommandLineParsing (>= 5.20.4) + Fake.Core.Context (>= 5.20.4) + Fake.Core.Environment (>= 5.20.4) + Fake.Core.FakeVar (>= 5.20.4) + Fake.Core.Process (>= 5.20.4) + Fake.Core.String (>= 5.20.4) + Fake.Core.Trace (>= 5.20.4) FSharp.Control.Reactive (>= 4.4.2) FSharp.Core (>= 4.7.2) - Fake.Core.Trace (5.20.3) - Fake.Core.Environment (>= 5.20.3) - Fake.Core.FakeVar (>= 5.20.3) - FSharp.Core (>= 4.7.2) - Fake.IO.FileSystem (5.20.3) - Fake.Core.String (>= 5.20.3) - FSharp.Core (>= 4.7.2) - Fantomas (4.3) - FSharp.Compiler.Service (>= 38.0) - FSharp.Core (>= 5.0) - Fantomas.Extras (4.3) - editorconfig (>= 0.12.2) - Fantomas (>= 4.3) - FSharp.Core (>= 5.0) - MAB.DotIgnore (>= 3.0.2) + Fake.Core.Tasks (5.20.4) + Fake.Core.Trace (>= 5.20.4) + FSharp.Core (>= 4.7.2) + Fake.Core.Trace (5.20.4) + Fake.Core.Environment (>= 5.20.4) + Fake.Core.FakeVar (>= 5.20.4) + FSharp.Core (>= 4.7.2) + Fake.Core.Xml (5.20.4) + Fake.Core.String (>= 5.20.4) + FSharp.Core (>= 4.7.2) + Fake.DotNet.Cli (5.20.4) + Fake.Core.Environment (>= 5.20.4) + Fake.Core.Process (>= 5.20.4) + Fake.Core.String (>= 5.20.4) + Fake.Core.Trace (>= 5.20.4) + Fake.DotNet.MSBuild (>= 5.20.4) + Fake.DotNet.NuGet (>= 5.20.4) + Fake.IO.FileSystem (>= 5.20.4) + FSharp.Core (>= 4.7.2) + Mono.Posix.NETStandard (>= 1.0) + Newtonsoft.Json (>= 12.0.3) + Fake.DotNet.MSBuild (5.20.4) + BlackFox.VsWhere (>= 1.1) + Fake.Core.Environment (>= 5.20.4) + Fake.Core.Process (>= 5.20.4) + Fake.Core.String (>= 5.20.4) + Fake.Core.Trace (>= 5.20.4) + Fake.IO.FileSystem (>= 5.20.4) + FSharp.Core (>= 4.7.2) + MSBuild.StructuredLogger (>= 2.1.176) + Fake.DotNet.NuGet (5.20.4) + Fake.Core.Environment (>= 5.20.4) + Fake.Core.Process (>= 5.20.4) + Fake.Core.SemVer (>= 5.20.4) + Fake.Core.String (>= 5.20.4) + Fake.Core.Tasks (>= 5.20.4) + Fake.Core.Trace (>= 5.20.4) + Fake.Core.Xml (>= 5.20.4) + Fake.IO.FileSystem (>= 5.20.4) + Fake.Net.Http (>= 5.20.4) + FSharp.Core (>= 4.7.2) + Newtonsoft.Json (>= 12.0.3) + NuGet.Protocol (>= 5.6) + Fake.IO.FileSystem (5.20.4) + Fake.Core.String (>= 5.20.4) + FSharp.Core (>= 4.7.2) + Fake.Net.Http (5.20.4) + Fake.Core.Trace (>= 5.20.4) + FSharp.Core (>= 4.7.2) FParsec (1.1.1) FSharp.Core (>= 4.3.4) - FSharp.Compiler.Service (38.0) - FSharp.Core (5.0) - FSharp.Control.Reactive (4.5) - FSharp.Core (>= 4.7.2) - System.Reactive (>= 4.4.1) - FSharp.Core (5.0) - MAB.DotIgnore (3.0.2) - NETStandard.Library (>= 1.6.1) - Microsoft.NETCore.Platforms (5.0) + FSharp.Control.Reactive (5.0.2) + FSharp.Core (>= 4.7.2) + System.Reactive (>= 5.0) + FSharp.Core (5.0.2) + Microsoft.Build (16.11) + Microsoft.Build.Framework (16.11) + System.Security.Permissions (>= 4.7) + Microsoft.Build.Tasks.Core (16.11) + Microsoft.Build.Framework (>= 16.11) + Microsoft.Build.Utilities.Core (>= 16.11) + Microsoft.NET.StringTools (>= 1.0) + Microsoft.Win32.Registry (>= 4.3) + System.CodeDom (>= 4.4) + System.Collections.Immutable (>= 5.0) + System.Reflection.Metadata (>= 1.6) + System.Resources.Extensions (>= 4.6) + System.Security.Cryptography.Pkcs (>= 4.7) + System.Security.Cryptography.Xml (>= 4.7) + System.Security.Permissions (>= 4.7) + System.Threading.Tasks.Dataflow (>= 4.9) + Microsoft.Build.Utilities.Core (16.11) + Microsoft.Build.Framework (>= 16.11) + Microsoft.NET.StringTools (>= 1.0) + Microsoft.Win32.Registry (>= 4.3) + System.Collections.Immutable (>= 5.0) + System.Configuration.ConfigurationManager (>= 4.7) + System.Security.Permissions (>= 4.7) + System.Text.Encoding.CodePages (>= 4.0.1) + Microsoft.NET.StringTools (1.0) + System.Memory (>= 4.5.4) + System.Runtime.CompilerServices.Unsafe (>= 5.0) + Microsoft.NETCore.Platforms (5.0.3) Microsoft.NETCore.Targets (5.0) - NETStandard.Library (2.0.3) - Microsoft.NETCore.Platforms (>= 1.1) + Microsoft.Win32.Registry (5.0) + System.Buffers (>= 4.5.1) + System.Memory (>= 4.5.4) + System.Security.AccessControl (>= 5.0) + System.Security.Principal.Windows (>= 5.0) + Mono.Posix.NETStandard (1.0) + MSBuild.StructuredLogger (2.1.545) + Microsoft.Build (>= 16.10) + Microsoft.Build.Framework (>= 16.10) + Microsoft.Build.Tasks.Core (>= 16.10) + Microsoft.Build.Utilities.Core (>= 16.10) + Newtonsoft.Json (13.0.1) + NuGet.Common (5.11) + NuGet.Frameworks (>= 5.11) + NuGet.Configuration (5.11) + NuGet.Common (>= 5.11) + System.Security.Cryptography.ProtectedData (>= 4.4) + NuGet.Frameworks (5.11) + NuGet.Packaging (5.11) + Newtonsoft.Json (>= 9.0.1) + NuGet.Configuration (>= 5.11) + NuGet.Versioning (>= 5.11) + System.Security.Cryptography.Cng (>= 5.0) + System.Security.Cryptography.Pkcs (>= 5.0) + NuGet.Protocol (5.11) + NuGet.Packaging (>= 5.11) + NuGet.Versioning (5.11) System.Buffers (4.5.1) + System.CodeDom (5.0) System.Collections.Immutable (5.0) System.Memory (>= 4.5.4) + System.Configuration.ConfigurationManager (5.0) + System.Security.Cryptography.ProtectedData (>= 5.0) + System.Security.Permissions (>= 5.0) + System.Formats.Asn1 (5.0) + System.Buffers (>= 4.5.1) + System.Memory (>= 4.5.4) System.Memory (4.5.4) System.Buffers (>= 4.5.1) System.Numerics.Vectors (>= 4.4) @@ -73,11 +166,35 @@ NUGET System.Reactive (5.0) System.Runtime.InteropServices.WindowsRuntime (>= 4.3) System.Threading.Tasks.Extensions (>= 4.5.4) + System.Reflection.Metadata (5.0) + System.Collections.Immutable (>= 5.0) + System.Resources.Extensions (5.0) + System.Memory (>= 4.5.4) System.Runtime (4.3.1) Microsoft.NETCore.Platforms (>= 1.1.1) Microsoft.NETCore.Targets (>= 1.1.3) System.Runtime.CompilerServices.Unsafe (5.0) System.Runtime.InteropServices.WindowsRuntime (4.3) System.Runtime (>= 4.3) + System.Security.AccessControl (5.0) + System.Security.Principal.Windows (>= 5.0) + System.Security.Cryptography.Cng (5.0) + System.Security.Cryptography.Pkcs (5.0.1) + System.Buffers (>= 4.5.1) + System.Formats.Asn1 (>= 5.0) + System.Memory (>= 4.5.4) + System.Security.Cryptography.Cng (>= 5.0) + System.Security.Cryptography.ProtectedData (5.0) + System.Memory (>= 4.5.4) + System.Security.Cryptography.Xml (5.0) + System.Memory (>= 4.5.4) + System.Security.Cryptography.Pkcs (>= 5.0) + System.Security.Permissions (>= 5.0) + System.Security.Permissions (5.0) + System.Security.AccessControl (>= 5.0) + System.Security.Principal.Windows (5.0) + System.Text.Encoding.CodePages (5.0) + System.Runtime.CompilerServices.Unsafe (>= 5.0) + System.Threading.Tasks.Dataflow (5.0) System.Threading.Tasks.Extensions (4.5.4) System.Runtime.CompilerServices.Unsafe (>= 4.5.3)