module LoadLibraries (docs) where
import Control.DeepSeq (force)
import qualified Control.Exception as E
import Paths_Elm
import System.Directory
import System.FilePath
import System.IO.Unsafe (unsafePerformIO)
docs :: String
docs = force $ unsafePerformIO (safeReadDocs =<< getDataFileName "docs.json")
safeReadDocs :: FilePath -> IO String
safeReadDocs name = E.catch (readDocs name) (emitError name)
readDocs :: FilePath -> IO String
readDocs name = do
exists <- doesFileExist name
if exists then readFile name
else ioError . userError $ "File Not Found"
emitError :: FilePath -> IOError -> IO String
emitError name err = do
putStrLn $ "Error! Types for standard library not loaded properly!\n File should be here:" ++ name ++ "\n The file is created and copied by command: cabal install"
putStrLn (show err)
return "{\"modules\":[]}"