on master help sign in
Make creation of elm.json more like in 0.18
8097a73Evan Czaplicki
builder/src/Elm/Project/Root.hs+54−52
@@ -6,28 +6,27 @@ module Elm.Project.Root
6 )
6 )
7 where
7 where
8
8
9+
10+import Control.Monad (msum)
9import Control.Monad.Trans (liftIO)
11import Control.Monad.Trans (liftIO)
10−import qualified Data.ByteString.Lazy as LBS
11import qualified Data.Map as Map
12import qualified Data.Map as Map
12−import Data.Monoid ((<>))
13−import qualified Network.HTTP.Client as Client
14import qualified System.Directory as Dir
13import qualified System.Directory as Dir
15import System.FilePath ((</>))
14import System.FilePath ((</>))
16
15
16+import qualified Deps.Cache as Cache
17+import qualified Deps.Explorer as Explorer
18+import qualified Deps.Solver as Solver
17import qualified Elm.Compiler.Version as Elm
19import qualified Elm.Compiler.Version as Elm
18import qualified Elm.Package as Pkg
20import qualified Elm.Package as Pkg
19import qualified Elm.Project.Constraint as Con
21import qualified Elm.Project.Constraint as Con
20import qualified Elm.Project.Json as Project
22import qualified Elm.Project.Json as Project
21import qualified Elm.Project.Licenses as Licenses
23import qualified Elm.Project.Licenses as Licenses
22−import Elm.Project.Json (Project(..), PkgInfo(..))
23−import Elm.Project.Summary (Summary)
24+import qualified Elm.Project.Summary as Summary
24import qualified Elm.PerUserCache as PerUserCache
25import qualified Elm.PerUserCache as PerUserCache
25import qualified File.IO as IO
26import qualified File.IO as IO
26−import qualified Reporting.Doc as D
27import qualified Reporting.Exit as Exit
27import qualified Reporting.Exit as Exit
28import qualified Reporting.Progress as Progress
28import qualified Reporting.Progress as Progress
29import qualified Reporting.Task as Task
29import qualified Reporting.Task as Task
30−import qualified Reporting.Task.Http as Http
31import qualified Stuff.Verify as Verify
30import qualified Stuff.Verify as Verify
32import qualified Json.Encode as Encode
31import qualified Json.Encode as Encode
33
32
@@ -36,14 +35,14 @@ import qualified Json.Encode as Encode
36-- GET
35-- GET
37
36
38
37
39−get :: Task.Task Summary
38+get :: Task.Task Summary.Summary
40get =
39get =
41 do root <- moveToRoot
40 do root <- moveToRoot
42 project <- Project.read "elm.json"
41 project <- Project.read "elm.json"
43 Verify.verify root project
42 Verify.verify root project
44
43
45
44
46−unsafeGet :: Task.Task (FilePath, Project)
45+unsafeGet :: Task.Task (FilePath, Project.Project)
47unsafeGet =
46unsafeGet =
48 (,) <$> moveToRoot <*> Project.read "elm.json"
47 (,) <$> moveToRoot <*> Project.read "elm.json"
49
48
@@ -61,38 +60,41 @@ moveToRoot =
61 return root
60 return root
62
61
63 Nothing ->
62 Nothing ->
64− do approved <- Task.getApproval $ D.vcat $
63+ do addElmJson
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
64+ Task.report Progress.ElmJsonAdded
81− liftIO $ Dir.getCurrentDirectory
65+ liftIO $ Dir.getCurrentDirectory
82− else
66+
83− do Task.report Progress.ElmJsonRejected
67+
68+addElmJson :: Task.Task ()
69+addElmJson =
70+ do registry <- Cache.optionalUpdate
71+ maybeSolution <- Explorer.run registry $ Solver.run $
72+ msum $ map Solver.solve $
73+ [ defaultDependencies
74+ , Map.singleton Pkg.core Con.anything
75+ ]
76+ case maybeSolution of
77+ Nothing ->
84− Task.throw Exit.NoElmJson
78+ Task.throw Exit.NoElmJson
85−
79+
86−
80+ Just solution ->
87−fetch :: FilePath -> Task.Task ()
81+ liftIO $ Encode.write "elm.json" $ Project.encode $ Project.App $
88−fetch path =
82+ Project.AppInfo
89− Http.run $
83+ Elm.version
90− Http.anything
84+ ["src"]
91− ("https://experiment.elm-lang.org/" ++ Pkg.versionToString Elm.version ++ "/starter/" ++ path)
85+ (Map.intersection solution defaultDependencies)
92− (\request manager ->
86+ Map.empty
93− do response <- Client.httpLbs request manager
87+ (Map.difference solution defaultDependencies)
94− Right <$> LBS.writeFile path (Client.responseBody response)
88+
95− )
89+
90+defaultDependencies :: Map.Map Pkg.Name Con.Constraint
91+defaultDependencies =
92+ Map.fromList
93+ [ (Pkg.browser, Con.anything)
94+ , (Pkg.core, Con.anything)
95+ , (Pkg.html, Con.anything)
96+ , (Pkg.json, Con.anything)
97+ ]
96
98
97
99
98
100
@@ -114,19 +116,19 @@ getWithReplFallback =
114 Dir.createDirectoryIfMissing True root
116 Dir.createDirectoryIfMissing True root
115 Dir.setCurrentDirectory root
117 Dir.setCurrentDirectory root
116 IO.removeDir "elm-stuff"
118 IO.removeDir "elm-stuff"
117− Encode.write "elm.json" (Project.encode (Pkg replInfo))
119+ Encode.write "elm.json" (Project.encode (Project.Pkg replInfo))
118 return root
120 return root
119
121
120
122
121−replInfo :: PkgInfo
123+replInfo :: Project.PkgInfo
122replInfo =
124replInfo =
123− PkgInfo
125+ Project.PkgInfo
124− { _pkg_name = Pkg.dummyName
126+ { Project._pkg_name = Pkg.dummyName
125− , _pkg_summary = "dummy code for the REPL"
127+ , Project._pkg_summary = "dummy code for the REPL"
126− , _pkg_license = Licenses.bsd3
128+ , Project._pkg_license = Licenses.bsd3
127− , _pkg_version = Pkg.dummyVersion
129+ , Project._pkg_version = Pkg.dummyVersion
128− , _pkg_exposed = Project.ExposedList []
130+ , Project._pkg_exposed = Project.ExposedList []
129− , _pkg_deps = Map.singleton Pkg.core Con.anything
131+ , Project._pkg_deps = Map.singleton Pkg.core Con.anything
130− , _pkg_test_deps = Map.empty
132+ , Project._pkg_test_deps = Map.empty
131− , _pkg_elm_version = Con.defaultElm
133+ , Project._pkg_elm_version = Con.defaultElm
132 }
134 }
builder/src/Reporting/Progress.hs+1−2
@@ -71,8 +71,7 @@ data Msg
71
71
72data Progress
72data Progress
73 -- elm.json
73 -- elm.json
74− = ElmJsonApproved
74+ = ElmJsonAdded
75− | ElmJsonRejected
76
75
77 -- download packages
76 -- download packages
78 | DownloadSkip
77 | DownloadSkip
builder/src/Reporting/Progress/Terminal.hs+5−15
@@ -92,24 +92,14 @@ loopHelp chan progress state@(State total good bad) =
92
92
93 -- ELM.JSON
93 -- ELM.JSON
94
94
95− ElmJsonApproved ->
95+ ElmJsonAdded ->
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 $
96+ do Help.toStdout $ D.black $ D.vcat $ map D.fromString $
104 [ "--------------------------------------------------------------------------------"
97 [ "--------------------------------------------------------------------------------"
105− , "-------------------- Now back to what you were doing before --------------------"
98+ , " Looks like you are starting a new Elm project, so I added an elm.json file."
99+ , " Read " ++ D.makeLink "get-started" ++ " for tips on what to do next!"
106 , "--------------------------------------------------------------------------------"
100 , "--------------------------------------------------------------------------------"
107 ]
101 ]
108− putStrLn "\n"
102+ putStrLn ""
109− loop chan state
110−
111− ElmJsonRejected ->
112− do putStrLn "\nOkay, I did not create anything.\n"
113 loop chan state
103 loop chan state
114
104
115
105