on master help sign in
Ask to create elm.json and src/Main.elm if it looks like a new project
cb903efEvan Czaplicki
builder/src/Elm/Project/Root.hs+39−1
@@ -7,10 +7,14 @@ module Elm.Project.Root
7 where
7 where
8
8
9import Control.Monad.Trans (liftIO)
9import Control.Monad.Trans (liftIO)
10+import qualified Data.ByteString.Lazy as LBS
10import qualified Data.Map as Map
11import qualified Data.Map as Map
12+import Data.Monoid ((<>))
13+import qualified Network.HTTP.Client as Client
11import qualified System.Directory as Dir
14import qualified System.Directory as Dir
12import System.FilePath ((</>))
15import System.FilePath ((</>))
13
16
17+import qualified Elm.Compiler.Version as Elm
14import qualified Elm.Package as Pkg
18import qualified Elm.Package as Pkg
15import qualified Elm.Project.Constraint as Con
19import qualified Elm.Project.Constraint as Con
16import qualified Elm.Project.Json as Project
20import qualified Elm.Project.Json as Project
@@ -19,8 +23,11 @@ import Elm.Project.Json (Project(..), PkgInfo(..))
19import Elm.Project.Summary (Summary)
23import Elm.Project.Summary (Summary)
20import qualified Elm.PerUserCache as PerUserCache
24import qualified Elm.PerUserCache as PerUserCache
21import qualified File.IO as IO
25import qualified File.IO as IO
26+import qualified Reporting.Doc as D
22import qualified Reporting.Exit as Exit
27import qualified Reporting.Exit as Exit
28+import qualified Reporting.Progress as Progress
23import qualified Reporting.Task as Task
29import qualified Reporting.Task as Task
30+import qualified Reporting.Task.Http as Http
24import qualified Stuff.Verify as Verify
31import qualified Stuff.Verify as Verify
25import qualified Json.Encode as Encode
32import qualified Json.Encode as Encode
26
33
@@ -54,7 +61,38 @@ moveToRoot =
54 return root
61 return root
55
62
56 Nothing ->
63 Nothing ->
64+ do approved <- Task.getApproval $ D.vcat $
65+ [ "It looks like you are starting a new Elm project. Very exciting!"
66+ , ""
67+ , "I would like to create two files to help you get started:"
68+ , ""
69+ , " 1. elm.json" <> D.black " ------------ describes your dependencies"
70+ , " 2. src/Main.elm" <> D.black " ------ a basic Elm program to expand"
71+ , ""
72+ , "This is common to all Elm projects. Would you like me to create them? [Y/n]: "
73+ ]
74+
75+ if approved
76+ then
77+ do liftIO $ Dir.createDirectoryIfMissing True "src"
78+ fetch "elm.json"
79+ fetch "src/Main.elm"
80+ Task.report Progress.ElmJsonApproved
81+ liftIO $ Dir.getCurrentDirectory
82+ else
83+ do Task.report Progress.ElmJsonRejected
57− Task.throw Exit.NoElmJson
84+ Task.throw Exit.NoElmJson
85+
86+
87+fetch :: FilePath -> Task.Task ()
88+fetch path =
89+ Http.run $
90+ Http.anything
91+ ("https://experiment.elm-lang.org/" ++ Pkg.versionToString Elm.version ++ "/starter/" ++ path)
92+ (\request manager ->
93+ do response <- Client.httpLbs request manager
94+ Right <$> LBS.writeFile path (Client.responseBody response)
95+ )
58
96
59
97
60
98
builder/src/Reporting/Progress.hs+5−1
@@ -70,8 +70,12 @@ data Msg
70
70
71
71
72data Progress
72data Progress
73+ -- elm.json
74+ = ElmJsonApproved
75+ | ElmJsonRejected
76+
73 -- download packages
77 -- download packages
74− = DownloadSkip
78+ | DownloadSkip
75 | DownloadStart [(Name, Version)]
79 | DownloadStart [(Name, Version)]
76 | DownloadPkgStart Name Version
80 | DownloadPkgStart Name Version
77 | DownloadPkgEnd Name Version Outcome
81 | DownloadPkgEnd Name Version Outcome
builder/src/Reporting/Progress/Terminal.hs+23
@@ -90,6 +90,29 @@ loopHelp chan progress state@(State total good bad) =
90 case progress of
90 case progress of
91
91
92
92
93+ -- ELM.JSON
94+
95+ ElmJsonApproved ->
96+ do putStrLn ""
97+ Help.toStdout $ D.fillSep $
98+ [ "Done!","And","check","out"
99+ ,D.green "<https://guide.elm-lang.org>"
100+ ,"to","learn","what","to","do","next!"
101+ ]
102+ putStrLn "\n"
103+ Help.toStdout $ D.black $ D.vcat $
104+ [ "--------------------------------------------------------------------------------"
105+ , "-------------------- Now back to what you were doing before --------------------"
106+ , "--------------------------------------------------------------------------------"
107+ ]
108+ putStrLn ""
109+ loop chan state
110+
111+ ElmJsonRejected ->
112+ do putStrLn "\nOkay, I did not create anything.\n"
113+ loop chan state
114+
115+
93 -- DOWNLOADS
116 -- DOWNLOADS
94
117
95 DownloadSkip ->
118 DownloadSkip ->