Repository navigation
Rop init & init auto restore command #533
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a797b62
Rop for Init command - references #464
theimowski 72340c8
inline init
theimowski 9ea5801
touch up on rop for init-auto-restore
theimowski d18a582
cleanup
theimowski 3a64b86
use projects from environment
theimowski c798af3
save file can fail
theimowski 2b9504d
createDir can fail, no need to delete file as DownloadFile will overw…
theimowski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
cleanup
- Loading branch information
commit d18a58270dabcce230dfbfb03ac71c05a9a2e858
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,48 +6,31 @@ open System | |
| open Rop | ||
| open Domain | ||
|
|
||
| let downloadString (url : string) (client : System.Net.WebClient) = | ||
| try | ||
| client.DownloadString url |> succeed | ||
| with _ -> | ||
| DownloadError url |> fail | ||
|
|
||
| let downloadFile (url : string) (fileName : string) (client : System.Net.WebClient) = | ||
| try | ||
| client.DownloadFile(url, fileName) |> succeed | ||
| with _ -> | ||
| DownloadError url |> fail | ||
|
|
||
| let deleteFile (fileName : string) = | ||
| try | ||
| File.Delete fileName |> succeed | ||
| with _ -> | ||
| FileDeleteError fileName |> fail | ||
|
|
||
| let getLatestVersionFromJson (data : string) = | ||
| try | ||
| let start = data.IndexOf("tag_name") + 11 | ||
| let end' = data.IndexOf("\"", start) | ||
| succeed (data.Substring(start, end' - start)) | ||
| (data.Substring(start, end' - start)) |> SemVer.Parse |> succeed | ||
| with _ -> | ||
| fail ReleasesJsonParseError | ||
|
|
||
| let InitAutoRestoreR(rootDirectory : DirectoryInfo) = | ||
| let exeDir = Path.Combine(rootDirectory.FullName, ".paket") | ||
| let InitAutoRestore environment = | ||
| let exeDir = Path.Combine(environment.RootDirectory.FullName, ".paket") | ||
| CreateDir(exeDir) | ||
| use client = createWebClient None | ||
|
|
||
| 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" version file | ||
| do! downloadFile url fileName client | ||
| 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 |> downloadString releasesUrl | ||
| let! data = client |> downloadStringSync releasesUrl | ||
| let! latestVersion = getLatestVersionFromJson data | ||
|
|
||
| let! downloads = | ||
|
|
@@ -56,52 +39,14 @@ let InitAutoRestoreR(rootDirectory : DirectoryInfo) = | |
| |> collect | ||
|
|
||
| let projectsUnderPaket = | ||
|
Contributor
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
Member
Author
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 rootDirectory.FullName | ||
| 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(root, ".paket", "paket.targets")) | ||
| createRelativePath project.FileName (Path.Combine(exeDir, "paket.targets")) | ||
| project.AddImportForPaketTargets(relativePath) | ||
| project.Save() | ||
| ) | ||
|
|
||
| return () | ||
| } | ||
|
|
||
| let InitAutoRestore(dependenciesFileName) = | ||
| let root = | ||
| if dependenciesFileName = Constants.DependenciesFileName then | ||
| "." | ||
| else | ||
| Path.GetDirectoryName dependenciesFileName | ||
|
|
||
| CreateDir(Path.Combine(root,".paket")) | ||
| 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() | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This one can also fail due to permissions.
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.
Btw. I don't like to have this one explicitly called, for me it should be part of
downloadfunction.No one needs this directory to be present besides the download, as it would fail.
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.
Thanks for comments, i'll apply changes