@@ -31,6 +31,7 @@ import qualified File.Args as Args
31import qualified File.Crawl as Crawl
31import qualified File.Crawl as Crawl
32import qualified File.IO as IO
32import qualified File.IO as IO
33import qualified Generate.Functions as Functions
33import qualified Generate.Functions as Functions
34+import qualified Generate.Html as Html
34import qualified Reporting.Task as Task
35import qualified Reporting.Task as Task
35import qualified Stuff.Paths as Paths
36import qualified Stuff.Paths as Paths
36import Terminal.Args (Parser(..), suggestFiles)
37import Terminal.Args (Parser(..), suggestFiles)
@@ -63,31 +64,40 @@ generate options summary graph@(Crawl.Graph args _ _ _ _) =
65generateMonolith :: Options -> Summary.Summary -> Crawl.Result -> [Module.Raw] -> Task.Task ()
66generateMonolith :: 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 =
67 do let pkg = Project.getName project
68 do let pkg = Project.getName project
68− let roots = map (Module.Canonical pkg) names
69+ let roots = map (Module.Canonical pkg) rootNames
69 objectGraph <- organize summary graph
70 objectGraph <- organize summary graph
70 case Obj.generate debug target ifaces objectGraph roots of
71 case Obj.generate debug target ifaces objectGraph roots of
71− Nothing ->
72+ Obj.None ->
74− Just builder ->
75+ Obj.Some name names builder ->
76 monolith =
77 monolith =
77 "(function(scope){\n'use strict';"
78 "(function(scope){\n'use strict';"
78 <> Functions.functions <> builder <> "}(this));"
79 <> Functions.functions <> builder <> "}(this));"
81− case output_ of
82+ case maybeOutput of
82− Nothing ->
83+ Nothing ->
83− IO.writeBuilder "elm.js" monolith
84+ IO.writeBuilder "elm.js" monolith
85− Just None ->
86+ Just None ->
86− return ()
87+ return ()
89+ Just (JavaScript maybeDir fileName) ->
90+ do path <- toWritablePath maybeDir fileName
91+ IO.writeBuilder path monolith
88− Just (Custom maybeDir fileName) ->
93+ Just (Html maybeDir fileName) ->
89− do path <- safeCustomPath maybeDir fileName
96+ do path <- toWritablePath maybeDir fileName
90− IO.writeBuilder path monolith
97+ IO.writeBuilder path (Html.sandwich name monolith)
@@ -141,12 +151,13 @@ loadPackageObj ( name, (version,_) ) =
142data Output
152data Output
154+ | Html (Maybe FilePath) FilePath
144− | Custom (Maybe FilePath) FilePath
155+ | JavaScript (Maybe FilePath) FilePath
147−safeCustomPath :: Maybe FilePath -> FilePath -> IO FilePath
158+toWritablePath :: Maybe FilePath -> FilePath -> IO FilePath
148−safeCustomPath maybeDirectory fileName =
159+toWritablePath maybeDir fileName =
149− case maybeDirectory of
160+ case maybeDir of
150 Nothing ->
161 Nothing ->
151 do return fileName
162 do return fileName
@@ -175,24 +186,27 @@ parseOutput string =
175 if string == "/dev/null" || string == "NUL" || string == "$null" then
186 if string == "/dev/null" || string == "NUL" || string == "$null" then
176 Just None
187 Just None
178− else if FP.takeExtension string == ".js" then
189+ else if FP.takeExtension string == ".html" && length string > 5 then
179− toCustom string
190+ splitOutput Html string
192+ else if FP.takeExtension string == ".js" && length string > 3 then
193+ splitOutput JavaScript string
185−toCustom :: String -> Maybe Output
199+splitOutput :: (Maybe FilePath -> FilePath -> Output) -> String -> Maybe Output
186−toCustom string =
200+splitOutput toOutput string =
187 case FP.splitPath string of
201 case FP.splitPath string of
191 [name] ->
205 [name] ->
192− Just $ Custom Nothing name
206+ Just $ toOutput Nothing name
194 segments ->
208 segments ->
195− Just $ Custom (Just (FP.joinPath (init segments))) (last segments)
209+ Just $ toOutput (Just (FP.joinPath (init segments))) (last segments)
198exampleOutput :: String -> IO [String]
212exampleOutput :: String -> IO [String]