@@ -1,6 +1,28 @@
11{-# LANGUAGE OverloadedStrings #-}
22module Reporting.Exit
33 ( Exit(..)
4+ --
5+ , Init(..)
6+ , initToReport
7+ --
8+ , Diff(..)
9+ , diffToReport
10+ --
11+ , Install(..)
12+ , installToReport
13+ --
14+ , Details(..)
15+ , OutlineProblem(..)
16+ , OutlineStructureProblem(..)
17+ , RegistryProblem(..)
18+ , PackageProblem(..)
19+ --
20+ , Make(..)
21+ , BuildProblem(..)
22+ , BuildProjectProblem(..)
23+ , makeToReport
24+ --
25+ , DocsProblem(..)
426 , toString
527 , toStderr
628 , toJson
@@ -8,21 +30,21 @@ module Reporting.Exit
830 where
931
1032
33+import qualified Data.List as List
34+import qualified Data.Utf8 as Utf8
35+
36+import qualified Elm.Constraint as C
37+import qualified Elm.Magnitude as M
1138import qualified Elm.ModuleName as ModuleName
39+import qualified Elm.Package as Pkg
40+import qualified Elm.Version as V
41+import qualified Http
1242import qualified Json.Encode as Encode
43+import Reporting.Doc ((<>))
1344import qualified Reporting.Doc as D
14−import qualified Reporting.Exit.Assets as Asset
15−import qualified Reporting.Exit.Bump as Bump
16−import qualified Reporting.Exit.Compile as Compile
17−import qualified Reporting.Exit.Crawl as Crawl
18−import qualified Reporting.Exit.Deps as Deps
19−import qualified Reporting.Exit.Diff as Diff
45+import qualified Reporting.Error.Json as Json
2046import qualified Reporting.Exit.Help as Help
21−import qualified Reporting.Exit.Http as Http
22−import qualified Reporting.Exit.Make as Make
23−import qualified Reporting.Exit.Init as Init
24−import qualified Reporting.Exit.Install as Install
25−import qualified Reporting.Exit.Publish as Publish
47+import qualified Reporting.Problem as Problem
2648
2749
2850
@@ -30,44 +52,605 @@ import qualified Reporting.Exit.Publish as Publish
3052
3153
3254data Exit
33− = NoElmJson
34− | Assets Asset.Exit
35− | Bump Bump.Exit
36− | Compile Compile.Exit [Compile.Exit]
37− | Crawl Crawl.Exit
38− | Cycle [ModuleName.Raw] -- TODO write docs to help with this scenario
39− | Deps Deps.Exit
40− | Diff Diff.Exit
41− | Make Make.Exit
42− | Init Init.Exit
43− | Install Install.Exit
44− | Publish Publish.Exit
45− | BadHttp String Http.Exit
55+ -- bump
56+ = BumpApplication
57+ | BumpUnexpectedVersion V.Version [V.Version]
58+ | BumpMustHaveLatestRegistry RegistryProblem
59+ | BumpCannotFindDocs Pkg.Name V.Version DocsProblem
60+ -- publish
61+ | PublishMustHaveLatestRegistry RegistryProblem
62+ | PublishApplication
63+ | PublishNotInitialVersion V.Version
64+ | PublishAlreadyPublished V.Version
65+ | PublishInvalidBump V.Version V.Version
66+ | PublishBadBump V.Version V.Version M.Magnitude V.Version M.Magnitude
67+ | PublishNoSummary
68+ | PublishNoExposed
69+ | PublishNoReadme
70+ | PublishShortReadme
71+ | PublishNoLicense
72+ | PublishCannotGetTag Http.Error
73+ | PublishCannotGetZip Http.Error
74+ | PublishCannotDecodeZip
75+ | PublishCannotGetDocs DocsProblem
76+ | PublishCannotRegister Http.Error
77+ | PublishMissingTag V.Version
78+ | PublishNoGit
79+ | PublishLocalChanges V.Version
80+
81+
82+data DocsProblem
83+ = DP_Http Http.Error
84+ | DP_Data
85+ | DP_Cache
86+
87+
88+
89+-- INIT
90+
91+
92+data Init
93+ = InitNoSolution [Pkg.Name]
94+ | InitAlreadyExists
95+ | InitRegistryProblem RegistryProblem
96+
97+
98+initToReport :: Init -> Help.Report
99+initToReport exit =
100+ case exit of
101+ InitNoSolution pkgs ->
102+ Help.report "NO SOLUTION" Nothing
103+ "I tried to create an elm.json with the following direct dependencies:"
104+ [ D.indent 4 $ D.vcat $
105+ map (D.dullyellow . D.fromChars . Pkg.toChars) pkgs
106+ , D.reflow $
107+ "I could not find compatible versions though! This should not happen, so please\
108+ \ ask around one of the community forums at https://elm-lang.org/community to learn\
109+ \ what is going on!"
110+ ]
111+
112+ InitAlreadyExists ->
113+ Help.report "EXISTING PROJECT" Nothing
114+ "You already have an elm.json file, so there is nothing for me to initialize!"
115+ [ D.fillSep
116+ ["Maybe",D.green (D.fromChars (D.makeLink "init")),"can","help"
117+ ,"you","figure","out","what","to","do","next?"
118+ ]
119+ ]
120+
121+ InitRegistryProblem _ ->
122+ error "TODO InitRegistryProblem"
123+
124+
125+
126+-- DIFF
127+
128+
129+data Diff
130+ = DiffApplication
131+ | DiffUnpublished
132+ | DiffUnknownPackage Pkg.Name [Pkg.Name]
133+ | DiffUnknownVersion Pkg.Name V.Version [V.Version]
134+ | DiffCannotFindDocs DocsProblem
135+ | DiffMustHaveLatestRegistry RegistryProblem
136+
137+
138+diffToReport :: Diff -> Help.Report
139+diffToReport diff =
140+ case diff of
141+ DiffApplication ->
142+ Help.report "CANNOT DIFF APPLICATIONS" Nothing
143+ "I cannot perform diffs on applications, only packages! If you are\
144+ \ just curious to see a diff, try running this command:"
145+ [ D.indent 4 $ D.green $ "elm diff elm/html 5.1.1 6.0.0"
146+ ]
147+
148+ DiffUnpublished ->
149+ Help.report "UNPUBLISHED" Nothing
150+ "This package is not published yet. There is nothing to diff against!"
151+ []
152+
153+ DiffUnknownPackage pkg suggestions ->
154+ Help.report "UNKNOWN PACKAGE" Nothing
155+ ( "I cannot find a package called:"
156+ )
157+ [ D.indent 4 $ D.red $ D.fromUtf8 $ Pkg.toString pkg
158+ , "Maybe you want one of these instead?"
159+ , D.indent 4 $ D.dullyellow $ D.vcat $ map (D.fromUtf8 . Pkg.toString) suggestions
160+ , "But check <https://package.elm-lang.org> to see all possibilities!"
161+ ]
162+
163+ DiffUnknownVersion _pkg vsn realVersions ->
164+ Help.docReport "UNKNOWN VERSION" Nothing
165+ ( D.fillSep $
166+ [ "Version", D.red (D.fromUtf8 (V.toString vsn))
167+ , "has", "never", "been", "published,", "so", "I"
168+ , "cannot", "diff", "against", "it."
169+ ]
170+ )
171+ [ "Here are all the versions that HAVE been published:"
172+ , D.indent 4 $ D.dullyellow $ D.vcat $
173+ let
174+ sameMajor v1 v2 = V._major v1 == V._major v2
175+ mkRow vsns = D.hsep $ map (D.fromUtf8 . V.toString) vsns
176+ in
177+ map mkRow $ List.groupBy sameMajor (List.sort realVersions)
178+ , "Want one of those instead?"
179+ ]
180+
181+ DiffCannotFindDocs problem ->
182+ error "TODO DiffCannotFindDocs" problem
183+
184+ DiffMustHaveLatestRegistry problem ->
185+ error "TODO DiffMustHaveLatestRegistry" problem
186+
187+
188+
189+-- INSTALL
190+
191+
192+data Install
193+ = InstallNoArgs FilePath
194+ | InstallNoSolution [Pkg.Name]
195+
196+
197+installToReport :: Install -> Help.Report
198+installToReport exit =
199+ case exit of
200+ InstallNoArgs elmHome ->
201+ Help.report "INSTALL WHAT?" Nothing
202+ "I am expecting commands like:"
203+ [ D.green $ D.indent 4 $ D.vcat $
204+ [ "elm install elm/http"
205+ , "elm install elm/json"
206+ , "elm install elm/random"
207+ ]
208+ , D.toFancyHint
209+ ["In","JavaScript","folks","run","`npm install`","to","start","projects."
210+ ,"\"Gotta","download","everything!\"","But","why","download","packages"
211+ ,"again","and","again?","Instead,","Elm","caches","packages","in"
212+ ,D.dullyellow (D.fromChars elmHome)
213+ ,"so","each","one","is","downloaded","and","built","ONCE","on","your","machine."
214+ ,"Elm","projects","check","that","cache","before","trying","the","internet."
215+ ,"This","reduces","build","times,","reduces","server","costs,","and","makes","it"
216+ ,"easier","to","work","offline.","As","a","result"
217+ ,D.dullcyan "elm install","is","only","for","adding","dependencies","to","elm.json,"
218+ ,"whereas",D.dullcyan "elm make","is","in","charge","of","gathering","dependencies"
219+ ,"and","building","everything.","So","maybe","try",D.green "elm make","instead?"
220+ ]
221+ ]
222+
223+ InstallNoSolution badPackages ->
224+ case badPackages of
225+ [] ->
226+ Help.report "UNSOLVABLE DEPENDENCIES" (Just "elm.json") -- TODO give better advice!
227+ "This usually happens if you try to modify dependency constraints by\
228+ \ hand. I recommend deleting any dependency you added recently (or all\
229+ \ of them if things are bad) and then adding them again with:"
230+ [ D.indent 4 $ D.green "elm install"
231+ , D.reflow $
232+ "And do not be afaid to ask for help on Slack if you get stuck!"
233+ ]
234+
235+ _:_ ->
236+ Help.report "OLD DEPENDENCIES" (Just "elm.json")
237+ ( "The following packages do not work with Elm " ++ V.toChars V.compiler ++ " right now:"
238+ )
239+ [ D.indent 4 $ D.vcat $ map (D.red . D.fromUtf8 . Pkg.toString) badPackages
240+ , D.reflow $
241+ "This may be because it is not upgraded yet. It may be because a\
242+ \ better solution came along, so there was no need to upgrade it.\
243+ \ Etc. Try asking around on Slack to learn more about the topic."
244+ , D.toSimpleNote
245+ "Whatever the case, please be kind to the relevant package authors! Having\
246+ \ friendly interactions with users is great motivation, and conversely, getting\
247+ \ berated by strangers on the internet sucks your soul dry. Furthermore, package\
248+ \ authors are humans with families, friends, jobs, vacations, responsibilities,\
249+ \ goals, etc. They face obstacles outside of their technical work you will never\
250+ \ know about, so please assume the best and try to be patient and supportive!"
251+ ]
252+
253+
254+
255+-- DETAILS
256+
257+
258+data Details
259+ = DetailsCorrupt
260+ | DetailsBadElmInPkg C.Constraint
261+ | DetailsBadElmInAppOutline V.Version
262+ | DetailsHandEditedDependencies
263+ | DetailsBadOutline OutlineProblem
264+ | DetailsCannotGetRegistry RegistryProblem
265+ | DetailsCannotBuildPackage Pkg.Name V.Version PackageProblem
266+
267+
268+data OutlineProblem
269+ = BadOutlineStructure (Json.Error OutlineStructureProblem)
270+ | BadOutlineSrcDirs FilePath [FilePath]
271+
272+
273+data OutlineStructureProblem
274+ = OSP_BadType Utf8.String
275+ | OSP_BadPkgName Pkg.BadName
276+ | OSP_BadVersion Utf8.String
277+ | OSP_BadConstraint C.Error
278+ | OSP_BadModuleName Utf8.String
279+ | OSP_BadModuleHeaderTooLong Utf8.String
280+ | OSP_BadDependencyName Utf8.String
281+ | OSP_BadLicense Utf8.String [Utf8.String]
282+ | OSP_BadSummaryTooLong
283+
284+
285+data RegistryProblem
286+ = RP_Http Http.Error
287+ | RP_Data
288+
289+
290+data PackageProblem
291+ = PP_BadEndpointRequest Http.Error
292+ | PP_BadEndpointContent
293+ | PP_BadArchiveRequest Http.Error
294+ | PP_BadArchiveContent
295+ | PP_BadArchiveHash String String
296+
297+
298+
299+-- MAKE
300+
301+
302+data Make
303+ = MakeNeedsOutline
304+ | MakeCannotOptimizeAndDebug
305+ | MakeBlockedByDetailsProblem Details
306+ | MakeAppNeedsFileNames
307+ | MakePkgNeedsExposing
308+ | MakeMultipleFilesIntoHtml
309+ | MakeNonMainFilesIntoJavaScript ModuleName.Raw [ModuleName.Raw]
310+ | MakeCannotOptimizeDebugValues ModuleName.Raw [ModuleName.Raw]
311+ | MakeCannotBuild BuildProblem
312+ | MakeCannotLoadArtifacts
313+
314+
315+data BuildProblem
316+ = BuildModuleProblems Problem.Problem [Problem.Problem]
317+ | BuildProjectProblem BuildProjectProblem
318+
319+
320+data BuildProjectProblem
321+ = BP_PathUnknown FilePath
322+ | BP_WithBadExtension FilePath
323+ | BP_WithAmbiguousSrcDir FilePath FilePath
324+ | BP_MainPathDuplicate FilePath FilePath
325+ | BP_MainNameDuplicate ModuleName.Raw FilePath FilePath
326+ | BP_CannotLoadDependencies
327+ | BP_Cycle ModuleName.Raw [ModuleName.Raw]
46328
47329
48330
49331-- RENDERERS
50332
51333
52−toString :: Exit -> String
53−toString exit =
54− Help.toString (Help.reportToDoc (toReport exit))
334+toString :: Help.Report -> String
335+toString report =
336+ Help.toString (Help.reportToDoc report)
55337
56338
57−toStderr :: Exit -> IO ()
58−toStderr exit =
59− Help.toStderr (Help.reportToDoc (toReport exit))
339+toStderr :: Help.Report -> IO ()
340+toStderr report =
341+ Help.toStderr (Help.reportToDoc report)
60342
61343
62−toJson :: Exit -> Encode.Value
63−toJson exit =
64− Help.reportToJson (toReport exit)
344+toJson :: Help.Report -> Encode.Value
345+toJson report =
346+ Help.reportToJson report
65347
66348
67−toReport :: Exit -> Help.Report
68−toReport exit =
349+_toReport :: Exit -> Help.Report
350+_toReport exit =
69351 case exit of
70− NoElmJson ->
352+
353+ -- bump
354+
355+ BumpApplication ->
356+ Help.report "CANNOT BUMP APPLICATIONS" (Just "elm.json")
357+ "Your elm.json says this is an application. That means it cannot be published\
358+ \ on <https://package.elm-lang.org> and therefore has no version to bump!"
359+ []
360+
361+ BumpUnexpectedVersion vsn versions ->
362+ Help.docReport "CANNOT BUMP" (Just "elm.json")
363+ ( D.fillSep
364+ ["Your","elm.json","says","I","should","bump","relative","to","version"
365+ ,D.red (D.fromUtf8 (V.toString vsn)) <> ","
366+ ,"but","I","cannot","find","that","version","on","<https://package.elm-lang.org>."
367+ ,"That","means","there","is","no","API","for","me","to","diff","against","and"
368+ ,"figure","out","if","these","are","MAJOR,","MINOR,","or","PATCH","changes."
369+ ]
370+ )
371+ [ D.fillSep $
372+ ["Try","bumping","again","after","changing","the",D.dullyellow "\"version\"","in","elm.json"]
373+ ++ if length versions == 1 then ["to:"] else ["to","one","of","these:"]
374+ , D.vcat $ map (D.green . D.fromUtf8 . V.toString) versions
375+ ]
376+
377+ BumpMustHaveLatestRegistry problem ->
378+ error "TODO BumpMustHaveLatestRegistry" problem
379+
380+ BumpCannotFindDocs name version problem ->
381+ error "TODO BumpCannotFindDocs" name version problem
382+
383+ -- publish
384+
385+ PublishMustHaveLatestRegistry problem ->
386+ error "TODO PublishMustHaveLatestRegistry" problem
387+
388+ PublishApplication ->
389+ Help.report "UNPUBLISHABLE" Nothing "I cannot publish applications, only packages!" []
390+
391+ PublishNotInitialVersion vsn ->
392+ Help.docReport "INVALID VERSION" Nothing
393+ ( D.fillSep
394+ ["I","cannot","publish"
395+ ,D.red (D.fromUtf8 (V.toString vsn))
396+ ,"as","the","initial","version."
397+ ]
398+ )
399+ [ D.fillSep
400+ ["Change","it","to",D.green "1.0.0","which","is"
401+ ,"the","initial","version","for","all","Elm","packages."
402+ ]
403+ ]
404+
405+ PublishAlreadyPublished vsn ->
406+ Help.docReport "ALREADY PUBLISHED" Nothing
407+ ( D.vcat
408+ [ D.fillSep
409+ [ "Version", D.green (D.fromUtf8 (V.toString vsn))
410+ , "has", "already", "been", "published.", "You", "cannot"
411+ , "publish", "it", "again!"
412+ ]
413+ , "Try using the `bump` command:"
414+ ]
415+ )
416+ [ D.dullyellow $ D.indent 4 "elm bump"
417+ , D.reflow $
418+ "It computes the version number based on API changes, ensuring\
419+ \ that no breaking changes end up in PATCH releases!"
420+ ]
421+
422+ PublishInvalidBump statedVersion latestVersion ->
423+ Help.docReport "INVALID VERSION" (Just "elm.json")
424+ ( D.fillSep $
425+ ["Your","elm.json","says","the","next","version","should","be"
426+ ,D.red (D.fromUtf8 (V.toString statedVersion)) <> ","
427+ ,"but","that","is","not","valid","based","on","the","previously"
428+ ,"published","versions."
429+ ]
430+ )
431+ [ D.fillSep $
432+ ["Change","the","version","back","to"
433+ ,D.green (D.fromUtf8 (V.toString latestVersion))
434+ ,"which","is","the","most","recently","published","version."
435+ ,"From","there,","have","Elm","bump","the","version","by","running:"
436+ ]
437+ , D.indent 4 $ D.green "elm bump"
438+ , D.reflow $
439+ "If you want more insight on the API changes Elm detects, you\
440+ \ can run `elm diff` at this point as well."
441+ ]
442+
443+ PublishBadBump old new magnitude realNew realMagnitude ->
444+ Help.docReport "INVALID VERSION" (Just "elm.json")
445+ (
446+ D.fillSep $
447+ ["Your","elm.json","says","the","next","version","should","be"
448+ ,D.red (D.fromUtf8 (V.toString new)) <> ","
449+ ,"indicating","a",D.fromChars (M.toChars magnitude)
450+ ,"change","to","the","public","API."
451+ ,"This","does","not","match","the","API","diff","given","by:"
452+ ]
453+ )
454+ [ D.indent 4 $ D.fromChars $
455+ "elm diff " ++ V.toChars old
456+
457+ , D.fillSep $
458+ ["This","command","says","this","is","a"
459+ ,D.fromChars (M.toChars realMagnitude)
460+ ,"change,","so","the","next","version","should","be"
461+ ,D.green (D.fromUtf8 (V.toString realNew)) <> "."
462+ ,"Double","check","everything","to","make","sure","you"
463+ ,"are","publishing","what","you","want!"
464+ ]
465+ , D.reflow $
466+ "Also, next time use `elm bump` and I'll figure all this out for you!"
467+ ]
468+
469+ PublishNoSummary ->
470+ Help.docReport "NO SUMMARY" (Just "elm.json")
471+ ( D.fillSep $
472+ [ "To", "publish", "a", "package,", "your", "elm.json", "must"
473+ , "have", "a", D.dullyellow "\"summary\"", "field", "that", "gives"
474+ , "a", "consice", "overview", "of", "your", "project."
475+ ]
476+ )
477+ [ D.reflow $
478+ "The summary must be less than 80 characters. It should describe\
479+ \ the concrete use of your package as clearly and as plainly as possible."
480+ ]
481+
482+ PublishNoExposed ->
483+ Help.docReport "NO EXPOSED MODULES" (Just "elm.json")
484+ ( D.fillSep $
485+ [ "To", "publish", "a", "package,", "the"
486+ , D.dullyellow "\"exposed-modules\"", "field", "of", "your"
487+ , "elm.json", "must", "list", "at", "least", "one", "module."
488+ ]
489+ )
490+ [ D.reflow $
491+ "What is the point of a package that has no modules?!"
492+ ]
493+
494+ PublishNoReadme ->
495+ badReadmeReport "NO README" $
496+ "Every published package must have a helpful README.md\
497+ \ file, but I do not see one in your project."
498+
499+ PublishShortReadme ->
500+ badReadmeReport "SHORT README" $
501+ "This README.md is too short. Having more details will help\
502+ \ people assess your package quickly and fairly."
503+
504+ PublishNoLicense ->
505+ Help.report "NO LICENSE FILE" (Just "LICENSE")
506+ "By publishing a package you are inviting the Elm community to build\
507+ \ upon your work. But without knowing your license, we have no idea if\
508+ \ that is legal!"
509+ [ D.reflow $
510+ "Once you pick an OSI approved license from <https://spdx.org/licenses/>,\
511+ \ you must share that choice in two places. First, the license\
512+ \ identifier must appear in your elm.json file. Second, the full\
513+ \ license text must appear in the root of your project in a file\
514+ \ named LICENSE. Add that file and you will be all set!"
515+ ]
516+
517+ PublishCannotGetTag httpError ->
518+ error "TODO PublishCannotGetTag" httpError
519+
520+ PublishCannotGetZip httpError ->
521+ error "TODO PublishCannotGetZip" httpError
522+
523+ PublishCannotDecodeZip ->
524+ error "TODO PublishCannotDecodeZip"
525+
526+ PublishCannotGetDocs docsProblem ->
527+ error "TODO PublishCannotGetDocs" docsProblem
528+
529+ PublishCannotRegister httpError ->
530+ error "TODO PublishCannotRegister" httpError
531+
532+ PublishMissingTag version ->
533+ let vsn = V.toChars version in
534+ Help.docReport "NO TAG" Nothing
535+ ( D.fillSep $
536+ [ "Packages", "must", "be", "tagged", "in", "git,", "but", "I"
537+ , "cannot", "find", "a", D.green (D.fromChars vsn), "tag."
538+ ]
539+ )
540+ [ D.vcat
541+ [ "These tags make it possible to find this specific version on GitHub."
542+ , "To tag the most recent commit and push it to GitHub, run this:"
543+ ]
544+ , D.indent 4 $ D.dullyellow $ D.vcat $ map D.fromChars $
545+ [ "git tag -a " ++ vsn ++ " -m \"new release\""
546+ , "git push origin " ++ vsn
547+ ]
548+ , "The -m flag is for a helpful message. Try to make it more informative!"
549+ ]
550+
551+ PublishNoGit ->
552+ Help.report "NO GIT" Nothing
553+ "I searched your PATH environment variable for `git` and could not\
554+ \ find it. Is it available through your PATH?"
555+ [ D.reflow $
556+ "Who cares about this? Well, I currently use `git` to check if there\
557+ \ are any local changes in your code. Local changes are a good sign\
558+ \ that some important improvements have gotten mistagged, so this\
559+ \ check can be extremely helpful for package authors!"
560+ , D.toSimpleNote $
561+ "We plan to do this without the `git` binary in a future release."
562+ ]
563+
564+ PublishLocalChanges version ->
565+ let vsn = V.toChars version in
566+ Help.docReport "LOCAL CHANGES" Nothing
567+ ( D.fillSep $
568+ [ "The", "code", "tagged", "as", D.green (D.fromChars vsn), "in"
569+ , "git", "does", "not", "match", "the", "code", "in", "your"
570+ , "working", "directory.", "This", "means", "you", "have"
571+ , "commits", "or", "local", "changes", "that", "are", "not"
572+ , "going", "to", "be", "published!"
573+ ]
574+ )
575+ [ D.toSimpleNote $
576+ "If you are sure everything is in order, you can run `git checkout "
577+ ++ vsn ++ "` and publish your code from there."
578+ ]
579+
580+
581+badReadmeReport :: String -> String -> Help.Report
582+badReadmeReport title summary =
583+ Help.report title (Just "README.md") summary
584+ [ D.reflow $
585+ "When people look at your README, they are wondering:"
586+ , D.vcat
587+ [ " - What does this package even do?"
588+ , " - Will it help me solve MY problems?"
589+ ]
590+ , D.reflow $
591+ "So I recommend starting your README with a small example of the\
592+ \ most common usage scenario. Show people what they can expect if\
593+ \ they learn more!"
594+ , D.toSimpleNote $
595+ "By publishing your package, you are inviting people to invest time\
596+ \ in understanding your work. Spending an hour to communicate your\
597+ \ knowledge more clearly can save the community days or weeks of time\
598+ \ in aggregate, and saving time in aggregate is the whole point of\
599+ \ publishing packages! People really appreciate it, and it makes the\
600+ \ whole ecosystem feel nicer!"
601+ ]
602+
603+
604+
605+-- DETAILS TO REPORT
606+
607+
608+detailsToReport :: Details -> Help.Report
609+detailsToReport details =
610+ case details of
611+ DetailsCorrupt ->
612+ error "TODO DetailsCorrupt"
613+
614+ DetailsBadElmInPkg constraint ->
615+ Help.report "ELM VERSION MISMATCH" (Just "elm.json")
616+ "Your elm.json says this package needs a version of Elm in this range:"
617+ [ D.indent 4 $ D.dullyellow $ D.fromUtf8 $ C.toString constraint
618+ , D.fillSep
619+ [ "But", "you", "are", "using", "Elm"
620+ , D.red (D.fromUtf8 (V.toString V.compiler))
621+ , "right", "now."
622+ ]
623+ ]
624+
625+ DetailsBadElmInAppOutline version ->
626+ Help.report "ELM VERSION MISMATCH" (Just "elm.json")
627+ "Your elm.json says this application needs a different version of Elm."
628+ [ D.fillSep
629+ [ "It", "requires"
630+ , D.green (D.fromUtf8 (V.toString version)) <> ","
631+ , "but", "you", "are", "using"
632+ , D.red (D.fromUtf8 (V.toString V.compiler))
633+ , "right", "now."
634+ ]
635+ ]
636+
637+ DetailsHandEditedDependencies ->
638+ error "TODO DetailsHandEditedDependencies"
639+
640+ DetailsBadOutline problem ->
641+ error "TODO DetailsBadOutline" problem
642+
643+ DetailsCannotGetRegistry problem ->
644+ error "TODO DetailsCannotGetRegistry" problem
645+
646+ DetailsCannotBuildPackage name version problem ->
647+ error "TODO DetailsCannotBuildPackage" name version problem
648+
649+
650+makeToReport :: Make -> Help.Report
651+makeToReport make =
652+ case make of
653+ MakeNeedsOutline ->
71654 Help.report "NO elm.json FILE" Nothing
72655 "It looks like you are starting a new Elm project. Very exciting! Try running:"
73656 [ D.indent 4 $ D.green $ "elm init"
@@ -75,44 +658,83 @@ toReport exit =
75658 "It will help you get set up. It is really simple!"
76659 ]
77660
78− Assets assetExit ->
79− Asset.toReport assetExit
80−
81− Bump bumpExit ->
82− Bump.toReport bumpExit
83−
84− Compile e es ->
85− Help.compilerReport e es
661+ MakeCannotOptimizeAndDebug ->
662+ Help.docReport "CLASHING FLAGS" Nothing
663+ ( D.fillSep
664+ ["I","cannot","compile","with",D.red "--optimize","and"
665+ ,D.red "--debug","at","the","same","time."
666+ ]
667+ )
668+ [ D.reflow
669+ "I need to take away information to optimize things, and I need to\
670+ \ add information to add the debugger. It is impossible to do both\
671+ \ at once though! Pick just one of those flags and it should work!"
672+ ]
86673
87− Crawl crawlExit ->
88− Crawl.toReport crawlExit
674+ MakeBlockedByDetailsProblem detailsProblem ->
675+ detailsToReport detailsProblem
89676
90− Cycle names ->
91− Help.report "IMPORT CYCLE" Nothing
92− "Your module imports form a cycle:"
93− [ D.cycle 4 names
94− , D.reflow $
95− "Learn more about why this is disallowed and how to break cycles here:"
96− ++ D.makeLink "import-cycles"
677+ MakeAppNeedsFileNames ->
678+ Help.report "NO INPUT" Nothing
679+ "What should I make though? I need a specific file like this:"
680+ [ D.indent 4 $ D.green "elm make src/Main.elm"
681+ , D.reflow
682+ "However many files you give, I will create one JS file out of them."
97683 ]
98684
99− Deps depsExit ->
100− Deps.toReport depsExit
685+ MakePkgNeedsExposing ->
686+ error "TODO MakePkgNeedsExposing"
687+
688+ MakeMultipleFilesIntoHtml ->
689+ error "TODO MakeMultipleFilesIntoHtml"
101690
102− Diff commandsExit ->
103− Diff.toReport commandsExit
691+ MakeNonMainFilesIntoJavaScript _ _ ->
692+ error "TODO MakeNonMainFilesIntoJavaScript"
104693
105− Make makeExit ->
106− Make.toReport makeExit
694+ MakeCannotOptimizeDebugValues m ms ->
695+ Help.report "DEBUG REMNANTS" Nothing
696+ "There are uses of the `Debug` module in the following modules:"
697+ [ D.indent 4 $ D.red $ D.vcat $ map (D.fromChars . ModuleName.toChars) (m:ms)
698+ , D.reflow "But the --optimize flag only works if all `Debug` functions are removed!"
699+ , D.toSimpleNote $
700+ "The issue is that --optimize strips out info needed by `Debug` functions.\
701+ \ Here are two examples:"
702+ , D.indent 4 $ D.reflow $
703+ "(1) It shortens record field names. This makes the generated JavaScript is\
704+ \ smaller, but `Debug.toString` cannot know the real field names anymore."
705+ , D.indent 4 $ D.reflow $
706+ "(2) Values like `type Height = Height Float` are unboxed. This reduces\
707+ \ allocation, but it also means that `Debug.toString` cannot tell if it is\
708+ \ looking at a `Height` or `Float` value."
709+ , D.reflow $
710+ "There are a few other cases like that, and it will be much worse once we start\
711+ \ inlining code. That optimization could move `Debug.log` and `Debug.todo` calls,\
712+ \ resulting in unpredictable behavior. I hope that clarifies why this restriction\
713+ \ exists!"
714+ ]
107715
108− Init initExit ->
109− Init.toReport initExit
716+ MakeCannotBuild buildProblem ->
717+ case buildProblem of
718+ BuildProjectProblem bp ->
719+ case bp of
720+ BP_PathUnknown _ -> error "TODO BP_PathUnknown"
721+ BP_WithBadExtension _ -> error "TODO BP_WithBadExtension"
722+ BP_WithAmbiguousSrcDir _ _ -> error "TODO BP_WithAmbiguousSrcDir"
723+ BP_MainPathDuplicate _ _ -> error "TODO BP_MainPathDuplicate"
724+ BP_MainNameDuplicate _ _ _ -> error "TODO BP_MainNameDuplicate"
725+ BP_CannotLoadDependencies -> error "TODO BP_CannotLoadDependencies"
726+ BP_Cycle name names ->
727+ Help.report "IMPORT CYCLE" Nothing
728+ "Your module imports form a cycle:"
729+ [ D.cycle 4 name names
730+ , D.reflow $
731+ "Learn more about why this is disallowed and how to break cycles here:"
732+ ++ D.makeLink "import-cycles"
733+ ]
110734
111− Install installExit ->
112− Install.toReport installExit
113735
114− Publish publishExit ->
115− Publish.toReport publishExit
736+ BuildModuleProblems p ps ->
737+ error "TODO MakeCannotBuild" p ps
116738
117− BadHttp url httpExit ->
118− Http.toReport url httpExit
739+ MakeCannotLoadArtifacts ->
740+ error "TODO MakeCannotLoadArtifacts"