1{-# LANGUAGE OverloadedStrings #-}
11import qualified Data.ByteString.Builder as B
12import Data.Monoid ((<>))
13import System.IO (stderr)
14import qualified Text.PrettyPrint.ANSI.Leijen as P
16import qualified Elm.Compiler as Compiler
17import qualified Elm.Compiler.Module as Module
18import qualified Elm.Package as Pkg
19import qualified Elm.Utils as Utils
20import qualified Json.Encode as Encode
21import qualified Reporting.Exit.Assets as Asset
22import qualified Reporting.Exit.Bump as Bump
23import qualified Reporting.Exit.Compile as Compile
24import qualified Reporting.Exit.Crawl as Crawl
25import qualified Reporting.Exit.Deps as Deps
26import qualified Reporting.Exit.Diff as Diff
27import qualified Reporting.Exit.Help as Help
28import qualified Reporting.Exit.Http as Http
29import qualified Reporting.Exit.Publish as Publish
40 | Compile Compile.Exit [Compile.Exit]
42 | Cycle [Module.Raw] -- TODO write docs to help with this scenario
45 | Publish Publish.Exit
46 | BadHttp String Http.Exit
49 | NoSolution [Pkg.Name]
51 | CannotOptimizeDebug Module.Raw [Module.Raw]
58toString :: Exit -> String
60 Help.toString (Help.reportToDoc (toReport exit))
63toStderr :: Exit -> IO ()
65 Help.toStderr (Help.reportToDoc (toReport exit))
68toJson :: Exit -> IO ()
70 B.hPutBuilder stderr $ Encode.encodeUgly $ Help.reportToJson (toReport exit)
73toReport :: Exit -> Help.Report
77 Help.report "WELCOME" Nothing
78 "It looks like you are trying to start a new Elm project. Very exciting! :D"
80 ["I","very","highly","recommend","working","through"
81 ,P.green "<https://guide.elm-lang.org>","which","will","teach","you","the"
82 ,"basics","of","Elm,","including","how","to","start","new","projects."
85 ["For","folks","who","have","already","built","stuff","with","Elm,","the"
86 ,"problem","is","just","that","there","is","no",P.dullyellow "elm.json","yet."
87 ,"If","you","want","to","work","from","an","example,","check","out","the"
88 ,"one","at","<https://github.com/evancz/elm-todomvc/blob/master/elm.json>"
91 "Whatever your scenario, I hope you have a lovely time using Elm!"
95 Asset.toReport assetError
98 Bump.toReport bumpError
101 Help.compilerReport e es
104 Crawl.toReport crawlError
107 Help.report "IMPORT CYCLE" Nothing
108 "Your module imports form a cycle:"
109 [ P.indent 4 (Utils.drawCycle names)
111 "Learn more about why this is disallowed and how to break cycles here:"
112 ++ Help.hintLink "import-cycles"
116 Deps.toReport depsError
118 Diff commandsError ->
119 Diff.toReport commandsError
121 Publish publishError ->
122 Publish.toReport publishError
124 BadHttp url httpError ->
125 Http.toReport url httpError
127 NoSolution badPackages ->
130 Help.report "UNSOLVABLE DEPENDENCIES" (Just "elm.json")
131 "This usually happens if you try to modify dependency constraints by\
132 \ hand. I recommend deleting any dependency you added recently (or all\
133 \ of them if things are bad) and then adding them again with:"
134 [ P.indent 4 $ P.green "elm install"
136 "And do not be afaid to ask for help on Slack if you get stuck!"
140 Help.report "OLD DEPENDENCIES" (Just "elm.json")
141 ( "The following packages do not work with Elm " ++ Pkg.versionToString Compiler.version ++ " right now:"
143 [ P.indent 4 $ P.vcat $ map (P.red . P.text . Pkg.toString) badPackages
145 "This may be because it is not upgraded yet. It may be because a\
146 \ better solution came along, so there was no need to upgrade it.\
147 \ Etc. Try asking around on Slack to learn more about the topic."
149 "Whatever the case, please be kind to the relevant package authors! Having\
150 \ friendly interactions with users is great motivation, and conversely, getting\
151 \ berated by strangers on the internet sucks your soul dry. Furthermore, package\
152 \ authors are humans with families, friends, jobs, vacations, responsibilities,\
153 \ goals, etc. They face obstacles outside of their technical work you will never\
154 \ know about, so please assume the best and try to be patient and supportive!"
158 Help.report "NO INPUT" Nothing
159 "What should I make though? I need more information, like:"
161 [ P.indent 4 $ P.green "elm make MyThing.elm"
162 , P.indent 4 $ P.green "elm make This.elm That.elm"
165 "However many files you give, I will create one JS file out of them."
168 CannotOptimizeDebug m ms ->
169 Help.report "DEBUG REMNANTS" Nothing
170 "There are uses of the `Debug` module in the following modules:"
171 [ P.indent 4 $ P.red $ P.vcat $ map (P.text . Module.nameToString) (m:ms)
172 , Help.reflow "But the --optimize flag only works if all `Debug` functions are removed!"
174 "The issue is that --optimize strips out info needed by `Debug` functions.\
175 \ Here are two examples:"
176 , P.indent 4 $ Help.reflow $
177 "(1) It shortens record field names. This makes the generated JavaScript is\
178 \ smaller, but `Debug.toString` cannot know the real field names anymore."
179 , P.indent 4 $ Help.reflow $
180 "(2) Values like `type Height = Height Float` are unboxed. This reduces\
181 \ allocation, but it also means that `Debug.toString` cannot tell if it is\
182 \ looking at a `Height` or `Float` value."
184 "There are a few other cases like that, and it will be much worse once we start\
185 \ inlining code. That optimization could move `Debug.log` and `Debug.todo` calls,\
186 \ resulting in unpredictable behavior. I hope that clarifies why this restriction\
191toSimpleNote :: String -> P.Doc
192toSimpleNote message =
193 P.fillSep ((P.underline "Note" <> ":") : map P.text (words message))
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list