@@ -42,7 +42,8 @@ data Flags =
42 , scripts :: [FilePath]
42 , scripts :: [FilePath]
43 , no_prelude :: Bool
43 , no_prelude :: Bool
44 , minify :: Bool
44 , minify :: Bool
45− , output_directory :: FilePath
45+ , cache_dir :: FilePath
46+ , build_dir :: FilePath
47 deriving (Data,Typeable,Show,Eq)
48 deriving (Data,Typeable,Show,Eq)
@@ -64,8 +65,10 @@ flags = Flags
64 &= help "Do not import Prelude by default, used only when compiling standard libraries."
65 &= help "Do not import Prelude by default, used only when compiling standard libraries."
65 , minify = False
66 , minify = False
66 &= help "Minify generated JavaScript and HTML"
67 &= help "Minify generated JavaScript and HTML"
67− , output_directory = "ElmFiles" &= typFile
68+ , cache_dir = "cache" &= typFile
68− &= help "Output files to directory specified. Defaults to ElmFiles/ directory."
69+ &= help "Directory for files cached to make builds faster. Defaults to cache/ directory."
70+ , build_dir = "build" &= typFile
71+ &= help "Directory for generated HTML and JS files. Defaults to build/ directory."
69 } &= help "Compile Elm programs to HTML, CSS, and JavaScript."
72 } &= help "Compile Elm programs to HTML, CSS, and JavaScript."
70 &= summary ("The Elm Compiler " ++ showVersion version ++ ", (c) Evan Czaplicki")
73 &= summary ("The Elm Compiler " ++ showVersion version ++ ", (c) Evan Czaplicki")
@@ -80,14 +83,17 @@ compileArgs flags =
80 fs -> mapM_ (build flags) fs
83 fs -> mapM_ (build flags) fs
83−file :: Flags -> FilePath -> String -> FilePath
86+buildPath :: Flags -> FilePath -> String -> FilePath
87+buildPath flags filePath ext = build_dir flags </> replaceExtension filePath ext
89+cachePath :: Flags -> FilePath -> String -> FilePath
84−file flags filePath ext = output_directory flags </> replaceExtension filePath ext
90+cachePath flags filePath ext = cache_dir flags </> replaceExtension filePath ext
86elmo :: Flags -> FilePath -> FilePath
92elmo :: Flags -> FilePath -> FilePath
87−elmo flags filePath = file flags filePath "elmo"
93+elmo flags filePath = cachePath flags filePath "elmo"
89elmi :: Flags -> FilePath -> FilePath
95elmi :: Flags -> FilePath -> FilePath
90−elmi flags filePath = file flags filePath "elmi"
96+elmi flags filePath = cachePath flags filePath "elmi"
93buildFile :: Flags -> Int -> Int -> Interfaces -> FilePath -> IO ModuleInterface
99buildFile :: Flags -> Int -> Int -> Interfaces -> FilePath -> IO ModuleInterface
@@ -127,7 +133,8 @@ buildFile flags moduleNum numModules interfaces filePath =
127 , replicate (max 1 (20 - length name)) ' '
133 , replicate (max 1 (20 - length name)) ' '
128 , "( " ++ filePath ++ " )" ]
134 , "( " ++ filePath ++ " )" ]
129 source <- readFile filePath
135 source <- readFile filePath
130− createDirectoryIfMissing True (output_directory flags)
136+ createDirectoryIfMissing True (cache_dir flags)
137+ createDirectoryIfMissing True (build_dir flags)
131 metaModule <-
138 metaModule <-
132 case buildFromSource (no_prelude flags) interfaces source of
139 case buildFromSource (no_prelude flags) interfaces source of
133 Left errors -> do
140 Left errors -> do
@@ -176,13 +183,13 @@ build flags rootFile = do
176 case only_js flags of
183 case only_js flags of
177 True -> do
184 True -> do
178 putStr "Generating JavaScript ... "
185 putStr "Generating JavaScript ... "
179− writeFile (file flags rootFile "js") (genJs js)
186+ writeFile (buildPath flags rootFile "js") (genJs js)
180 putStrLn "Done"
187 putStrLn "Done"
181 False -> do
188 False -> do
182 putStr "Generating HTML ... "
189 putStr "Generating HTML ... "
183 runtime <- getRuntime flags
190 runtime <- getRuntime flags
184 let html = genHtml $ createHtml runtime (takeBaseName rootFile) (sources js) moduleName ""
191 let html = genHtml $ createHtml runtime (takeBaseName rootFile) (sources js) moduleName ""
185− writeFile (file flags rootFile "html") html
192+ writeFile (buildPath flags rootFile "html") html
186 putStrLn "Done"
193 putStrLn "Done"