@@ -27,6 +27,7 @@ data ELM =
2727 , import_js :: [FilePath]
2828 , generate_noscript :: Bool
2929 , minify :: Bool
30+ , output_directory :: Maybe FilePath
3031 }
3132 deriving (Data,Typeable,Show,Eq)
3233
@@ -39,6 +40,7 @@ elm = ELM { make = False &= help "automatically compile dependencies."
3940 , import_js = [] &= typFile &= help "Include a JavaScript file before the body of the Elm program. Can be used many times. Files will be included in the given order."
4041 , generate_noscript = True &= help "Add generated <noscript> tag to HTML output."
4142 , minify = False &= help "Minify generated JavaScript"
43+ , output_directory = Nothing &= typFile &= help "Output files to directory specified. Defaults to the location of original file."
4244 } &=
4345 help "Compile Elm programs to HTML, CSS, and JavaScript." &=
4446 summary ("The Elm Compiler " ++ showVersion version ++ ", (c) Evan Czaplicki")
@@ -48,17 +50,17 @@ main = do
4850 mini <- getDataFileName ("elm-runtime-" ++ showVersion version ++ ".js")
4951 compileArgs mini args
5052
51−compileArgs mini (ELM _ [] _ _ _ _ _ _) =
53+compileArgs mini (ELM _ [] _ _ _ _ _ _ _) =
5254 putStrLn "Usage: elm [OPTIONS] [FILES]\nFor more help: elm --help"
53−compileArgs mini (ELM make files rtLoc split only js nscrpt isMini) =
54− mapM_ (fileTo isMini get what js nscrpt $ fromMaybe mini rtLoc) files
55+compileArgs mini (ELM make files rtLoc split only js nscrpt isMini outputDir) =
56+ mapM_ (fileTo isMini get what js nscrpt outputDir $ fromMaybe mini rtLoc) files
5557 where get = if make then getModules [] else getModule
5658 what = if only then JS else
5759 if split then Split else HTML
5860
5961data What = JS | HTML | Split
6062
61−fileTo isMini get what jsFiles noscript rtLoc file = do
63+fileTo isMini get what jsFiles noscript outputDir rtLoc file = do
6264 let jsStyle = if isMini then Minified else Readable
6365 let formatJS = if isMini then BS.unpack . JS.minify . BS.pack else id
6466 ems <- get file
@@ -66,9 +68,11 @@ fileTo isMini get what jsFiles noscript rtLoc file = do
6668 case ems of
6769 Left err -> putStrLn $ "Error while compiling " ++ file ++ ":\n" ++ err
6870 Right ms ->
69− let name = reverse . tail . dropWhile (/='.') $ reverse file
70− js = name ++ ".js"
71− html = name ++ ".html"
71+ let path = case outputDir of
72+ Nothing -> reverse . tail . dropWhile (/='.') $ reverse file
73+ Just dir -> (\s -> dir ++ "/" ++ s) . reverse . takeWhile (/='/') . tail . dropWhile (/='.') $ reverse file
74+ js = path ++ ".js"
75+ html = path ++ ".html"
7276 in case what of
7377 JS -> writeFile js . formatJS $ jss ++ concatMap jsModule ms
7478 HTML -> writeFile html . renderHtml $ modulesToHtml jsStyle "" rtLoc jss noscript ms
@@ -107,4 +111,4 @@ builtInModules =
107111 , [ "Graphics", "Text", "Color" ]
108112 , map ("JavaScript"++) [ "", "Experimental" ]
109113 , [ "Prelude", "JSON" ]
110− ]
114+ ]