Add a way to specify the runtime location

This commit is contained in:
Evan Czaplicki 2014-03-23 17:57:36 -07:00
parent 1dd651ecbf
commit 0fe6ec0bd7

View file

@ -24,11 +24,14 @@ import Snap.Util.FileServe
data Flags = Flags data Flags = Flags
{ port :: Int { port :: Int
, runtime :: Maybe FilePath
} deriving (Data,Typeable,Show,Eq) } deriving (Data,Typeable,Show,Eq)
flags :: Flags flags :: Flags
flags = Flags flags = Flags
{ port = 8000 &= help "set the port of the server" { port = 8000 &= help "set the port of the server"
, runtime = Nothing &= typFile
&= help "Specify a custom location for Elm's runtime system."
} &= help "Quickly reload Elm projects in your browser. Just refresh to recompile.\n\ } &= help "Quickly reload Elm projects in your browser. Just refresh to recompile.\n\
\It serves static files and freshly recompiled Elm files." \It serves static files and freshly recompiled Elm files."
&= helpArg [explicit, name "help", name "h"] &= helpArg [explicit, name "help", name "h"]
@ -49,7 +52,7 @@ main = do
putStrLn $ "Elm Server " ++ Version.showVersion version ++ putStrLn $ "Elm Server " ++ Version.showVersion version ++
": Just refresh a page to recompile it!" ": Just refresh a page to recompile it!"
httpServe (setPort (port cargs) config) $ httpServe (setPort (port cargs) config) $
serveRuntime serveRuntime (maybe Elm.runtime id (runtime cargs))
<|> serveElm <|> serveElm
<|> serveDirectoryWith directoryConfig "." <|> serveDirectoryWith directoryConfig "."
@ -74,14 +77,14 @@ indexStyle =
\th { background:rgb(90,99,120); color:white; text-align:left;\ \th { background:rgb(90,99,120); color:white; text-align:left;\
\ padding:10px; font-weight:normal; }" \ padding:10px; font-weight:normal; }"
runtime :: String runtimeName :: String
runtime = "elm-runtime.js" runtimeName = "elm-runtime.js"
serveRuntime :: Snap () serveRuntime :: FilePath -> Snap ()
serveRuntime = serveRuntime runtimePath =
do file <- BSC.unpack . rqPathInfo <$> getRequest do file <- BSC.unpack . rqPathInfo <$> getRequest
guard (file == runtime) guard (file == runtimeName)
serveFileAs "application/javascript" Elm.runtime serveFileAs "application/javascript" runtimePath
serveElm :: Snap () serveElm :: Snap ()
serveElm = serveElm =
@ -91,7 +94,7 @@ serveElm =
onSuccess (compile file) (serve file) onSuccess (compile file) (serve file)
where where
compile file = compile file =
let elmArgs = [ "--make", "--runtime=" ++ runtime, file ] let elmArgs = [ "--make", "--runtime=" ++ runtimeName, file ]
in createProcess $ (proc "elm" elmArgs) { std_out = CreatePipe } in createProcess $ (proc "elm" elmArgs) { std_out = CreatePipe }
serve file = serve file =