on master help sign in
Start using the given output-directory
commit212d19c3e8b4dd924a688e0e305c119f74c25ca0 authorevancz <info@elm-lang.org> dateWed 5 Jun 2013, 14:22 (13 years ago) parentf5bdb2c
1 file changed+18−19
compiler/Compiler.hs+18−19
compiler/Compiler.hs+18−19
@@ -49,7 +49,7 @@ flags = Flags
4949 , no_prelude = False
5050 &= help "Do not import Prelude by default, used only when compiling standard libraries."
5151 , minify = False
52− &= help "Minify generated JavaScript"
52+ &= help "Minify generated JavaScript and HTML"
5353 , output_directory = "ElmFiles" &= typFile
5454 &= help "Output files to directory specified. Defaults to ElmFiles/ directory."
5555 } &= help "Compile Elm programs to HTML, CSS, and JavaScript."
@@ -60,11 +60,9 @@ main = compileArgs =<< cmdArgs flags
6060
6161compileArgs :: Flags -> IO ()
6262compileArgs 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
66− [] -> putStrLn "Usage: elm [OPTIONS] [FILES]\nFor more help: elm --help"
67− fs -> mapM_ builder fs
63+ case files flags of
64+ [] -> putStrLn "Usage: elm [OPTIONS] [FILES]\nFor more help: elm --help"
65+ fs -> mapM_ (build flags) fs
6866
6967
7068type Interface = String
@@ -76,7 +74,7 @@ buildFile flags moduleNum numModules filePath =
7674
7775 where
7876 file :: String -> FilePath
79− file ext = replaceExtension filePath ext
77+ file ext = output_directory flags </> replaceExtension filePath ext
8078
8179 interface :: FilePath
8280 interface = file "elmi"
@@ -99,14 +97,15 @@ buildFile flags moduleNum numModules filePath =
9997 compile = do
10098 putStrLn (number ++ " Compiling " ++ name)
10199 source <- readFile filePath
102− js <- if takeExtension filePath == ".js" then return source else
103− case buildFromSource (no_prelude flags) source of
104− Left err -> putStrLn err >> exitFailure
105− Right modul -> return (jsModule modul)
106− writeFile interface js
107− writeFile (file "elmo") js
108− when (only_js flags) (writeFile (file "js") js)
109− return js
100+ (inter,obj) <-
101+ if takeExtension filePath == ".js" then return ("",source) else
102+ case buildFromSource (no_prelude flags) source of
103+ Left err -> putStrLn err >> exitFailure
104+ Right modul -> return (show modul, jsModule modul)
105+ createDirectoryIfMissing True (output_directory flags)
106+ writeFile interface inter
107+ writeFile (file "elmo") obj
108+ return inter
110109
111110 getInterface :: IO Interface
112111 getInterface = do
@@ -120,16 +119,16 @@ getRuntime flags =
120119
121120build :: Flags -> FilePath -> IO ()
122121build flags rootFile = do
123− files <- getSortedModuleNames rootFile
122+ files <- if make flags then getSortedModuleNames rootFile else return [rootFile]
124123 buildFiles flags (length files) Map.empty files
125124 js <- foldM appendToOutput "" files
126125 case only_js flags of
127126 True -> do
128− putStr "\nGenerating JavaScript... "
127+ putStr "Generating JavaScript ... "
129128 writeFile (replaceExtension rootFile "js") (genJs js)
130129 putStrLn "Done"
131130 False -> do
132− putStr "\nGenerating HTML... "
131+ putStr "Generating HTML ... "
133132 runtime <- getRuntime flags
134133 let html = genHtml $ createHtml runtime rootFile (sources js) ""
135134 writeFile (replaceExtension rootFile "html") html
@@ -138,7 +137,7 @@ build flags rootFile = do
138137 where
139138 appendToOutput :: String -> FilePath -> IO String
140139 appendToOutput js filePath =
141− do src <- readFile (replaceExtension filePath "elmo")
140+ do src <- readFile (output_directory flags </> replaceExtension filePath "elmo")
142141 return (src ++ js)
143142
144143 genHtml = if minify flags then Normal.renderHtml else Pretty.renderHtml