Skip to content
Next Next commit
Parses -- syntax to exclude file-patterns in paket.template files
  • Loading branch information
devboy committed Jun 22, 2015
commit d084448ac4c11bbb0fcb94b7e98ba8daa4d8b92f
24 changes: 21 additions & 3 deletions src/Paket.Core/TemplateFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ type internal OptionalPackagingInfo =
Dependencies : (string * VersionRequirement) list
References : string list
FrameworkAssemblyReferences : string list
Files : (string * string) list }
Files : (string * string) list
FilesExcluded : string list }
static member Epmty : OptionalPackagingInfo =
{ Title = None
Owners = []
Expand All @@ -137,7 +138,8 @@ type internal OptionalPackagingInfo =
Dependencies = []
References = []
FrameworkAssemblyReferences = []
Files = [] }
Files = []
FilesExcluded = [] }

type internal CompleteInfo = CompleteCoreInfo * OptionalPackagingInfo

Expand Down Expand Up @@ -225,16 +227,31 @@ module internal TemplateFile =
let private getFiles (map : Map<string, string>) =
Map.tryFind "files" map
|> Option.map (fun d -> d.Split '\n')
|> Option.map (Array.filter (fun l -> l.TrimStart(' ', '\t').StartsWith("--") |> not))
|> Option.map
(Seq.map
(fun (line:string) ->

let splitted = line.Split([|"==>"|],StringSplitOptions.None) |> Array.map (fun s -> s.Trim())
let splitted.Length < 2 then "lib" else splitted.[1]

splitted.[0],target))
|> Option.map List.ofSeq
|> fun x -> defaultArg x []

let private getFileExcludes (map : Map<string, string>) =
Map.tryFind "files" map
|> Option.map (fun d -> d.Split '\n')
|> Option.map (Array.filter (fun l -> l.TrimStart(' ', '\t').StartsWith("--")))
|> Option.map
(Seq.map
(fun (line:string) ->
let exclude = line.Split([|"--"|],StringSplitOptions.RemoveEmptyEntries)
|> Array.map (fun s -> s.Trim())
exclude.[0]))
|> Option.map List.ofSeq
|> fun x -> defaultArg x []

let private getReferences (map : Map<string, string>) =
Map.tryFind "references" map
|> Option.map (fun d -> d.Split '\n')
Expand Down Expand Up @@ -301,7 +318,8 @@ module internal TemplateFile =
Dependencies = getDependencies(fileName,map,currentVersion)
References = getReferences map
FrameworkAssemblyReferences = getFrameworkReferences map
Files = getFiles map }
Files = getFiles map
FilesExcluded = getFileExcludes map }

let Parse(file,currentVersion,contentStream : Stream) =
trial {
Expand Down
25 changes: 25 additions & 0 deletions tests/Paket.Tests/TemplateFileParsing.fs
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,31 @@ files
to2 |> shouldEqual "someLib"
| _ -> Assert.Fail()

[<Test>]
let ``Detect exclude files correctly``() =
let text = """type file
id My.Thing
authors Bob McBob
description
A longer description
on two lines.
version
1.0
files
someDir
anotherDir ==> someLib
-- excludeDir
"""
let sut =
TemplateFile.Parse("file1.template", None, strToStream text)
|> returnOrFail
|> function
| CompleteInfo (_, opt)
| ProjectInfo (_, opt) -> opt
match sut.FilesExcluded with
| [x] -> x |> shouldEqual "excludeDir"
| _ -> Assert.Fail()

[<Literal>]
let ProjectType1 = """type project
"""
Expand Down