Skip to content

Commit 709c598

Browse files
committed
Added more paths.
1 parent 64fd1ba commit 709c598

File tree

2 files changed

+95
-61
lines changed

2 files changed

+95
-61
lines changed

src/Compiler/Backend.gren

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ module Compiler.Backend exposing
1616
, UnsupportedPlatform(..)
1717
, downloadUrl
1818
, download
19-
, cachePath
20-
, isCached
2119
)
2220

2321

@@ -112,65 +110,6 @@ download permission url =
112110
|> HttpClient.send permission
113111

114112

115-
{-| Construct a `Path` where we'd expect to find the compiler blob if it has been downloaded
116-
previously.
117-
-}
118-
cachePath : Node.Platform -> Dict String String -> Path -> Path
119-
cachePath platform envVars homeDir =
120-
let
121-
startPath =
122-
when platform is
123-
Node.Win32 ->
124-
envVars
125-
|> Dict.get "LOCALAPPDATA"
126-
|> Maybe.map Path.fromWin32String
127-
|> Maybe.withDefault (
128-
"AppData/Local"
129-
|> Path.fromPosixString
130-
|> Path.prepend homeDir
131-
)
132-
133-
Node.Darwin ->
134-
"Library/Caches"
135-
|> Path.fromPosixString
136-
|> Path.prepend homeDir
137-
138-
_ ->
139-
envVars
140-
|> Dict.get "XDG_CACHE_HOME"
141-
|> Maybe.map Path.fromPosixString
142-
|> Maybe.withDefault (Path.append (Path.fromPosixString ".cache") homeDir)
143-
144-
filename =
145-
when platform is
146-
Node.Win32 ->
147-
"gren.exe"
148-
149-
_ ->
150-
"gren"
151-
152-
endPath =
153-
[ "gren"
154-
, version
155-
, "bin"
156-
, filename
157-
]
158-
|> String.join "/"
159-
|> Path.fromPosixString
160-
in
161-
Path.prepend startPath endPath
162-
163-
164-
{-| Checks if the compiler blob exist on this system.
165-
-}
166-
isCached : FileSystem.Permission -> Node.Platform -> Dict String String -> Path -> Task x Bool
167-
isCached permission platform envVars homeDir =
168-
cachePath platform envVars homeDir
169-
|> FileSystem.checkAccess permission []
170-
|> Task.map (\_ -> True)
171-
|> Task.onError (\_ -> Task.succeed False)
172-
173-
174113
-- Compiler Commands
175114

176115

src/Compiler/Paths.gren

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
11
module Compiler.Paths exposing
22
( projectRoot
33
, projectMetadata
4+
--
5+
, CacheRoot
6+
, cacheRoot
7+
, cacheRootToPath
8+
, backendBinary
9+
, packageSources
10+
, repl
11+
, exists
412
)
513

614

715
import FileSystem
816
import FileSystem.Path as Path exposing (Path)
917
import Task exposing (Task)
18+
import Dict exposing (Dict)
19+
import Node
20+
import Compiler.Backend
21+
import SemanticVersion exposing (SemanticVersion)
1022

1123

1224
projectRoot : FileSystem.Permission -> Task FileSystem.Error Path
@@ -34,3 +46,86 @@ projectMetadataHelp perm dir =
3446
else
3547
Task.fail err
3648
)
49+
50+
51+
type CacheRoot
52+
= CacheRoot Path
53+
54+
55+
{-| Construct a [CacheRoot](#CacheRoot), a system specific path where the Gren compiler caches
56+
things like the backend binary and package sources.
57+
-}
58+
cacheRoot : Node.Platform -> Dict String String -> Path -> SemanticVersion -> CacheRoot
59+
cacheRoot platform envVars homeDir grenVersion =
60+
let
61+
startPath =
62+
when platform is
63+
Node.Win32 ->
64+
envVars
65+
|> Dict.get "LOCALAPPDATA"
66+
|> Maybe.map Path.fromWin32String
67+
|> Maybe.withDefault (
68+
"AppData/Local"
69+
|> Path.fromPosixString
70+
|> Path.prepend homeDir
71+
)
72+
73+
Node.Darwin ->
74+
"Library/Caches"
75+
|> Path.fromPosixString
76+
|> Path.prepend homeDir
77+
78+
_ ->
79+
envVars
80+
|> Dict.get "XDG_CACHE_HOME"
81+
|> Maybe.map Path.fromPosixString
82+
|> Maybe.withDefault (Path.append (Path.fromPosixString ".cache") homeDir)
83+
84+
85+
endPath =
86+
[ "gren"
87+
, SemanticVersion.toString grenVersion
88+
]
89+
|> String.join "/"
90+
|> Path.fromPosixString
91+
in
92+
CacheRoot (Path.prepend startPath endPath)
93+
94+
95+
cacheRootToPath : CacheRoot -> Path
96+
cacheRootToPath (CacheRoot path) =
97+
path
98+
99+
100+
backendBinary : Node.Platform -> CacheRoot -> Path
101+
backendBinary platform (CacheRoot cache) =
102+
let
103+
binPath =
104+
when platform is
105+
Node.Win32 ->
106+
Path.fromPosixString "bin/gren.exe"
107+
108+
_ ->
109+
Path.fromPosixString "bin/gren"
110+
in
111+
Path.append binPath cache
112+
113+
114+
packageSources : CacheRoot -> Path
115+
packageSources (CacheRoot cache) =
116+
Path.prepend cache (Path.fromPosixString "packages")
117+
118+
119+
repl : CacheRoot -> Path
120+
repl (CacheRoot cache) =
121+
Path.prepend cache (Path.fromPosixString "repl")
122+
123+
124+
{-| Checks to see if the given `Path` points to a real file.
125+
-}
126+
exists : FileSystem.Permission -> Path -> Task x Bool
127+
exists permission path =
128+
path
129+
|> FileSystem.checkAccess permission []
130+
|> Task.map (\_ -> True)
131+
|> Task.onError (\_ -> Task.succeed False)

0 commit comments

Comments
 (0)