on master help sign in
compiler has an option to specify output directory for html/js files
34a9671Piotr Adamski
elm/src/Compiler.hs+12−8
@@ -27,6 +27,7 @@ data ELM =
27 , import_js :: [FilePath]
27 , import_js :: [FilePath]
28 , generate_noscript :: Bool
28 , generate_noscript :: Bool
29 , minify :: Bool
29 , minify :: Bool
30+ , output_directory :: Maybe FilePath
30 }
31 }
31 deriving (Data,Typeable,Show,Eq)
32 deriving (Data,Typeable,Show,Eq)
32
33
@@ -39,6 +40,7 @@ elm = ELM { make = False &= help "automatically compile dependencies."
39 , 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."
40 , 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."
40 , generate_noscript = True &= help "Add generated <noscript> tag to HTML output."
41 , generate_noscript = True &= help "Add generated <noscript> tag to HTML output."
41 , minify = False &= help "Minify generated JavaScript"
42 , minify = False &= help "Minify generated JavaScript"
43+ , output_directory = Nothing &= typFile &= help "Output files to directory specified. Defaults to the location of original file."
42 } &=
44 } &=
43 help "Compile Elm programs to HTML, CSS, and JavaScript." &=
45 help "Compile Elm programs to HTML, CSS, and JavaScript." &=
44 summary ("The Elm Compiler " ++ showVersion version ++ ", (c) Evan Czaplicki")
46 summary ("The Elm Compiler " ++ showVersion version ++ ", (c) Evan Czaplicki")
@@ -48,17 +50,17 @@ main = do
48 mini <- getDataFileName ("elm-runtime-" ++ showVersion version ++ ".js")
50 mini <- getDataFileName ("elm-runtime-" ++ showVersion version ++ ".js")
49 compileArgs mini args
51 compileArgs mini args
50
52
51−compileArgs mini (ELM _ [] _ _ _ _ _ _) =
53+compileArgs mini (ELM _ [] _ _ _ _ _ _ _) =
52 putStrLn "Usage: elm [OPTIONS] [FILES]\nFor more help: elm --help"
54 putStrLn "Usage: elm [OPTIONS] [FILES]\nFor more help: elm --help"
53−compileArgs mini (ELM make files rtLoc split only js nscrpt isMini) =
55+compileArgs mini (ELM make files rtLoc split only js nscrpt isMini outputDir) =
54− mapM_ (fileTo isMini get what js nscrpt $ fromMaybe mini rtLoc) files
56+ mapM_ (fileTo isMini get what js nscrpt outputDir $ fromMaybe mini rtLoc) files
55 where get = if make then getModules [] else getModule
57 where get = if make then getModules [] else getModule
56 what = if only then JS else
58 what = if only then JS else
57 if split then Split else HTML
59 if split then Split else HTML
58
60
59data What = JS | HTML | Split
61data What = JS | HTML | Split
60
62
61−fileTo isMini get what jsFiles noscript rtLoc file = do
63+fileTo isMini get what jsFiles noscript outputDir rtLoc file = do
62 let jsStyle = if isMini then Minified else Readable
64 let jsStyle = if isMini then Minified else Readable
63 let formatJS = if isMini then BS.unpack . JS.minify . BS.pack else id
65 let formatJS = if isMini then BS.unpack . JS.minify . BS.pack else id
64 ems <- get file
66 ems <- get file
@@ -66,9 +68,11 @@ fileTo isMini get what jsFiles noscript rtLoc file = do
66 case ems of
68 case ems of
67 Left err -> putStrLn $ "Error while compiling " ++ file ++ ":\n" ++ err
69 Left err -> putStrLn $ "Error while compiling " ++ file ++ ":\n" ++ err
68 Right ms ->
70 Right ms ->
71+ let path = case outputDir of
69− let name = reverse . tail . dropWhile (/='.') $ reverse file
72+ Nothing -> reverse . tail . dropWhile (/='.') $ reverse file
73+ Just dir -> (\s -> dir ++ "/" ++ s) . reverse . takeWhile (/='/') . tail . dropWhile (/='.') $ reverse file
70− js = name ++ ".js"
74+ js = path ++ ".js"
71− html = name ++ ".html"
75+ html = path ++ ".html"
72 in case what of
76 in case what of
73 JS -> writeFile js . formatJS $ jss ++ concatMap jsModule ms
77 JS -> writeFile js . formatJS $ jss ++ concatMap jsModule ms
74 HTML -> writeFile html . renderHtml $ modulesToHtml jsStyle "" rtLoc jss noscript ms
78 HTML -> writeFile html . renderHtml $ modulesToHtml jsStyle "" rtLoc jss noscript ms
@@ -107,4 +111,4 @@ builtInModules =
107 , [ "Graphics", "Text", "Color" ]
111 , [ "Graphics", "Text", "Color" ]
108 , map ("JavaScript"++) [ "", "Experimental" ]
112 , map ("JavaScript"++) [ "", "Experimental" ]
109 , [ "Prelude", "JSON" ]
113 , [ "Prelude", "JSON" ]
110− ]
114+ ]