on master help sign in
Allow generation when listed application files have no main

This way you can call `elm make` on whatever you want, but you only get output if there is a file with `main` in the arguments.

commitd42572a71410f56c8996fafcc2ed6947a166de32 authorEvan Czaplicki <evancz@users.noreply.github.com> dateThu 29 Mar 2018, 20:07 (9 years ago) parentd4e9599
2 files changed+28−25
builder/src/Generate/Output.hs+23−18 compiler/src/Generate/JavaScript.hs+5−7
builder/src/Generate/Output.hs+23−18
@@ -63,25 +63,30 @@ generate options summary graph@(Crawl.Graph args _ _ _ _) =
6363
6464generateMonolith :: Options -> Summary.Summary -> Crawl.Result -> [Module.Raw] -> Task.Task ()
6565generateMonolith (Options debug target output_) summary@(Summary.Summary _ project _ ifaces _) graph names =
66− do
67− objectGraph <- organize summary graph
68− let pkg = Project.getName project
66+ do let pkg = Project.getName project
6967 let roots = map (Module.Canonical pkg) names
70− let (Right builder) = Obj.generate debug target ifaces objectGraph roots
71− let monolith =
72− "(function(scope){\n'use strict';" <> Functions.functions <> builder <> "}(this));"
73−
74− liftIO $
75− case output_ of
76− Nothing ->
77− IO.writeBuilder "elm.js" monolith
78−
79− Just None ->
80− return ()
81−
82− Just (Custom maybeDir fileName) ->
83− do path <- safeCustomPath maybeDir fileName
84− IO.writeBuilder path monolith
68+ objectGraph <- organize summary graph
69+ case Obj.generate debug target ifaces objectGraph roots of
70+ Nothing ->
71+ return ()
72+
73+ Just builder ->
74+ let
75+ monolith =
76+ "(function(scope){\n'use strict';"
77+ <> Functions.functions <> builder <> "}(this));"
78+ in
79+ liftIO $
80+ case output_ of
81+ Nothing ->
82+ IO.writeBuilder "elm.js" monolith
83+
84+ Just None ->
85+ return ()
86+
87+ Just (Custom maybeDir fileName) ->
88+ do path <- safeCustomPath maybeDir fileName
89+ IO.writeBuilder path monolith
8590
8691
8792
compiler/src/Generate/JavaScript.hs+5−7
@@ -39,22 +39,20 @@ import qualified Reporting.Helpers as H
3939data Mode = Debug | Prod
4040
4141
42−generate :: Mode -> Name.Target -> I.Interfaces -> Opt.Graph -> [ModuleName.Canonical] -> Either [ModuleName.Canonical] B.Builder
42+generate :: Mode -> Name.Target -> I.Interfaces -> Opt.Graph -> [ModuleName.Canonical] -> Maybe B.Builder
4343generate mode target interfaces (Opt.Graph mains graph fields) roots =
4444 let
4545 rootSet = Set.fromList roots
4646 rootMap = Map.restrictKeys mains rootSet
4747 in
48− if Map.size rootMap == Set.size rootSet then
48+ if Map.null rootMap then
49+ Nothing
50+ else
4951 let
5052 realMode = toRealMode mode target fields
5153 state = Map.foldrWithKey (addMain realMode graph) emptyState rootMap
5254 in
53− Right $ stateToBuilder state <> toMainExports realMode interfaces rootMap
54−
55− else
56− Left $ Set.toList $
57− Set.intersection rootSet (Map.keysSet mains)
55+ Just $ stateToBuilder state <> toMainExports realMode interfaces rootMap
5856
5957
6058addMain :: Name.Mode -> Graph -> ModuleName.Canonical -> main -> State -> State