-
Notifications
You must be signed in to change notification settings - Fork 525
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rop init & init auto restore command #533
Changes from 4 commits
a797b62
72340c8
9ea5801
d18a582
3a64b86
c798af3
2b9504d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,39 +3,50 @@ | |
open System.IO | ||
open Logging | ||
open System | ||
open Rop | ||
open Domain | ||
|
||
let InitAutoRestore(dependenciesFileName) = | ||
let root = | ||
if dependenciesFileName = Constants.DependenciesFileName then | ||
"." | ||
else | ||
Path.GetDirectoryName dependenciesFileName | ||
|
||
CreateDir(Path.Combine(root,".paket")) | ||
let getLatestVersionFromJson (data : string) = | ||
try | ||
let start = data.IndexOf("tag_name") + 11 | ||
let end' = data.IndexOf("\"", start) | ||
(data.Substring(start, end' - start)) |> SemVer.Parse |> succeed | ||
with _ -> | ||
fail ReleasesJsonParseError | ||
|
||
let InitAutoRestore environment = | ||
let exeDir = Path.Combine(environment.RootDirectory.FullName, ".paket") | ||
CreateDir(exeDir) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one can also fail due to permissions. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Btw. I don't like to have this one explicitly called, for me it should be part of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for comments, i'll apply changes |
||
use client = createWebClient None | ||
|
||
let releasesUrl = "https://api.github.com/repos/fsprojects/Paket/releases"; | ||
let data = client.DownloadString(releasesUrl) | ||
let start = data.IndexOf("tag_name") + 11 | ||
let end' = data.IndexOf("\"", start) | ||
let latestVersion = data.Substring(start, end' - start); | ||
|
||
for file in ["paket.targets"; "paket.bootstrapper.exe"] do | ||
try | ||
File.Delete(Path.Combine(root, ".paket", file)) | ||
with _ -> traceErrorfn "Unable to delete %s" file | ||
try | ||
client.DownloadFile(sprintf "https://github.com/fsprojects/Paket/releases/download/%s/%s" latestVersion file, | ||
Path.Combine(root, ".paket", file)) | ||
tracefn "Downloaded %s" file | ||
with _ -> traceErrorfn "Unable to download %s for version %s" file latestVersion | ||
|
||
let projectsUnderPaket = | ||
ProjectFile.FindAllProjects root | ||
|> Array.filter (fun project -> ProjectFile.FindReferencesFile(FileInfo(project.FileName)).IsSome) | ||
|
||
for project in projectsUnderPaket do | ||
let relativePath = | ||
createRelativePath project.FileName (Path.Combine(root, ".paket", "paket.targets")) | ||
project.AddImportForPaketTargets(relativePath) | ||
project.Save() | ||
let download version file = | ||
rop { | ||
let fileName = Path.Combine(exeDir, file) | ||
do! deleteFile fileName | ||
let url = sprintf "https://github.com/fsprojects/Paket/releases/download/%s/%s" (string version) file | ||
do! downloadFileSync url fileName client | ||
} | ||
|
||
rop { | ||
let releasesUrl = "https://api.github.com/repos/fsprojects/Paket/releases"; | ||
let! data = client |> downloadStringSync releasesUrl | ||
let! latestVersion = getLatestVersionFromJson data | ||
|
||
let! downloads = | ||
["paket.targets"; "paket.bootstrapper.exe"] | ||
|> List.map (download latestVersion) | ||
|> collect | ||
|
||
let projectsUnderPaket = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. aren't the projects already in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good spot! I totally forgot about it |
||
ProjectFile.FindAllProjects environment.RootDirectory.FullName | ||
|> Array.filter (fun project -> ProjectFile.FindReferencesFile(FileInfo(project.FileName)).IsSome) | ||
|
||
projectsUnderPaket | ||
|> Array.iter (fun project -> | ||
let relativePath = | ||
createRelativePath project.FileName (Path.Combine(exeDir, "paket.targets")) | ||
project.AddImportForPaketTargets(relativePath) | ||
project.Save() | ||
) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually this
Save
call can fail. For example insufficient rights to create a file.