@@ -0,0 +1,147 @@
1+{-# OPTIONS_GHC -Wall #-}
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 ((</>), (<.>))
23+import qualified Elm.ModuleName as ModuleName
24+import qualified Elm.Package as Pkg
25+import qualified Elm.Version as V
34+ "elm-stuff" </> compilerVersion
39+ stuff </> "details.dat"
42+prepublishDir :: FilePath
44+ stuff </> "prepublish"
47+compilerVersion :: FilePath
56+elmi :: FilePath -> ModuleName.Raw -> FilePath
58+ toArtifactPath root name "elmi"
61+elmo :: FilePath -> ModuleName.Raw -> FilePath
63+ toArtifactPath root name "elmo"
66+toArtifactPath :: FilePath -> ModuleName.Raw -> String -> FilePath
67+toArtifactPath root name ext =
68+ root </> stuff </> ModuleName.toHyphenPath name <.> ext
75+temp :: String -> FilePath
77+ stuff </> "temp" <.> ext
84+getRoot :: IO (Maybe FilePath)
86+ do dir <- Dir.getCurrentDirectory
87+ getRootHelp (FP.splitDirectories dir)
90+getRootHelp :: [String] -> IO (Maybe FilePath)
97+ do exists_ <- Dir.doesFileExist (FP.joinPath dirs </> "elm.json")
99+ then return (Just (FP.joinPath dirs))
100+ else getRootHelp (init dirs)
107+newtype PackageCache = PackageCache FilePath
110+getPackageCache :: IO PackageCache
112+ PackageCache <$> getCacheDir "packages"
115+registry :: PackageCache -> FilePath
116+registry (PackageCache dir) =
117+ dir </> "registry.dat"
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
129+getReplCache :: IO FilePath
134+getCacheDir :: FilePath -> IO FilePath
135+getCacheDir projectName =
136+ do home <- getElmHome
137+ let root = home </> compilerVersion </> projectName
138+ Dir.createDirectoryIfMissing True root
142+getElmHome :: IO FilePath
144+ do maybeCustomHome <- Env.lookupEnv "ELM_HOME"
145+ case maybeCustomHome of
146+ Just customHome -> return customHome
147+ Nothing -> Dir.getAppUserDataDirectory "elm"