1{-# LANGUAGE DeriveDataTypeable #-}
4import Data.Either (lefts, rights)
5import Data.List (intersect, intercalate)
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
25 , runtime :: Maybe FilePath
28 , import_js :: [FilePath]
32 , output_directory :: Maybe FilePath
34 deriving (Data,Typeable,Show,Eq)
36elm = ELM { make = False &= help "automatically compile dependencies."
37 , files = def &= args &= typ "FILES"
38 , runtime = Nothing &= typFile &=
39 help "Specify a custom location for Elm's runtime system."
40 , separate_js = False &= help "Compile to separate HTML and JS files."
41 , only_js = False &= help "Compile only to JavaScript."
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."
44 , noscript = True &= help "Add generated <noscript> tag to HTML output."
45 , minify = False &= help "Minify generated JavaScript"
46 , output_directory = Nothing &= typFile &= help "Output files to directory specified. Defaults to the location of original file."
48 help "Compile Elm programs to HTML, CSS, and JavaScript." &=
49 summary ("The Elm Compiler " ++ showVersion version ++ ", (c) Evan Czaplicki")
53 mini <- getDataFileName "elm-runtime.js"
56compileArgs mini flags =
58 [] -> putStrLn "Usage: elm [OPTIONS] [FILES]\nFor more help: elm --help"
59 fs -> mapM_ (fileTo flags what loc) fs
60 where loc = fromMaybe mini (runtime flags)
61 what | only_js flags = JS
62 | separate_js flags = Split
65data What = JS | HTML | Split
67fileTo flags what rtLoc file = do
68 let jsStyle = if minify flags then Minified else Readable
69 formatJS = if minify flags then BS.unpack . JS.minify . BS.pack else id
70 ems <- if make flags then build file
71 else do src <- readFile file
72 return (fmap (:[]) (buildFromSource src))
73 jss <- concat `fmap` mapM readFile (import_js flags)
75 Left err -> do putStrLn $ "Error while compiling " ++ file ++ ":\n" ++ err
78 let path = fromMaybe "" (output_directory flags) </> file
79 js = replaceExtension path ".js"
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'
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