on master help sign in
Add a way to specify the runtime location
0fe6ec0Evan Czaplicki
server/Server.hs+11−8
@@ -24,11 +24,14 @@ import Snap.Util.FileServe
24
24
25data Flags = Flags
25data Flags = Flags
26 { port :: Int
26 { port :: Int
27+ , runtime :: Maybe FilePath
27 } deriving (Data,Typeable,Show,Eq)
28 } deriving (Data,Typeable,Show,Eq)
28
29
29flags :: Flags
30flags :: Flags
30flags = Flags
31flags = Flags
31 { port = 8000 &= help "set the port of the server"
32 { port = 8000 &= help "set the port of the server"
33+ , runtime = Nothing &= typFile
34+ &= help "Specify a custom location for Elm's runtime system."
32 } &= help "Quickly reload Elm projects in your browser. Just refresh to recompile.\n\
35 } &= help "Quickly reload Elm projects in your browser. Just refresh to recompile.\n\
33 \It serves static files and freshly recompiled Elm files."
36 \It serves static files and freshly recompiled Elm files."
34 &= helpArg [explicit, name "help", name "h"]
37 &= helpArg [explicit, name "help", name "h"]
@@ -49,7 +52,7 @@ main = do
49 putStrLn $ "Elm Server " ++ Version.showVersion version ++
52 putStrLn $ "Elm Server " ++ Version.showVersion version ++
50 ": Just refresh a page to recompile it!"
53 ": Just refresh a page to recompile it!"
51 httpServe (setPort (port cargs) config) $
54 httpServe (setPort (port cargs) config) $
52− serveRuntime
55+ serveRuntime (maybe Elm.runtime id (runtime cargs))
53 <|> serveElm
56 <|> serveElm
54 <|> serveDirectoryWith directoryConfig "."
57 <|> serveDirectoryWith directoryConfig "."
55
58
@@ -74,14 +77,14 @@ indexStyle =
74 \th { background:rgb(90,99,120); color:white; text-align:left;\
77 \th { background:rgb(90,99,120); color:white; text-align:left;\
75 \ padding:10px; font-weight:normal; }"
78 \ padding:10px; font-weight:normal; }"
76
79
77−runtime :: String
80+runtimeName :: String
78−runtime = "elm-runtime.js"
81+runtimeName = "elm-runtime.js"
79
82
80−serveRuntime :: Snap ()
83+serveRuntime :: FilePath -> Snap ()
81−serveRuntime =
84+serveRuntime runtimePath =
82 do file <- BSC.unpack . rqPathInfo <$> getRequest
85 do file <- BSC.unpack . rqPathInfo <$> getRequest
83− guard (file == runtime)
86+ guard (file == runtimeName)
84− serveFileAs "application/javascript" Elm.runtime
87+ serveFileAs "application/javascript" runtimePath
85
88
86serveElm :: Snap ()
89serveElm :: Snap ()
87serveElm =
90serveElm =
@@ -91,7 +94,7 @@ serveElm =
91 onSuccess (compile file) (serve file)
94 onSuccess (compile file) (serve file)
92 where
95 where
93 compile file =
96 compile file =
94− let elmArgs = [ "--make", "--runtime=" ++ runtime, file ]
97+ let elmArgs = [ "--make", "--runtime=" ++ runtimeName, file ]
95 in createProcess $ (proc "elm" elmArgs) { std_out = CreatePipe }
98 in createProcess $ (proc "elm" elmArgs) { std_out = CreatePipe }
96
99
97 serve file =
100 serve file =