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]
29 , generate_noscript :: Bool
31 , output_directory :: Maybe FilePath
33 deriving (Data,Typeable,Show,Eq)
35elm = ELM { make = False &= help "automatically compile dependencies."
36 , files = def &= args &= typ "FILES"
37 , runtime = Nothing &= typFile &=
38 help "Specify a custom location for Elm's runtime system."
39 , separate_js = False &= help "Compile to separate HTML and JS files."
40 , 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 , generate_noscript = True &= help "Add generated <noscript> tag to HTML output."
43 , 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 help "Compile Elm programs to HTML, CSS, and JavaScript." &=
47 summary ("The Elm Compiler " ++ showVersion version ++ ", (c) Evan Czaplicki")
51 mini <- getDataFileName "elm-runtime.js"
54compileArgs mini (ELM _ [] _ _ _ _ _ _ _) =
55 putStrLn "Usage: elm [OPTIONS] [FILES]\nFor more help: elm --help"
56compileArgs mini (ELM make files rtLoc split only js nscrpt isMini outputDir) =
57 mapM_ (fileTo isMini make what js nscrpt outputDir loc) files
58 where loc = fromMaybe mini rtLoc
63data What = JS | HTML | Split
65fileTo isMini make what jsFiles noscript outputDir rtLoc file = do
66 let jsStyle = if isMini then Minified else Readable
67 formatJS = if isMini then BS.unpack . JS.minify . BS.pack else id
68 ems <- if make then build file else do src <- readFile file
69 return (fmap (:[]) (buildFromSource src))
70 jss <- concat `fmap` mapM readFile jsFiles
72 Left err -> do putStrLn $ "Error while compiling " ++ file ++ ":\n" ++ err
75 let path = fromMaybe "" outputDir </> file
76 js = replaceExtension path ".js"
77 html = replaceExtension path ".html"
78 txt = jss ++ concatMap jsModule ms
80 JS -> writeFile js (formatJS txt)
81 HTML -> writeFile html . renderHtml $
82 modulesToHtml jsStyle "" rtLoc jss noscript ms
84 do writeFile html . renderHtml $ linkedHtml rtLoc js ms
85 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