@@ -7,6 +7,9 @@ import Data.Maybe (fromMaybe)
7import System.Console.CmdArgs
7import System.Console.CmdArgs
8import Text.Blaze.Html.Renderer.String (renderHtml)
8import Text.Blaze.Html.Renderer.String (renderHtml)
10+import qualified Text.Jasmine as JS
11+import qualified Data.ByteString.Lazy.Char8 as BS
11import Initialize
14import Initialize
12import CompileToJS
15import CompileToJS
@@ -22,6 +25,7 @@ data ELM =
22 , only_js :: Bool
25 , only_js :: Bool
23 , import_js :: [FilePath]
26 , import_js :: [FilePath]
24 , generate_noscript :: Bool
27 , generate_noscript :: Bool
26 deriving (Data,Typeable,Show,Eq)
30 deriving (Data,Typeable,Show,Eq)
@@ -33,26 +37,29 @@ elm = ELM { make = False &= help "automatically compile dependencies."
33 , only_js = False &= help "Compile only to JavaScript."
37 , only_js = False &= help "Compile only to JavaScript."
34 , 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."
38 , 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."
35 , generate_noscript = True &= help "Add generated <noscript> tag to HTML output."
39 , generate_noscript = True &= help "Add generated <noscript> tag to HTML output."
40+ , minify = False &= help "Minify generated JavaScript"
37 help "Compile Elm programs to HTML, CSS, and JavaScript." &=
42 help "Compile Elm programs to HTML, CSS, and JavaScript." &=
38− summary "The Elm Compiler v0.3.6.2, (c) Evan Czaplicki"
43+ summary "The Elm Compiler v0.4.0, (c) Evan Czaplicki"
41 args <- cmdArgs elm
46 args <- cmdArgs elm
42− mini <- getDataFileName "elm-runtime-0.3.6.2.js"
47+ mini <- getDataFileName "elm-runtime-0.4.0.js"
43 compileArgs mini args
48 compileArgs mini args
45−compileArgs mini (ELM _ [] _ _ _ _ _) =
50+compileArgs mini (ELM _ [] _ _ _ _ _ _) =
46 putStrLn "Usage: elm [OPTIONS] [FILES]\nFor more help: elm --help"
51 putStrLn "Usage: elm [OPTIONS] [FILES]\nFor more help: elm --help"
47−compileArgs mini (ELM make files rtLoc split only js nscrpt) =
52+compileArgs mini (ELM make files rtLoc split only js nscrpt isMini) =
48− mapM_ (fileTo get what js nscrpt $ fromMaybe mini rtLoc) files
53+ mapM_ (fileTo isMini get what js nscrpt $ fromMaybe mini rtLoc) files
49 where get = if make then getModules [] else getModule
54 where get = if make then getModules [] else getModule
50 what = if only then JS else
55 what = if only then JS else
51 if split then Split else HTML
56 if split then Split else HTML
53data What = JS | HTML | Split
58data What = JS | HTML | Split
55−fileTo get what jsFiles noscript rtLoc file = do
60+fileTo isMini get what jsFiles noscript rtLoc file = do
61+ let jsStyle = if isMini then Minified else Readable
62+ let formatJS = if isMini then BS.unpack . JS.minify . BS.pack else id
56 ems <- get file
63 ems <- get file
57 jss <- concat `fmap` mapM readFile jsFiles
64 jss <- concat `fmap` mapM readFile jsFiles
58 case ems of
65 case ems of
@@ -62,11 +69,11 @@ fileTo get what jsFiles noscript rtLoc file = do
62 js = name ++ ".js"
69 js = name ++ ".js"
63 html = name ++ ".html"
70 html = name ++ ".html"
64 in case what of
71 in case what of
65− JS -> writeFile js $ jss ++ concatMap jsModule ms
72+ JS -> writeFile js . formatJS $ jss ++ concatMap jsModule ms
66− HTML -> writeFile html . renderHtml $ modulesToHtml "" rtLoc jss noscript ms
73+ HTML -> writeFile html . renderHtml $ modulesToHtml jsStyle "" rtLoc jss noscript ms
67 Split -> do
74 Split -> do
68 writeFile html . renderHtml $ linkedHtml rtLoc js ms
75 writeFile html . renderHtml $ linkedHtml rtLoc js ms
69− writeFile js $ jss ++ concatMap jsModule ms
76+ writeFile js . formatJS $ jss ++ concatMap jsModule ms
71getModules :: [String] -> FilePath -> IO (Either String [([String],Module)])
78getModules :: [String] -> FilePath -> IO (Either String [([String],Module)])
72getModules uses file = do
79getModules uses file = do