@@ -9,11 +9,13 @@ import Happstack.Server.Compression
9import System.Directory (makeRelativeToCurrentDirectory)
9import System.Directory (makeRelativeToCurrentDirectory)
10import System.Environment
10import System.Environment
11import qualified Language.Elm as Elm
11import qualified Language.Elm as Elm
12−import Paths_Elm
12+import Paths_elm_server
14+runtime = "/elm-" ++ show version ++ ".js"
14serve :: String -> IO ()
16serve :: String -> IO ()
15serve libLoc = do
17serve libLoc = do
16− putStrLn "Elm Server 0.4.0.3: running at <http://localhost:8000>"
18+ putStrLn ("Elm Server "++show version++": running at <http://localhost:8000>")
17 simpleHTTP nullConf $ do
19 simpleHTTP nullConf $ do
18 _ <- compressedResponseFilter
20 _ <- compressedResponseFilter
19 msum [ uriRest serveElm
21 msum [ uriRest serveElm
@@ -29,10 +31,10 @@ serveElm fp = do
29 let ('/':filePath) = fp
31 let ('/':filePath) = fp
30 guard (".elm" `isSuffixOf` filePath)
32 guard (".elm" `isSuffixOf` filePath)
31 content <- liftIO (readFile filePath)
33 content <- liftIO (readFile filePath)
32− ok . toResponse $ Elm.toHtml "elm-runtime.js" (pageTitle filePath) content
34+ ok . toResponse $ Elm.toHtml runtime (pageTitle filePath) content
34serveLib libLoc fp = do
36serveLib libLoc fp = do
35− guard (fp == "/elm-runtime.js")
37+ guard (fp == runtime)
36 serveFile (asContentType "application/javascript") libLoc
38 serveFile (asContentType "application/javascript") libLoc
38main :: IO ()
40main :: IO ()
@@ -40,11 +42,8 @@ main = getArgs >>= parse
41parse :: [String] -> IO ()
43parse :: [String] -> IO ()
42parse ("--help":_) = putStrLn usage
44parse ("--help":_) = putStrLn usage
43−parse ("--version":_) = putStrLn "The Elm Server 0.4.0.3"
45+parse ("--version":_) = putStrLn ("The Elm Server " ++ show version)
44−parse [] = do
46+parse [] = serve =<< Elm.runtimeLocation
45− absolutePath <- getDataFileName "elm-runtime-0.4.0.3.js"
46− runtime <- makeRelativeToCurrentDirectory absolutePath
48parse [arg]
47parse [arg]
49 | "--runtime-location=" `isPrefixOf` arg =
48 | "--runtime-location=" `isPrefixOf` arg =
50 serve . tail $ dropWhile (/='=') arg
49 serve . tail $ dropWhile (/='=') arg
@@ -63,7 +62,7 @@ usage =
63 \Example: elm-server\n\
62 \Example: elm-server\n\
65 \Resource Locations:\n\
64 \Resource Locations:\n\
66− \ --runtime-location set the location of the Elm runtime (elm-mini.js)\n\
65+ \ --runtime-location set the location of the Elm runtime\n\
68 \Compiler Information:\n\
67 \Compiler Information:\n\
69 \ --version print the version information and exit\n\
68 \ --version print the version information and exit\n\