@@ -26,7 +26,8 @@ data ELM =
26 , separate_js :: Bool
26 , separate_js :: Bool
27 , only_js :: Bool
27 , only_js :: Bool
28 , import_js :: [FilePath]
28 , import_js :: [FilePath]
29− , generate_noscript :: Bool
29+ , no_prelude :: Bool
30 , minify :: Bool
31 , minify :: Bool
31 , output_directory :: Maybe FilePath
32 , output_directory :: Maybe FilePath
@@ -39,7 +40,8 @@ elm = ELM { make = False &= help "automatically compile dependencies."
39 , separate_js = False &= help "Compile to separate HTML and JS files."
40 , separate_js = False &= help "Compile to separate HTML and JS files."
40 , only_js = False &= help "Compile only to JavaScript."
41 , only_js = False &= help "Compile only to JavaScript."
41 , 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."
42 , 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."
43+ , no_prelude = False &= help "Do not import Prelude by default, used only when compiling standard libraries."
42− , generate_noscript = True &= help "Add generated <noscript> tag to HTML output."
44+ , noscript = True &= help "Add generated <noscript> tag to HTML output."
43 , minify = False &= help "Minify generated JavaScript"
45 , minify = False &= help "Minify generated JavaScript"
44 , output_directory = Nothing &= typFile &= help "Output files to directory specified. Defaults to the location of original file."
46 , output_directory = Nothing &= typFile &= help "Output files to directory specified. Defaults to the location of original file."
@@ -51,35 +53,39 @@ main = do
51 mini <- getDataFileName "elm-runtime.js"
53 mini <- getDataFileName "elm-runtime.js"
52 compileArgs mini args
54 compileArgs mini args
54−compileArgs mini (ELM _ [] _ _ _ _ _ _ _) =
56+compileArgs mini flags =
55− putStrLn "Usage: elm [OPTIONS] [FILES]\nFor more help: elm --help"
58+ [] -> putStrLn "Usage: elm [OPTIONS] [FILES]\nFor more help: elm --help"
56−compileArgs mini (ELM make files rtLoc split only js nscrpt isMini outputDir) =
57− mapM_ (fileTo isMini make what js nscrpt outputDir loc) files
59+ fs -> mapM_ (fileTo flags what loc) fs
58− where loc = fromMaybe mini rtLoc
60+ where loc = fromMaybe mini (runtime flags)
59− what | only = JS
61+ what | only_js flags = JS
60− | split = Split
62+ | separate_js flags = Split
61− | otherwise = HTML
63+ | otherwise = HTML
63data What = JS | HTML | Split
65data What = JS | HTML | Split
65−fileTo isMini make what jsFiles noscript outputDir rtLoc file = do
67+fileTo flags what rtLoc file = do
66− let jsStyle = if isMini then Minified else Readable
68+ let jsStyle = if minify flags then Minified else Readable
67− formatJS = if isMini then BS.unpack . JS.minify . BS.pack else id
69+ formatJS = if minify flags then BS.unpack . JS.minify . BS.pack else id
70+ ems <- if make flags then build file
68− ems <- if make then build file else do src <- readFile file
71+ else do src <- readFile file
69− return (fmap (:[]) (buildFromSource src))
72+ return (fmap (:[]) (buildFromSource src))
70− jss <- concat `fmap` mapM readFile jsFiles
73+ jss <- concat `fmap` mapM readFile (import_js flags)
71 case ems of
74 case ems of
72 Left err -> do putStrLn $ "Error while compiling " ++ file ++ ":\n" ++ err
75 Left err -> do putStrLn $ "Error while compiling " ++ file ++ ":\n" ++ err
73 exitFailure
76 exitFailure
74− Right ms ->
77+ Right ms' ->
75− let path = fromMaybe "" outputDir </> file
78+ let path = fromMaybe "" (output_directory flags) </> file
76 js = replaceExtension path ".js"
79 js = replaceExtension path ".js"
77 html = replaceExtension path ".html"
80 html = replaceExtension path ".html"
81+ addPrelude (Module name exs ims stmts) =
82+ Module name exs (("Prelude", Importing []) : ims) stmts
83+ ms = if no_prelude flags then ms' else map addPrelude ms'
78 txt = jss ++ concatMap jsModule ms
84 txt = jss ++ concatMap jsModule ms
79 in case what of
85 in case what of
80 JS -> writeFile js (formatJS txt)
86 JS -> writeFile js (formatJS txt)
81 HTML -> writeFile html . renderHtml $
87 HTML -> writeFile html . renderHtml $
82− modulesToHtml jsStyle "" rtLoc jss noscript ms
88+ modulesToHtml jsStyle "" rtLoc jss (noscript flags) ms
84 do writeFile html . renderHtml $ linkedHtml rtLoc js ms
90 do writeFile html . renderHtml $ linkedHtml rtLoc js ms
85 writeFile js (formatJS txt)
91 writeFile js (formatJS txt)