1{-# LANGUAGE DeriveDataTypeable #-}
4import Data.Either (lefts, rights)
5import Data.List (intersect, intercalate,lookup)
6import Data.Maybe (fromMaybe)
7import Data.Version (showVersion)
8import System.Console.CmdArgs
11import Text.Blaze.Html.Renderer.String (renderHtml)
13import qualified Text.Jasmine as JS
14import qualified Data.ByteString.Lazy.Char8 as BS
17import Initialize (build,buildFromSource)
20import qualified Libraries as Libraries
26 , runtime :: Maybe FilePath
29 , import_js :: [FilePath]
33 , output_directory :: Maybe FilePath
35 deriving (Data,Typeable,Show,Eq)
37elm = ELM { make = False &= help "automatically compile dependencies."
38 , files = def &= args &= typ "FILES"
39 , runtime = Nothing &= typFile &=
40 help "Specify a custom location for Elm's runtime system."
41 , separate_js = False &= help "Compile to separate HTML and JS files."
42 , only_js = False &= help "Compile only to JavaScript."
43 , 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."
44 , no_prelude = False &= help "Do not import Prelude by default, used only when compiling standard libraries."
45 , noscript = True &= help "Add generated <noscript> tag to HTML output."
46 , minify = False &= help "Minify generated JavaScript"
47 , output_directory = Nothing &= typFile &= help "Output files to directory specified. Defaults to the location of original file."
49 help "Compile Elm programs to HTML, CSS, and JavaScript." &=
50 summary ("The Elm Compiler " ++ showVersion version ++ ", (c) Evan Czaplicki")
54 mini <- getDataFileName "elm-runtime.js"
57compileArgs mini flags =
59 [] -> putStrLn "Usage: elm [OPTIONS] [FILES]\nFor more help: elm --help"
60 fs -> mapM_ (fileTo flags what loc) fs
61 where loc = fromMaybe mini (runtime flags)
62 what | only_js flags = JS
63 | separate_js flags = Split
66data What = JS | HTML | Split
68fileTo flags what rtLoc file = do
69 let jsStyle = if minify flags then Minified else Readable
70 formatJS = if minify flags then BS.unpack . JS.minify . BS.pack else id
71 prelude = not (no_prelude flags)
72 ems <- if make flags then build prelude file
73 else do src <- readFile file
74 return (fmap (:[]) (buildFromSource prelude src))
75 jss <- concat `fmap` mapM readFile (import_js flags)
77 Left err -> do putStrLn $ "Error while compiling " ++ file ++ ":\n" ++ err
80 let path = fromMaybe "" (output_directory flags) </> file
81 js = replaceExtension path ".js"
82 html = replaceExtension path ".html"
83 ms = if no_prelude flags then ms' else map Libraries.addPrelude ms'
84 txt = jss ++ concatMap jsModule ms
86 JS -> writeFile js (formatJS txt)
87 HTML -> writeFile html . renderHtml $
88 modulesToHtml jsStyle "" rtLoc jss (noscript flags) ms
90 do writeFile html . renderHtml $ linkedHtml rtLoc js ms
91 writeFile js (formatJS txt)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list