@@ -49,7 +49,7 @@ flags = Flags
49 , no_prelude = False
49 , no_prelude = False
50 &= help "Do not import Prelude by default, used only when compiling standard libraries."
50 &= help "Do not import Prelude by default, used only when compiling standard libraries."
51 , minify = False
51 , minify = False
52− &= help "Minify generated JavaScript"
52+ &= help "Minify generated JavaScript and HTML"
53 , output_directory = "ElmFiles" &= typFile
53 , output_directory = "ElmFiles" &= typFile
54 &= help "Output files to directory specified. Defaults to ElmFiles/ directory."
54 &= help "Output files to directory specified. Defaults to ElmFiles/ directory."
55 } &= help "Compile Elm programs to HTML, CSS, and JavaScript."
55 } &= help "Compile Elm programs to HTML, CSS, and JavaScript."
@@ -60,11 +60,9 @@ main = compileArgs =<< cmdArgs flags
61compileArgs :: Flags -> IO ()
61compileArgs :: Flags -> IO ()
62compileArgs flags =
62compileArgs flags =
63− let builder file = if make flags then build flags file
64− else buildFile flags 1 1 file >> return ()
65− in case files flags of
63+ case files flags of
66− [] -> putStrLn "Usage: elm [OPTIONS] [FILES]\nFor more help: elm --help"
64+ [] -> putStrLn "Usage: elm [OPTIONS] [FILES]\nFor more help: elm --help"
67− fs -> mapM_ builder fs
65+ fs -> mapM_ (build flags) fs
70type Interface = String
68type Interface = String
@@ -76,7 +74,7 @@ buildFile flags moduleNum numModules filePath =
78 file :: String -> FilePath
76 file :: String -> FilePath
79− file ext = replaceExtension filePath ext
77+ file ext = output_directory flags </> replaceExtension filePath ext
81 interface :: FilePath
79 interface :: FilePath
82 interface = file "elmi"
80 interface = file "elmi"
@@ -99,14 +97,15 @@ buildFile flags moduleNum numModules filePath =
99 compile = do
97 compile = do
100 putStrLn (number ++ " Compiling " ++ name)
98 putStrLn (number ++ " Compiling " ++ name)
101 source <- readFile filePath
99 source <- readFile filePath
102− js <- if takeExtension filePath == ".js" then return source else
101+ if takeExtension filePath == ".js" then return ("",source) else
103− case buildFromSource (no_prelude flags) source of
102+ case buildFromSource (no_prelude flags) source of
104− Left err -> putStrLn err >> exitFailure
103+ Left err -> putStrLn err >> exitFailure
105− Right modul -> return (jsModule modul)
104+ Right modul -> return (show modul, jsModule modul)
105+ createDirectoryIfMissing True (output_directory flags)
106− writeFile interface js
106+ writeFile interface inter
107− writeFile (file "elmo") js
107+ writeFile (file "elmo") obj
108− when (only_js flags) (writeFile (file "js") js)
109− return js
108+ return inter
111 getInterface :: IO Interface
110 getInterface :: IO Interface
112 getInterface = do
111 getInterface = do
@@ -120,16 +119,16 @@ getRuntime flags =
121build :: Flags -> FilePath -> IO ()
120build :: Flags -> FilePath -> IO ()
122build flags rootFile = do
121build flags rootFile = do
123− files <- getSortedModuleNames rootFile
122+ files <- if make flags then getSortedModuleNames rootFile else return [rootFile]
124 buildFiles flags (length files) Map.empty files
123 buildFiles flags (length files) Map.empty files
125 js <- foldM appendToOutput "" files
124 js <- foldM appendToOutput "" files
126 case only_js flags of
125 case only_js flags of
127 True -> do
126 True -> do
128− putStr "\nGenerating JavaScript... "
127+ putStr "Generating JavaScript ... "
129 writeFile (replaceExtension rootFile "js") (genJs js)
128 writeFile (replaceExtension rootFile "js") (genJs js)
130 putStrLn "Done"
129 putStrLn "Done"
131 False -> do
130 False -> do
132− putStr "\nGenerating HTML... "
131+ putStr "Generating HTML ... "
133 runtime <- getRuntime flags
132 runtime <- getRuntime flags
134 let html = genHtml $ createHtml runtime rootFile (sources js) ""
133 let html = genHtml $ createHtml runtime rootFile (sources js) ""
135 writeFile (replaceExtension rootFile "html") html
134 writeFile (replaceExtension rootFile "html") html
@@ -138,7 +137,7 @@ build flags rootFile = do
139 appendToOutput :: String -> FilePath -> IO String
138 appendToOutput :: String -> FilePath -> IO String
140 appendToOutput js filePath =
139 appendToOutput js filePath =
141− do src <- readFile (replaceExtension filePath "elmo")
140+ do src <- readFile (output_directory flags </> replaceExtension filePath "elmo")
142 return (src ++ js)
141 return (src ++ js)
144 genHtml = if minify flags then Normal.renderHtml else Pretty.renderHtml
143 genHtml = if minify flags then Normal.renderHtml else Pretty.renderHtml