on master help sign in
Move Stuff.Paths into just Stuff
commit31fde71f0e8b58d70241c64a6c7de78cfade4228 authorEvan Czaplicki <evancz@users.noreply.github.com> dateTue 12 Feb 2019, 19:40 (8 years ago) parent08ebf20
2 files changed+147−92
builder/src/Stuff.hs+147 builder/src/Stuff/Paths.hs−92
builder/src/Stuff.hsnew file+147
@@ -0,0 +1,147 @@
1+{-# OPTIONS_GHC -Wall #-}
2+module Stuff
3+ ( details
4+ , prepublishDir
5+ , elmi
6+ , elmo
7+ , temp
8+ , getRoot
9+ , PackageCache
10+ , getPackageCache
11+ , registry
12+ , metadata
13+ , getReplCache
14+ )
15+ where
16+
17+
18+import qualified System.Directory as Dir
19+import qualified System.Environment as Env
20+import qualified System.FilePath as FP
21+import System.FilePath ((</>), (<.>))
22+
23+import qualified Elm.ModuleName as ModuleName
24+import qualified Elm.Package as Pkg
25+import qualified Elm.Version as V
26+
27+
28+
29+-- PATHS
30+
31+
32+stuff :: FilePath
33+stuff =
34+ "elm-stuff" </> compilerVersion
35+
36+
37+details :: FilePath
38+details =
39+ stuff </> "details.dat"
40+
41+
42+prepublishDir :: FilePath
43+prepublishDir =
44+ stuff </> "prepublish"
45+
46+
47+compilerVersion :: FilePath
48+compilerVersion =
49+ V.toChars V.compiler
50+
51+
52+
53+-- ELMI and ELMO
54+
55+
56+elmi :: FilePath -> ModuleName.Raw -> FilePath
57+elmi root name =
58+ toArtifactPath root name "elmi"
59+
60+
61+elmo :: FilePath -> ModuleName.Raw -> FilePath
62+elmo root name =
63+ toArtifactPath root name "elmo"
64+
65+
66+toArtifactPath :: FilePath -> ModuleName.Raw -> String -> FilePath
67+toArtifactPath root name ext =
68+ root </> stuff </> ModuleName.toHyphenPath name <.> ext
69+
70+
71+
72+-- TEMP
73+
74+
75+temp :: String -> FilePath
76+temp ext =
77+ stuff </> "temp" <.> ext
78+
79+
80+
81+-- GET ROOT
82+
83+
84+getRoot :: IO (Maybe FilePath)
85+getRoot =
86+ do dir <- Dir.getCurrentDirectory
87+ getRootHelp (FP.splitDirectories dir)
88+
89+
90+getRootHelp :: [String] -> IO (Maybe FilePath)
91+getRootHelp dirs =
92+ case dirs of
93+ [] ->
94+ return Nothing
95+
96+ _:_ ->
97+ do exists_ <- Dir.doesFileExist (FP.joinPath dirs </> "elm.json")
98+ if exists_
99+ then return (Just (FP.joinPath dirs))
100+ else getRootHelp (init dirs)
101+
102+
103+
104+-- PACKAGE CACHES
105+
106+
107+newtype PackageCache = PackageCache FilePath
108+
109+
110+getPackageCache :: IO PackageCache
111+getPackageCache =
112+ PackageCache <$> getCacheDir "packages"
113+
114+
115+registry :: PackageCache -> FilePath
116+registry (PackageCache dir) =
117+ dir </> "registry.dat"
118+
119+
120+metadata :: PackageCache -> Pkg.Name -> V.Version -> String -> FilePath
121+metadata (PackageCache dir) name version path =
122+ dir </> Pkg.toFilePath name </> V.toChars version </> path
123+
124+
125+
126+-- CACHE
127+
128+
129+getReplCache :: IO FilePath
130+getReplCache =
131+ getCacheDir "repl"
132+
133+
134+getCacheDir :: FilePath -> IO FilePath
135+getCacheDir projectName =
136+ do home <- getElmHome
137+ let root = home </> compilerVersion </> projectName
138+ Dir.createDirectoryIfMissing True root
139+ return root
140+
141+
142+getElmHome :: IO FilePath
143+getElmHome =
144+ do maybeCustomHome <- Env.lookupEnv "ELM_HOME"
145+ case maybeCustomHome of
146+ Just customHome -> return customHome
147+ Nothing -> Dir.getAppUserDataDirectory "elm"
builder/src/Stuff/Paths.hsdeleted−92
@@ -1,92 +0,0 @@
1−{-# OPTIONS_GHC -Wall #-}
2−module Stuff.Paths
3− ( docs
4− , summary
5− , prepublishDir
6− , removeStuff
7− , elmi
8− , elmo
9− , moduleDocs
10− , temp
11− )
12− where
13−
14−
15−import Control.Monad.Trans (liftIO)
16−import qualified System.Directory as Dir
17−import System.FilePath ((</>), (<.>))
18−
19−import qualified Elm.ModuleName as ModuleName
20−import qualified Elm.Version as V
21−import qualified Reporting.Task as Task
22−
23−
24−
25−-- PATHS
26−
27−
28−stuff :: FilePath
29−stuff =
30− "elm-stuff" </> V.toChars V.compiler
31−
32−
33−docs :: FilePath
34−docs =
35− stuff </> "docs.json"
36−
37−
38−summary :: FilePath
39−summary =
40− stuff </> "summary.dat"
41−
42−
43−prepublishDir :: FilePath
44−prepublishDir =
45− stuff </> "prepublish"
46−
47−
48−
49−-- REMOVE STUFF
50−
51−
52−removeStuff :: FilePath -> Task.Task_ e ()
53−removeStuff root =
54− liftIO $
55− do let dir = root </> "elm-stuff"
56− exists <- Dir.doesDirectoryExist dir
57− if exists
58− then Dir.removeDirectoryRecursive dir
59− else return ()
60−
61−
62−
63−-- ELMI and ELMO
64−
65−
66−elmi :: FilePath -> ModuleName.Raw -> FilePath
67−elmi root name =
68− toArtifactPath root name "elmi"
69−
70−
71−elmo :: FilePath -> ModuleName.Raw -> FilePath
72−elmo root name =
73− toArtifactPath root name "elmo"
74−
75−
76−moduleDocs :: FilePath -> ModuleName.Raw -> FilePath
77−moduleDocs root name =
78− toArtifactPath root name "json"
79−
80−
81−toArtifactPath :: FilePath -> ModuleName.Raw -> String -> FilePath
82−toArtifactPath root name ext =
83− root </> stuff </> ModuleName.nameToHyphenPath name <.> ext
84−
85−
86−
87−-- TEMP
88−
89−
90−temp :: String -> FilePath
91−temp ext =
92− stuff </> "temp" <.> ext