Skip to content

Commit

Permalink
If we specify a type project templatefile in paket pack it should fin…
Browse files Browse the repository at this point in the history
…d the project - fixes #945
  • Loading branch information
forki committed Jul 29, 2015
1 parent e73d042 commit 6e63336
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 43 deletions.
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Fix build exe path which includes whitespace - https://github.com/fsprojects/ProjectScaffold/pull/185
* Preserve encoding upon saving solution - https://github.com/fsprojects/Paket/pull/940
* BUGFIX: If we specify a templatefile in paket pack it still packs all templates - https://github.com/fsprojects/Paket/pull/944
* BUGFIX: If we specify a type project templatefile in paket pack it should find the project - https://github.com/fsprojects/Paket/issues/945

#### 1.21.0 - 23.07.2015
* Allow nuget packages to put version in the path - https://github.com/fsprojects/Paket/pull/928
Expand Down
99 changes: 56 additions & 43 deletions src/Paket.Core/PackageProcess.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,49 @@ open System.Collections.Generic
open Paket.PackageMetaData
open Chessie.ErrorHandling

let private merge buildConfig version projectFile templateFile =
let withVersion =
match version with
| None -> templateFile
| Some v -> templateFile |> TemplateFile.setVersion v

match withVersion with
| { Contents = ProjectInfo(md, opt) } ->
match md with
| Valid completeCore -> { templateFile with Contents = CompleteInfo(completeCore, opt) }
| _ ->
let assembly,id,assemblyFileName = loadAssemblyId buildConfig projectFile
let md = { md with Id = md.Id ++ Some id }

match md with
| Valid completeCore -> { templateFile with Contents = CompleteInfo(completeCore, opt) }
| _ ->
let attribs = loadAssemblyAttributes assemblyFileName assembly

let merged =
{ Id = md.Id
Version = md.Version ++ getVersion assembly attribs
Authors = md.Authors ++ getAuthors attribs
Description = md.Description ++ getDescription attribs }

match merged with
| Invalid ->
let missing =
[ if merged.Id = None then yield "Id"
if merged.Version = None then yield "Version"
if merged.Authors = None || merged.Authors = Some [] then yield "Authors"
if merged.Description = None then yield "Description" ]
|> fun xs -> String.Join(", ",xs)

failwithf
"Incomplete mandatory metadata in template file %s (even including assembly attributes)%sTemplate: %A%sMissing: %s"
templateFile.FileName
Environment.NewLine md
Environment.NewLine missing

| Valid completeCore -> { templateFile with Contents = CompleteInfo(completeCore, opt) }
| _ -> templateFile

let Pack(workingDir,dependencies : DependenciesFile, packageOutputPath, buildConfig, version, releaseNotes, templateFile, lockDependencies) =
let buildConfig = defaultArg buildConfig "Release"
let packageOutputPath = if Path.IsPathRooted(packageOutputPath) then packageOutputPath else Path.Combine(workingDir,packageOutputPath)
Expand Down Expand Up @@ -46,48 +89,7 @@ let Pack(workingDir,dependencies : DependenciesFile, packageOutputPath, buildCon
|> Array.map (fun (projectFile,templateFile) ->
allTemplateFiles.Remove(templateFile.FileName) |> ignore

let merged =
let withVersion =
match version with
| None -> templateFile
| Some v -> templateFile |> TemplateFile.setVersion v

match withVersion with
| { Contents = ProjectInfo(md, opt) } ->
match md with
| Valid completeCore -> { templateFile with Contents = CompleteInfo(completeCore, opt) }
| _ ->
let assembly,id,assemblyFileName = loadAssemblyId buildConfig projectFile
let md = { md with Id = md.Id ++ Some id }

match md with
| Valid completeCore -> { templateFile with Contents = CompleteInfo(completeCore, opt) }
| _ ->
let attribs = loadAssemblyAttributes assemblyFileName assembly

let merged =
{ Id = md.Id
Version = md.Version ++ getVersion assembly attribs
Authors = md.Authors ++ getAuthors attribs
Description = md.Description ++ getDescription attribs }

match merged with
| Invalid ->
let missing =
[ if merged.Id = None then yield "Id"
if merged.Version = None then yield "Version"
if merged.Authors = None || merged.Authors = Some [] then yield "Authors"
if merged.Description = None then yield "Description" ]
|> fun xs -> String.Join(", ",xs)

failwithf
"Incomplete mandatory metadata in template file %s (even including assembly attributes)%sTemplate: %A%sMissing: %s"
templateFile.FileName
Environment.NewLine md
Environment.NewLine missing

| Valid completeCore -> { templateFile with Contents = CompleteInfo(completeCore, opt) }
| _ -> templateFile
let merged = merge buildConfig version projectFile templateFile

let id =
match merged.Contents with
Expand All @@ -103,7 +105,18 @@ let Pack(workingDir,dependencies : DependenciesFile, packageOutputPath, buildCon
|> Map.map (fun _ (t, p) -> p,findDependencies dependencies buildConfig t p lockDependencies projectTemplates)
|> Map.toList
|> List.map (fun (_,(_,x)) -> x)
|> List.append [for fileName in allTemplateFiles -> TemplateFile.Load(fileName,version)]
|> List.append [for fileName in allTemplateFiles ->
let templateFile = TemplateFile.Load(fileName,version)
match templateFile with
| { Contents = ProjectInfo(_) } ->
let fi = FileInfo(fileName)
let allProjectFiles = ProjectFile.FindAllProjects(fi.Directory.FullName) |> Array.toList

match allProjectFiles with
| [ projectFile ] -> merge buildConfig version projectFile templateFile
| [] -> failwithf "There was no project file found for template file %s" fileName
| _ -> failwithf "There was more than one project file found for template file %s" fileName
| _ -> templateFile ]

// set version
let templatesWithVersion =
Expand Down

0 comments on commit 6e63336

Please sign in to comment.