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
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 ems <- if make flags then build file
72 else do src <- readFile file
73 return (fmap (:[]) (buildFromSource src))
74 jss <- concat `fmap` mapM readFile (import_js flags)
76 Left err -> do putStrLn $ "Error while compiling " ++ file ++ ":\n" ++ err
79 let path = fromMaybe "" (output_directory flags) </> file
80 js = replaceExtension path ".js"
81 html = replaceExtension path ".html"
82 ms = if no_prelude flags then ms' else map Libraries.addPrelude ms'
83 txt = jss ++ concatMap jsModule ms
85 JS -> writeFile js (formatJS txt)
86 HTML -> writeFile html . renderHtml $
87 modulesToHtml jsStyle "" rtLoc jss (noscript flags) ms
89 do writeFile html . renderHtml $ linkedHtml rtLoc js ms
90 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