on master help sign in
Expose runtime, add Elm.Utils for all projects to share
10a84b4Evan Czaplicki
compiler/Elm/Compiler.hs+12−1
@@ -1,6 +1,6 @@
1{-# OPTIONS_GHC -Wall #-}
1{-# OPTIONS_GHC -Wall #-}
2{-# LANGUAGE FlexibleContexts #-}
2{-# LANGUAGE FlexibleContexts #-}
3−module Elm.Compiler (version, parseDependencies, compile) where
3+module Elm.Compiler (version, parseDependencies, compile, runtimePath) where
4
4
5import Control.Monad.Error (MonadError, throwError)
5import Control.Monad.Error (MonadError, throwError)
6import qualified Data.List as List
6import qualified Data.List as List
@@ -11,9 +11,11 @@ import qualified AST.Module as Module (HeaderAndImports(HeaderAndImports), toInt
11import qualified Build.Source as Source
11import qualified Build.Source as Source
12import qualified Elm.Compiler.Module as PublicModule
12import qualified Elm.Compiler.Module as PublicModule
13import qualified Elm.Compiler.Version as Version
13import qualified Elm.Compiler.Version as Version
14+import qualified Elm.Utils as Utils
14import qualified Generate.JavaScript as JS
15import qualified Generate.JavaScript as JS
15import qualified Parse.Helpers as Help
16import qualified Parse.Helpers as Help
16import qualified Parse.Module as Parse
17import qualified Parse.Module as Parse
18+import qualified Paths_elm_compiler as Compiler
17
19
18
20
19-- VERSION
21-- VERSION
@@ -55,3 +57,12 @@ compile source interfaces =
55 where
57 where
56 unwrappedInterfaces =
58 unwrappedInterfaces =
57 Map.mapKeysMonotonic (\(PublicModule.Name name) -> name) interfaces
59 Map.mapKeysMonotonic (\(PublicModule.Name name) -> name) interfaces
60+
61+
62+-- DATA FILES
63+
64+{-| Path to the runtime.
65+-}
66+runtimePath :: IO FilePath
67+runtimePath =
68+ Utils.getAsset "compiler" Compiler.getDataFileName "runtime/core.js"
compiler/Elm/Utils.hsnew file+64
@@ -0,0 +1,64 @@
1+{-# OPTIONS_GHC -Wall #-}
2+module Elm.Utils ((|>), (<|), getAsset) where
3+
4+import System.Directory (doesFileExist)
5+import System.Environment (getEnv)
6+import System.FilePath ((</>))
7+import System.IO.Error (tryIOError)
8+
9+
10+{-| Forward function application `x |> f == f x`. This function is useful
11+for avoiding parenthesis and writing code in a more natural way.
12+-}
13+(|>) :: a -> (a -> b) -> b
14+x |> f = f x
15+
16+
17+{-| Backward function application `f <| x == f x`. This function is useful for
18+avoiding parenthesis.
19+-}
20+(<|) :: (a -> b) -> a -> b
21+f <| x = f x
22+
23+
24+infixr 0 <|
25+infixl 0 |>
26+
27+
28+{-| Get the absolute path to a data file. If you install with cabal it will look
29+-}
30+getAsset :: String -> (FilePath -> IO FilePath) -> FilePath -> IO FilePath
31+getAsset project getDataFileName name =
32+ do path <- getDataFileName name
33+ exists <- doesFileExist path
34+ if exists
35+ then return path
36+ else do
37+ environment <- tryIOError (getEnv "ELM_HOME")
38+ case environment of
39+ Right env ->
40+ return (env </> project </> name)
41+
42+ Left _ ->
43+ fail (errorNotFound name)
44+
45+
46+errorNotFound :: FilePath -> String
47+errorNotFound name =
48+ unlines
49+ [ "Unable to find the ELM_HOME environment variable when searching"
50+ , "for the " ++ name ++ " file."
51+ , ""
52+ , "If you installed Elm Platform with the Mac or Windows installer, it looks like"
53+ , "ELM_HOME was not set automatically. Look up how to set environment variables"
54+ , "on your platform and set ELM_HOME to the directory that contains Elm's static"
55+ , "files:"
56+ , ""
57+ , " * On Mac it is /usr/local/share/elm"
58+ , " * On Windows it is one of the following:"
59+ , " C:/Program Files/Elm Platform/0.13/share"
60+ , " C:/Program Files (x86)/Elm Platform/0.13/share"
61+ , ""
62+ , "If it seems like a more complex issue, please report it here:"
63+ , " <https://github.com/elm-lang/elm-platform/issues>"
64+ ]
elm-compiler.cabal+5−2
@@ -27,11 +27,13 @@ Extra-source-files: changelog.md
27Cabal-version: >=1.9
27Cabal-version: >=1.9
28Build-type: Simple
28Build-type: Simple
29
29
30+Data-files:
31+ runtime/core.js
32+
30source-repository head
33source-repository head
31 type: git
34 type: git
32 location: git://github.com/elm-lang/Elm.git
35 location: git://github.com/elm-lang/Elm.git
33
36
34−
35Library
37Library
36 ghc-options:
38 ghc-options:
37 -threaded -O2 -W
39 -threaded -O2 -W
@@ -42,7 +44,8 @@ Library
42 exposed-modules:
44 exposed-modules:
43 Elm.Compiler,
45 Elm.Compiler,
44 Elm.Compiler.Module,
46 Elm.Compiler.Module,
45− Elm.Docs
47+ Elm.Docs,
48+ Elm.Utils
46
49
47 other-modules:
50 other-modules:
48 Elm.Compiler.Version,
51 Elm.Compiler.Version,