on master help sign in
add error messages on --output with unexpected # of files
commit26f809e75a3c244bdf291222a557018065e2fbf9 authorEvan Czaplicki <evancz@users.noreply.github.com> dateWed 26 Jun 2019, 14:24 (7 years ago) parentaac806c
2 files changed+100−18
builder/src/Reporting/Exit.hs+94−8 terminal/src/Make.hs+6−10
builder/src/Reporting/Exit.hs+94−8
@@ -1473,6 +1473,7 @@ data Make
14731473 | MakeAppNeedsFileNames
14741474 | MakePkgNeedsExposing
14751475 | MakeMultipleFilesIntoHtml
1476+ | MakeNoMain
14761477 | MakeNonMainFilesIntoJavaScript ModuleName.Raw [ModuleName.Raw]
14771478 | MakeCannotBuild BuildProblem
14781479 | MakeBadGenerate Generate
@@ -1507,20 +1508,105 @@ makeToReport make =
15071508
15081509 MakeAppNeedsFileNames ->
15091510 Help.report "NO INPUT" Nothing
1510− "What should I make though? I need a specific file like this:"
1511− [ D.indent 4 $ D.green "elm make src/Main.elm"
1512− , D.reflow
1513− "However many files you give, I will create one JS file out of them."
1511+ "What should I make though? I need specific files like:"
1512+ [ D.vcat
1513+ [ D.indent 4 $ D.green "elm make src/Main.elm"
1514+ , D.indent 4 $ D.green "elm make src/This.elm src/That.elm"
1515+ ]
1516+ , D.reflow $
1517+ "I recommend reading through https://guide.elm-lang.org for guidance on what to\
1518+ \ actually put in those files!"
15141519 ]
15151520
15161521 MakePkgNeedsExposing ->
1517− error "TODO MakePkgNeedsExposing"
1522+ Help.report "NO INPUT" Nothing
1523+ "What should I make though? I need specific files like:"
1524+ [ D.vcat
1525+ [ D.indent 4 $ D.green "elm make src/Main.elm"
1526+ , D.indent 4 $ D.green "elm make src/This.elm src/That.elm"
1527+ ]
1528+ , D.reflow $
1529+ "You can also entries to the \"exposed-modules\" list in your elm.json file, and\
1530+ \ I will try to compile the relevant files."
1531+ ]
15181532
15191533 MakeMultipleFilesIntoHtml ->
1520− error "TODO MakeMultipleFilesIntoHtml"
1534+ error "MakeMultipleFilesIntoHtml"
1535+
1536+ MakeNoMain ->
1537+ Help.docReport "NO MAIN" Nothing
1538+ (
1539+ "When producing an HTML file, I require that the given file has a `main` value.\
1540+ \ That way I have something to show on screen!"
1541+ )
1542+ [ D.reflow $
1543+ "Try adding a `main` value to your file? Or if you just want to verify that this\
1544+ \ module compiles, switch to --output=/dev/null to skip the code gen phase\
1545+ \ altogether."
1546+ , D.toSimpleNote $
1547+ "Adding a `main` value can be as brief as adding something like this:"
1548+ , D.vcat
1549+ [ D.fillSep [D.cyan "import","Html"]
1550+ , ""
1551+ , D.fillSep [D.green "main","="]
1552+ , D.indent 2 $ D.fillSep [D.cyan "Html" <> ".text",D.dullyellow "\"Hello!\""]
1553+ ]
1554+ , D.reflow $
1555+ "From there I can create an HTML file that says \"Hello!\" on screen. I recommend\
1556+ \ looking through https://guide.elm-lang.org for more guidance on how to fill in\
1557+ \ the `main` value."
1558+ ]
1559+
1560+ MakeNonMainFilesIntoJavaScript m ms ->
1561+ case ms of
1562+ [] ->
1563+ Help.report "NO MAIN" Nothing
1564+ (
1565+ "When producing a JS file, I require that the given file has a `main` value. That\
1566+ \ way Elm." ++ ModuleName.toChars m ++ ".init() is definitely defined in the\
1567+ \ resulting file!"
1568+ )
1569+ [ D.reflow $
1570+ "Try adding a `main` value to your file? Or if you just want to verify that this\
1571+ \ module compiles, switch to --output=/dev/null to skip the code gen phase\
1572+ \ altogether."
1573+ , D.toSimpleNote $
1574+ "Adding a `main` value can be as brief as adding something like this:"
1575+ , D.vcat
1576+ [ D.fillSep [D.cyan "import","Html"]
1577+ , ""
1578+ , D.fillSep [D.green "main","="]
1579+ , D.indent 2 $ D.fillSep [D.cyan "Html" <> ".text",D.dullyellow "\"Hello!\""]
1580+ ]
1581+ , D.reflow $
1582+ "Or use https://package.elm-lang.org/packages/elm/core/latest/Platform#worker to\
1583+ \ make a `main` with no user interface."
1584+ ]
15211585
1522− MakeNonMainFilesIntoJavaScript _ _ ->
1523− error "TODO MakeNonMainFilesIntoJavaScript"
1586+ _:_ ->
1587+ Help.report "NO MAIN" Nothing
1588+ (
1589+ "When producing a JS file, I require that given files all have `main` values.\
1590+ \ That way functions like Elm." ++ ModuleName.toChars m ++ ".init() are\
1591+ \ definitely defined in the resulting file. I am missing `main` values in:"
1592+ )
1593+ [ D.indent 4 $ D.red $ D.vcat $ map D.fromName (m:ms)
1594+ , D.reflow $
1595+ "Try adding a `main` value to them? Or if you just want to verify that these\
1596+ \ modules compile, switch to --output=/dev/null to skip the code gen phase\
1597+ \ altogether."
1598+ , D.toSimpleNote $
1599+ "Adding a `main` value can be as brief as adding something like this:"
1600+ , D.vcat
1601+ [ D.fillSep [D.cyan "import","Html"]
1602+ , ""
1603+ , D.fillSep [D.green "main","="]
1604+ , D.indent 2 $ D.fillSep [D.cyan "Html" <> ".text",D.dullyellow "\"Hello!\""]
1605+ ]
1606+ , D.reflow $
1607+ "Or use https://package.elm-lang.org/packages/elm/core/latest/Platform#worker to\
1608+ \ make a `main` with no user interface."
1609+ ]
15241610
15251611 MakeCannotBuild buildProblem ->
15261612 toBuildProblemReport buildProblem
terminal/src/Make.hs+6−10
@@ -102,13 +102,9 @@ run paths (Flags debug optimize maybeOutput report maybeDocs) =
102102 Task.throw (Exit.MakeNonMainFilesIntoJavaScript name names)
103103
104104 Just (Html target) ->
105− case hasOneMain artifacts of
106− Just name ->
107− do builder <- toBuilder root details desiredMode artifacts
108− generate style target (Html.sandwich name builder) (NE.List name [])
109−
110− Nothing ->
111− Task.throw Exit.MakeMultipleFilesIntoHtml
105+ do name <- hasOneMain artifacts
106+ builder <- toBuilder root details desiredMode artifacts
107+ generate style target (Html.sandwich name builder) (NE.List name [])
112108
113109
114110
@@ -199,11 +195,11 @@ isMain targetName modul =
199195-- HAS ONE MAIN
200196
201197
202−hasOneMain :: Build.Artifacts -> Maybe ModuleName.Raw
198+hasOneMain :: Build.Artifacts -> Task ModuleName.Raw
203199hasOneMain (Build.Artifacts _ _ mains modules) =
204200 case mains of
205− NE.List main [] -> getMain modules main
206− NE.List _ (_:_) -> Nothing
201+ NE.List main [] -> Task.mio Exit.MakeNoMain (return $ getMain modules main)
202+ NE.List _ (_:_) -> Task.throw Exit.MakeMultipleFilesIntoHtml
207203
208204
209205