-
Notifications
You must be signed in to change notification settings - Fork 525
/
Constants.fs
142 lines (126 loc) · 6.07 KB
/
Constants.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
module Paket.Constants
open System
open System.IO
open Paket.Domain
let [<Literal>] GitHubUrl = "https://github.com"
let [<Literal>] DefaultNuGetStream = "https://www.nuget.org/api/v2"
let [<Literal>] DefaultNuGetV3Stream = "https://api.nuget.org/v3/index.json"
let [<Literal>] GitHubReleasesUrl = "https://api.github.com/repos/fsprojects/Paket/releases"
let [<Literal>] GithubReleaseDownloadUrl = "https://github.com/fsprojects/Paket/releases/download"
/// 'paket.lock'
let [<Literal>] LockFileName = "paket.lock"
/// 'paket.local'
let [<Literal>] LocalFileName = "paket.local"
/// 'paket.restore.sha512'
let [<Literal>] RestoreHashFile = "paket.restore.cached"
/// 'paket.dependencies'
let [<Literal>] DependenciesFileName = "paket.dependencies"
/// '.paket'
let [<Literal>] PaketFolderName = ".paket"
let [<Literal>] BootstrapperFileName = "paket.bootstrapper.exe"
let [<Literal>] PaketFileName = "paket.exe"
let [<Literal>] TargetsFileName = "paket.targets"
let [<Literal>] ReferencesFile = "paket.references"
let [<Literal>] AccessLockFileName = "paket.locked"
let [<Literal>] PaketFilesFolderName = "paket-files"
let [<Literal>] DefaultPackagesFolderName = "packages"
let [<Literal>] SolutionFolderProjectGuid = "2150E333-8FDC-42A3-9474-1A3956D46DE8"
let [<Literal>] PaketVersionFileName = "paket.version"
let [<Literal>] TemplateFile = "paket.template"
let [<Literal>] PackagesConfigFile = "packages.config"
let [<Literal>] NuGetConfigFile = "NuGet.Config"
let [<Literal>] FullProjectSourceFileName = "FULLPROJECT"
let [<Literal>] ProjectDefaultNameSpace = "http://schemas.microsoft.com/developer/msbuild/2003"
let [<Literal>] ProjectDefaultNameSpaceCore = "http://schemas.microsoft.com/developer/msbuild/2003"
let [<Literal>] NuGetProtocolVersion = "4.1.0"
#if DOTNETCORE
module Environment =
type SpecialFolder =
| ApplicationData
| UserProfile
| LocalApplicationData
| ProgramFiles
| ProgramFilesX86
let GetFolderPath sf =
let envVar, monoPathSuffix =
match sf with
| ApplicationData -> "APPDATA", ".config"
| UserProfile -> "USERPROFILE", ""
| LocalApplicationData -> "LocalAppData", ".local/share"
| ProgramFiles -> "PROGRAMFILES", ".programfiles"
| ProgramFilesX86 -> "PROGRAMFILES(X86)", ".programfilesX86"
let isWindows =
System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(
System.Runtime.InteropServices.OSPlatform.Windows)
let homePath =
if isWindows then
let defaultPath = Environment.GetEnvironmentVariable("USERPROFILE")
if System.String.IsNullOrEmpty defaultPath then
Environment.GetEnvironmentVariable("HOME")
else defaultPath
else Environment.GetEnvironmentVariable("HOME")
if isWindows then
let res = Environment.GetEnvironmentVariable(envVar)
if System.String.IsNullOrEmpty res then
System.IO.Path.Combine(homePath, monoPathSuffix)
else res
else
System.IO.Path.Combine(homePath, monoPathSuffix)
#endif
let MainDependencyGroup = GroupName "Main"
let getEnVar variable =
let envar = Environment.GetEnvironmentVariable variable
if String.IsNullOrEmpty envar then None else Some envar
let getEnvDir specialPath =
let dir = Environment.GetFolderPath specialPath
if String.IsNullOrEmpty dir then None else Some dir
let AppDataFolder =
getEnvDir Environment.SpecialFolder.ApplicationData
|> Option.defaultWith (fun _ ->
let fallback = Path.GetFullPath ".paket"
Logging.traceWarnfn "Could not find AppDataFolder, try to set the APPDATA environment variable. Using '%s' instead." fallback
if not (Directory.Exists fallback) then
Directory.CreateDirectory fallback |> ignore
fallback)
let PaketConfigFolder = Path.Combine(AppDataFolder, "Paket")
let PaketConfigFile = Path.Combine(PaketConfigFolder, "paket.config")
let LocalRootForTempData =
getEnvDir Environment.SpecialFolder.UserProfile
|> Option.orElse (getEnvDir Environment.SpecialFolder.LocalApplicationData)
|> Option.defaultWith (fun _ ->
let fallback = Path.GetFullPath ".paket"
Logging.traceWarnfn "Could not detect a root for our (user specific) temporary files. Try to set the 'HOME' or 'LocalAppData' environment variable!. Using '%s' instead." fallback
if not (Directory.Exists fallback) then
Directory.CreateDirectory fallback |> ignore
fallback
)
let GitRepoCacheFolder = Path.Combine(LocalRootForTempData,".paket","git","db")
let [<Literal>] GlobalPackagesFolderEnvironmentKey = "NUGET_PACKAGES"
let UserNuGetPackagesFolder =
getEnVar GlobalPackagesFolderEnvironmentKey
|> Option.map (fun path ->
path.Replace (Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar)
) |> Option.defaultWith (fun _ ->
Path.Combine (LocalRootForTempData,".nuget","packages")
)
/// The magic unpublished date is 1900-01-01T00:00:00
let MagicUnlistingDate = DateTimeOffset(1900, 1, 1, 0, 0, 0, TimeSpan.FromHours(-8.)).DateTime
/// The NuGet cache folder.
let NuGetCacheFolder =
getEnVar "NuGetCachePath"
|> Option.bind (fun cachePath ->
let di = DirectoryInfo cachePath
if not di.Exists then di.Create()
Some di.FullName
) |> Option.orElse (
getEnvDir Environment.SpecialFolder.LocalApplicationData
|> Option.bind (fun appData ->
let di = DirectoryInfo (Path.Combine (appData, "Nuget", "Cache"))
if not di.Exists then
di.Create ()
Some di.FullName
))|> Option.defaultWith (fun _ ->
let fallback = Path.GetFullPath ".paket"
Logging.traceWarnfn "Could not find LocalApplicationData folder, try to set the 'LocalAppData' environment variable. Using '%s' instead" fallback
fallback
)