on master help sign in
Stop using a custom cache directory, and stop deleting the cache immediately. Also clean up related code.
d57b91cEvan Czaplicki
server/Server.hs+14−16
@@ -33,20 +33,23 @@ serve portNumber libLoc = do
33pageTitle :: String -> String
33pageTitle :: String -> String
34pageTitle = dropExtension . takeBaseName
34pageTitle = dropExtension . takeBaseName
35
35
36−defaultCacheDirectory = "elm-server-cache"
37−
38serveElm :: FilePath -> ServerPartT IO Response
36serveElm :: FilePath -> ServerPartT IO Response
39−serveElm fp = do
37+serveElm fp =
40− fileExists <- liftIO $ doesFileExist file
38+ do fileExists <- liftIO $ doesFileExist file
41− guard $ fileExists && takeExtension fp == ".elm"
39+ guard (fileExists && takeExtension fp == ".elm")
40+ onSuccess compile serve
41+ where
42+ file = tail fp
42
43
43− (_, stdout, _, handle) <- liftIO $ createProcess $
44− (proc "elm" args) { std_out = CreatePipe }
44+ compile = liftIO $ createProcess $ (proc "elm" args) { std_out = CreatePipe }
45− exitCode <- liftIO $ waitForProcess handle
45+ where args = [ "--make", "--runtime=" ++ runtime, file ]
46
46
47− dirExists <- liftIO $ doesDirectoryExist defaultCacheDirectory
47+ serve = serveFile (asContentType "text/html")
48− when dirExists $ liftIO $ removeDirectoryRecursive defaultCacheDirectory
48+ ("build" </> replaceExtension file "html")
49
49
50+onSuccess action success = do
51+ (_, stdout, _, handle) <- action
52+ exitCode <- liftIO $ waitForProcess handle
50 case (exitCode, stdout) of
53 case (exitCode, stdout) of
51 (ExitFailure 127, _) ->
54 (ExitFailure 127, _) ->
52 badRequest $ toResponse "Error: elm binary not found in your path."
55 badRequest $ toResponse "Error: elm binary not found in your path."
@@ -55,13 +58,8 @@ serveElm fp = do
55 badRequest $ toResponse str
58 badRequest $ toResponse str
56 (ExitFailure _, Nothing) ->
59 (ExitFailure _, Nothing) ->
57 badRequest $ toResponse "See command line for error message."
60 badRequest $ toResponse "See command line for error message."
58− (ExitSuccess, _) ->
61+ (ExitSuccess, _) -> success
59− serveFile
60− (asContentType "text/html") ("build" </> replaceExtension file "html")
61
62
62− where file = tail fp
63− args = [ "--make" ,"--runtime=" ++ runtime,
64− "--cache-dir=" ++ defaultCacheDirectory, file ]
65
63
66serveLib :: FilePath -> String -> ServerPartT IO Response
64serveLib :: FilePath -> String -> ServerPartT IO Response
67serveLib libLoc fp = do
65serveLib libLoc fp = do