Skip to content

Commit

Permalink
Merge pull request #1108 from mvkra/paketrestore
Browse files Browse the repository at this point in the history
resolves #1095 - adds paket restore to the PaketHelper
  • Loading branch information
forki committed Jan 23, 2016
2 parents 444a560 + cf6f5d4 commit b79dc2e
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/app/FakeLib/PaketHelper.fs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,25 @@ let PaketPushDefaults() : PaketPushParams =
DegreeOfParallelism = 8
ApiKey = null }

/// Paket restore packages type
type PaketRestoreParams =
{ ToolPath : string
TimeOut : TimeSpan
WorkingDir : string
ForceDownloadOfPackages : bool
OnlyReferencedFiles: bool
Group: string
ReferenceFiles: string list }

let PaketRestoreDefaults() : PaketRestoreParams =
{ ToolPath = (findToolFolderInSubPath "paket.exe" (currentDirectory @@ ".paket")) @@ "paket.exe"
TimeOut = System.TimeSpan.MaxValue
WorkingDir = "."
ForceDownloadOfPackages = false
OnlyReferencedFiles = false
ReferenceFiles = []
Group = "" }

/// Creates a new NuGet package by using Paket pack on all paket.template files in the working directory.
/// ## Parameters
///
Expand Down Expand Up @@ -179,3 +198,28 @@ let GetDependenciesForReferencesFile (referencesFile:string) =

getLockFilePackages referencesFile
|> Array.filter (fun (n, _) -> refLines |> Array.exists (fun pn -> pn.Equals(n, StringComparison.InvariantCultureIgnoreCase)))

/// Restores all packages referenced in either a paket.dependencies or a paket.references file using Paket
/// ## Parameters
///
/// - `setParams` - Function used to manipulate the default parameters.
let Restore setParams =
let parameters : PaketRestoreParams = PaketRestoreDefaults() |> setParams
let forceRestore = if parameters.ForceDownloadOfPackages then " --force " else ""
let onlyReferenced = if parameters.OnlyReferencedFiles then " --only-referenced " else ""
let groupArg = if parameters.Group <> "" then (sprintf " group %s " parameters.Group) else ""
let referencedFiles =
if parameters.ReferenceFiles |> List.isEmpty |> not
then (sprintf " --references-files %s " (System.String.Join(" ", parameters.ReferenceFiles)))
else ""

traceStartTask "PaketRestore" parameters.WorkingDir

let restoreResult =
ExecProcess (fun info ->
info.FileName <- parameters.ToolPath
info.WorkingDirectory <- parameters.WorkingDir
info.Arguments <- sprintf "restore %s%s%s%s" forceRestore onlyReferenced groupArg referencedFiles) parameters.TimeOut

if restoreResult <> 0 then failwithf "Error during restore %s." parameters.WorkingDir
traceEndTask "PaketRestore" parameters.WorkingDir

0 comments on commit b79dc2e

Please sign in to comment.