Update elm-server to work with 0.9, compiles multiple files
This commit is contained in:
parent
77ff8ca3ab
commit
0f400da42f
2 changed files with 28 additions and 17 deletions
|
@ -7,17 +7,19 @@ import Data.List (isPrefixOf, isSuffixOf, (\\))
|
|||
import Data.Version (showVersion)
|
||||
import Happstack.Server
|
||||
import Happstack.Server.Compression
|
||||
import System.Directory
|
||||
import System.Environment
|
||||
import System.FilePath
|
||||
import System.Process
|
||||
import qualified Language.Elm as Elm
|
||||
import Paths_elm_server
|
||||
|
||||
runtime = "/elm-" ++ showVersion version ++ ".js"
|
||||
runtime = "/elm-runtime.js"
|
||||
|
||||
serve :: Int -> String -> IO ()
|
||||
serve portNumber libLoc = do
|
||||
putStrLn ("Elm Server " ++ showVersion version ++
|
||||
": running at <http://localhost:" ++ (show portNumber) ++ ">")
|
||||
putStrLn $ "Elm Server " ++ showVersion version ++
|
||||
": running at <http://localhost:" ++ show portNumber ++ ">"
|
||||
putStrLn "Just refresh a page to recompile it!"
|
||||
simpleHTTP httpConf $ do
|
||||
_ <- compressedResponseFilter
|
||||
|
@ -30,11 +32,16 @@ serve portNumber libLoc = do
|
|||
pageTitle :: String -> String
|
||||
pageTitle = dropExtension . takeBaseName
|
||||
|
||||
serveElm :: FilePath -> ServerPartT IO Response
|
||||
serveElm fp = do
|
||||
guard (takeExtension fp == ".elm")
|
||||
content <- liftIO (readFile (tail fp))
|
||||
length content `seq` (ok . toResponse $ Elm.toHtml runtime (pageTitle fp) content)
|
||||
let file = tail fp
|
||||
liftIO $ rawSystem "elm" [ "--make" ,"--runtime=" ++ runtime
|
||||
, "--cache-dir=elm-server-cache", file ]
|
||||
liftIO $ removeDirectoryRecursive "elm-server-cache"
|
||||
serveFile (asContentType "text/html") ("build" </> replaceExtension file "html")
|
||||
|
||||
serveLib :: FilePath -> [Char] -> ServerPartT IO Response
|
||||
serveLib libLoc fp = do
|
||||
guard (fp == runtime)
|
||||
serveFile (asContentType "application/javascript") libLoc
|
||||
|
@ -45,16 +52,18 @@ main = getArgs >>= parse
|
|||
parse :: [String] -> IO ()
|
||||
parse ("--help":_) = putStrLn usage
|
||||
parse ("--version":_) = putStrLn ("The Elm Server " ++ showVersion version)
|
||||
parse args = if null remainingArgs
|
||||
then serve portNumber =<< elmRuntime
|
||||
else putStrLn usageMini
|
||||
where runtimeArg = filter (isPrefixOf "--runtime-location=") args
|
||||
portArg = filter (isPrefixOf "--port=") args
|
||||
remainingArgs = (args \\ runtimeArg) \\ portArg
|
||||
parse args =
|
||||
case null remainingArgs of
|
||||
True -> serve portNumber =<< elmRuntime
|
||||
False -> putStrLn usageMini
|
||||
where
|
||||
runtimeArg = filter (isPrefixOf "--runtime-location=") args
|
||||
portArg = filter (isPrefixOf "--port=") args
|
||||
remainingArgs = (args \\ runtimeArg) \\ portArg
|
||||
|
||||
argValue arg = tail $ dropWhile (/= '=') (head arg)
|
||||
portNumber = if null portArg then 8000 else read (argValue portArg) :: Int
|
||||
elmRuntime = if null runtimeArg then Elm.runtime else return $ argValue runtimeArg
|
||||
argValue arg = tail $ dropWhile (/= '=') (head arg)
|
||||
portNumber = if null portArg then 8000 else read (argValue portArg) :: Int
|
||||
elmRuntime = if null runtimeArg then Elm.runtime else return $ argValue runtimeArg
|
||||
|
||||
usageMini :: String
|
||||
usageMini =
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
Name: elm-server
|
||||
Version: 0.8
|
||||
Version: 0.9
|
||||
Synopsis: The Elm language server.
|
||||
Description: This package provides a standalone, Happstack-based Elm server.
|
||||
|
||||
|
@ -27,12 +27,14 @@ Executable elm-server
|
|||
Main-is: Server.hs
|
||||
Build-depends: base >=4.2 && <5,
|
||||
containers >= 0.3,
|
||||
directory,
|
||||
transformers >= 0.2,
|
||||
mtl >= 2,
|
||||
parsec >= 3.1.1,
|
||||
blaze-html >= 0.5.1,
|
||||
HTTP >= 4000,
|
||||
happstack-server == 7.1.1 || == 7.1.7 || == 7.0.2,
|
||||
happstack-server,
|
||||
deepseq,
|
||||
filepath,
|
||||
Elm >= 0.8
|
||||
Elm >= 0.9.0.1,
|
||||
process
|
||||
|
|
Loading…
Reference in a new issue