Skip to content

Commit

Permalink
Update to Fantomas 3.0.0 and use Fake Helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
Jimmy Byrd committed Oct 22, 2019
1 parent 2c49bd8 commit fb26e47
Show file tree
Hide file tree
Showing 14 changed files with 164 additions and 113 deletions.
6 changes: 0 additions & 6 deletions Content/Console/.config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@
"version": 1,
"isRoot": true,
"tools": {
"fantomas-tool": {
"version": "3.0.0-beta-002",
"commands": [
"fantomas"
]
},
"sourcelink": {
"version": "3.1.1",
"commands": [
Expand Down
32 changes: 25 additions & 7 deletions Content/Console/build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ open Fake.IO.Globbing.Operators
open Fake.Core.TargetOperators
open Fake.Api
open Fake.BuildServer
open Fantomas
open Fantomas.FakeHelpers

BuildServer.install [
AppVeyor.Installer
Expand Down Expand Up @@ -43,6 +45,14 @@ let sln = "MyLib.1.sln"

let src = __SOURCE_DIRECTORY__ @@ "src"

let srcCodeGlob =
!! ( src @@ "**/*.fs")
++ ( src @@ "**/*.fsx")

let testsCodeGlob =
!! (__SOURCE_DIRECTORY__ @@ "tests/**/*.fs")
++ (__SOURCE_DIRECTORY__ @@ "tests/**/*.fsx")

let srcGlob = src @@ "**/*.??proj"
let testsGlob = __SOURCE_DIRECTORY__ @@ "tests/**/*.??proj"

Expand Down Expand Up @@ -126,9 +136,6 @@ module dotnet =
DotNet.exec optionConfig (sprintf "%s" command) args
|> failOnBadExitAndPrint

let fantomas optionConfig args =
tool optionConfig "fantomas" args

let reportgenerator optionConfig args =
tool optionConfig "reportgenerator" args

Expand Down Expand Up @@ -345,10 +352,21 @@ let githubRelease _ =
|> Async.RunSynchronously

let formatCode _ =
srcAndTest
|> Seq.map (IO.Path.GetDirectoryName)
|> Seq.iter (fun projDir ->
dotnet.fantomas id (sprintf "--recurse %s" projDir)
[
srcCodeGlob
testsCodeGlob
]
|> Seq.collect id
// Ignore AssemblyInfo
|> Seq.filter(fun f -> f.EndsWith("AssemblyInfo.fs") |> not)
|> formatFilesAsync FormatConfig.FormatConfig.Default
|> Async.RunSynchronously
|> Seq.iter(fun result ->
match result with
| Formatted(original, tempfile) ->
tempfile |> Shell.copyFile original
Trace.logfn "Formatted %s" original
| _ -> ()
)

//-----------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions Content/Console/paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ group Build
nuget Fake.Api.GitHub 5.18.1
nuget Fake.BuildServer.AppVeyor 5.18.1
nuget Fake.BuildServer.Travis 5.18.1
nuget Fantomas 3.0.0
57 changes: 35 additions & 22 deletions Content/Console/paket.lock

Large diffs are not rendered by default.

39 changes: 21 additions & 18 deletions Content/Console/src/MyLib.1/Main.fs
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
namespace MyLib._1

open System.Reflection

module AssemblyInfo =

let metaDataValue (mda : AssemblyMetadataAttribute) = mda.Value
let getMetaDataAttribute (assembly : Assembly) key =
let metaDataValue (mda: AssemblyMetadataAttribute) = mda.Value

let getMetaDataAttribute (assembly: Assembly) key =
assembly.GetCustomAttributes(typedefof<AssemblyMetadataAttribute>)
|> Seq.cast<AssemblyMetadataAttribute>
|> Seq.find(fun x -> x.Key = key)
|> Seq.cast<AssemblyMetadataAttribute>
|> Seq.find (fun x -> x.Key = key)

let getReleaseDate assembly =
"ReleaseDate"
Expand All @@ -23,26 +25,27 @@ module AssemblyInfo =
"AssemblyVersion"
|> getMetaDataAttribute assembly
|> metaDataValue
let assembly = lazy(Assembly.GetEntryAssembly())
let printVersion () =

let assembly = lazy (Assembly.GetEntryAssembly())

let printVersion() =
let version = assembly.Force().GetName().Version
printfn "%A" version

let printInfo () =
let printInfo() =
let assembly = assembly.Force()
let name = assembly.GetName()
let version = assembly.GetName().Version
let releaseDate = getReleaseDate assembly
let githash = getGitHash assembly
let githash = getGitHash assembly
printfn "%s - %A - %s - %s" name.Name version releaseDate githash

module Say =
open System
let nothing name =
name |> ignore

let hello name =
sprintf "Hello %s" name
let nothing name = name |> ignore

let hello name = sprintf "Hello %s" name

let colorizeIn color str =
let oldColor = Console.ForegroundColor
Expand All @@ -52,34 +55,34 @@ module Say =

module Main =
open Argu

type CLIArguments =
| Info
| Version
| Favorite_Color of string // Look in App.config
| [<MainCommand>] Hello of string
with
interface IArgParserTemplate with
member s.Usage =
match s with
| Info -> "More detailed information"
| Version -> "Version of application"
| Favorite_Color _ -> "Favorite color"
| Hello _-> "Who to say hello to"
| Hello _ -> "Who to say hello to"

[<EntryPoint>]
let main (argv : string array) =
let main (argv: string array) =
let parser = ArgumentParser.Create<CLIArguments>(programName = "MyLib._1")
let results = parser.Parse(argv)
if results.Contains Version then
AssemblyInfo.printVersion ()
AssemblyInfo.printVersion()
elif results.Contains Info then
AssemblyInfo.printInfo ()
AssemblyInfo.printInfo()
elif results.Contains Hello then
match results.TryGetResult Hello with
| Some v ->
let color = results.GetResult Favorite_Color
Say.hello v |> Say.colorizeIn color
| None -> parser.PrintUsage() |> printfn "%s"
| None -> parser.PrintUsage() |> printfn "%s"
else
parser.PrintUsage() |> printfn "%s"
0
4 changes: 2 additions & 2 deletions Content/Console/tests/MyLib.1.Tests/Main.fs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module ExpectoTemplate

open Expecto

[<EntryPoint>]
let main argv =
Tests.runTestsInAssembly defaultConfig argv
let main argv = Tests.runTestsInAssembly defaultConfig argv
15 changes: 7 additions & 8 deletions Content/Console/tests/MyLib.1.Tests/Tests.fs
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ open MyLib._1

[<Tests>]
let tests =
testList "samples" [
testCase "Say nothing" <| fun _ ->
let subject = Say.nothing ()
Expect.equal subject () "Not an absolute unit"
testCase "Say hello all" <| fun _ ->
let subject = Say.hello "all"
Expect.equal subject "Hello all" "You didn't say hello"
]
testList "samples"
[ testCase "Say nothing" <| fun _ ->
let subject = Say.nothing()
Expect.equal subject () "Not an absolute unit"
testCase "Say hello all" <| fun _ ->
let subject = Say.hello "all"
Expect.equal subject "Hello all" "You didn't say hello" ]
6 changes: 0 additions & 6 deletions Content/Library/.config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@
"version": 1,
"isRoot": true,
"tools": {
"fantomas-tool": {
"version": "3.0.0-beta-002",
"commands": [
"fantomas"
]
},
"sourcelink": {
"version": "3.1.1",
"commands": [
Expand Down
33 changes: 26 additions & 7 deletions Content/Library/build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ open Fake.IO.Globbing.Operators
open Fake.Core.TargetOperators
open Fake.Api
open Fake.BuildServer
open Fantomas
open Fantomas.FakeHelpers

BuildServer.install [
AppVeyor.Installer
Expand Down Expand Up @@ -41,6 +43,15 @@ let environVarAsBoolOrDefault varName defaultValue =
let productName = "MyLib.1"
let sln = "MyLib.1.sln"


let srcCodeGlob =
!! (__SOURCE_DIRECTORY__ @@ "src/**/*.fs")
++ (__SOURCE_DIRECTORY__ @@ "src/**/*.fsx")

let testsCodeGlob =
!! (__SOURCE_DIRECTORY__ @@ "tests/**/*.fs")
++ (__SOURCE_DIRECTORY__ @@ "tests/**/*.fsx")

let srcGlob =__SOURCE_DIRECTORY__ @@ "src/**/*.??proj"
let testsGlob = __SOURCE_DIRECTORY__ @@ "tests/**/*.??proj"

Expand Down Expand Up @@ -112,9 +123,6 @@ module dotnet =
DotNet.exec optionConfig (sprintf "%s" command) args
|> failOnBadExitAndPrint

let fantomas optionConfig args =
tool optionConfig "fantomas" args

let reportgenerator optionConfig args =
tool optionConfig "reportgenerator" args

Expand Down Expand Up @@ -334,10 +342,21 @@ let githubRelease _ =
|> Async.RunSynchronously

let formatCode _ =
srcAndTest
|> Seq.map (IO.Path.GetDirectoryName)
|> Seq.iter (fun projDir ->
dotnet.fantomas id (sprintf "--recurse %s" projDir)
[
srcCodeGlob
testsCodeGlob
]
|> Seq.collect id
// Ignore AssemblyInfo
|> Seq.filter(fun f -> f.EndsWith("AssemblyInfo.fs") |> not)
|> formatFilesAsync FormatConfig.FormatConfig.Default
|> Async.RunSynchronously
|> Seq.iter(fun result ->
match result with
| Formatted(original, tempfile) ->
tempfile |> Shell.copyFile original
Trace.logfn "Formatted %s" original
| _ -> ()
)

//-----------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions Content/Library/paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ group Build
nuget Fake.Api.GitHub 5.18.1
nuget Fake.BuildServer.AppVeyor 5.18.1
nuget Fake.BuildServer.Travis 5.18.1
nuget Fantomas 3.0.0
Loading

0 comments on commit fb26e47

Please sign in to comment.