@@ -11,6 +11,7 @@ import Control.Monad.Trans (liftIO)
1111import qualified Data.ByteString.Lazy as LBS
1212import Data.Monoid ((<>))
1313import qualified Network.HTTP.Client as Client
14+import qualified System.Directory as Dir
1415
1516import qualified Elm.Compiler.Version as Compiler
1617import qualified Elm.Package as Pkg
@@ -85,17 +86,18 @@ init flags =
8586
8687download :: String -> Task.Task ()
8788download projectType =
88− do fetch (projectType ++ "/elm.json")
89− fetch (projectType ++ "/src/Main.elm")
89+ do fetch projectType "elm.json" $ return ()
90+ fetch projectType "src/Main.elm" $ Dir.createDirectoryIfMissing True "src"
9091
9192
92−fetch :: FilePath -> Task.Task ()
93−fetch path =
93+fetch :: String -> FilePath -> IO () -> Task.Task ()
94+fetch projectType path setup =
9495 Http.run $
9596 Http.anything
96− ("https://experiment.elm-lang.org/" ++ vsn ++ "/init/" ++ path)
97+ ("https://experiment.elm-lang.org/" ++ vsn ++ "/init/" ++ projectType ++ "/" ++ path)
9798 (\request manager ->
9899 do response <- Client.httpLbs request manager
100+ setup
99101 Right <$> LBS.writeFile path (Client.responseBody response)
100102 )
101103