@@ -31,6 +31,7 @@ import qualified File.Args as Args
3131import qualified File.Crawl as Crawl
3232import qualified File.IO as IO
3333import qualified Generate.Functions as Functions
34+import qualified Generate.Html as Html
3435import qualified Reporting.Task as Task
3536import qualified Stuff.Paths as Paths
3637import Terminal.Args (Parser(..), suggestFiles)
@@ -63,31 +64,40 @@ generate options summary graph@(Crawl.Graph args _ _ _ _) =
6364
6465
6566generateMonolith :: Options -> Summary.Summary -> Crawl.Result -> [Module.Raw] -> Task.Task ()
66−generateMonolith (Options debug target output_) summary@(Summary.Summary _ project _ ifaces _) graph names =
67+generateMonolith (Options debug target maybeOutput) summary@(Summary.Summary _ project _ ifaces _) graph rootNames =
6768 do let pkg = Project.getName project
68− let roots = map (Module.Canonical pkg) names
69+ let roots = map (Module.Canonical pkg) rootNames
6970 objectGraph <- organize summary graph
7071 case Obj.generate debug target ifaces objectGraph roots of
71− Nothing ->
72+ Obj.None ->
7273 return ()
7374
74− Just builder ->
75+ Obj.Some name names builder ->
7576 let
7677 monolith =
7778 "(function(scope){\n'use strict';"
7879 <> Functions.functions <> builder <> "}(this));"
7980 in
8081 liftIO $
81− case output_ of
82− Nothing ->
83− IO.writeBuilder "elm.js" monolith
82+ case maybeOutput of
83+ Nothing ->
84+ IO.writeBuilder "elm.js" monolith
8485
85− Just None ->
86− return ()
86+ Just None ->
87+ return ()
8788
88− Just (Custom maybeDir fileName) ->
89− do path <- safeCustomPath maybeDir fileName
90− IO.writeBuilder path monolith
89+ Just (JavaScript maybeDir fileName) ->
90+ do path <- toWritablePath maybeDir fileName
91+ IO.writeBuilder path monolith
92+
93+ Just (Html maybeDir fileName) ->
94+ case names of
95+ [] ->
96+ do path <- toWritablePath maybeDir fileName
97+ IO.writeBuilder path (Html.sandwich name monolith)
98+
99+ _:_ ->
100+ return ()
91101
92102
93103
@@ -141,12 +151,13 @@ loadPackageObj ( name, (version,_) ) =
141151
142152data Output
143153 = None
144− | Custom (Maybe FilePath) FilePath
154+ | Html (Maybe FilePath) FilePath
155+ | JavaScript (Maybe FilePath) FilePath
145156
146157
147−safeCustomPath :: Maybe FilePath -> FilePath -> IO FilePath
148−safeCustomPath maybeDirectory fileName =
149− case maybeDirectory of
158+toWritablePath :: Maybe FilePath -> FilePath -> IO FilePath
159+toWritablePath maybeDir fileName =
160+ case maybeDir of
150161 Nothing ->
151162 do return fileName
152163
@@ -175,24 +186,27 @@ parseOutput string =
175186 if string == "/dev/null" || string == "NUL" || string == "$null" then
176187 Just None
177188
178− else if FP.takeExtension string == ".js" then
179− toCustom string
189+ else if FP.takeExtension string == ".html" && length string > 5 then
190+ splitOutput Html string
191+
192+ else if FP.takeExtension string == ".js" && length string > 3 then
193+ splitOutput JavaScript string
180194
181195 else
182196 Nothing
183197
184198
185−toCustom :: String -> Maybe Output
186−toCustom string =
199+splitOutput :: (Maybe FilePath -> FilePath -> Output) -> String -> Maybe Output
200+splitOutput toOutput string =
187201 case FP.splitPath string of
188202 [] ->
189203 Nothing
190204
191205 [name] ->
192− Just $ Custom Nothing name
206+ Just $ toOutput Nothing name
193207
194208 segments ->
195− Just $ Custom (Just (FP.joinPath (init segments))) (last segments)
209+ Just $ toOutput (Just (FP.joinPath (init segments))) (last segments)
196210
197211
198212exampleOutput :: String -> IO [String]