4import Control.Monad (foldM, when)
5import qualified Data.Maybe as Maybe
6import Text.Blaze.Html.Renderer.String (renderHtml)
7import qualified Data.ByteString.Lazy.Char8 as BS
8import qualified System.Console.CmdArgs as CmdArgs
10import System.Exit (exitSuccess)
14import Build.Dependencies (getBuildRecipe, Recipe(..))
15import qualified Generate.Html as Html
16import qualified Metadata.Prelude as Prelude
17import qualified Build.Utils as Utils
18import qualified Build.Flags as Flag
19import qualified Build.File as File
20import qualified Elm.Internal.Paths as Path
23main = do setNumCapabilities =<< getNumProcessors
24 compileArgs =<< CmdArgs.cmdArgs Flag.flags
26compileArgs :: Flag.Flags -> IO ()
28 do when (Flag.get_runtime flags) $ do
31 case Flag.files flags of
32 [] -> putStrLn "Usage: elm [OPTIONS] [FILES]\nFor more help: elm --help"
33 fs -> mapM_ (build flags) fs
35build :: Flag.Flags -> FilePath -> IO ()
37 do let noPrelude = Flag.no_prelude flags
38 builtIns <- Prelude.interfaces noPrelude
40 (Recipe elmFiles jsFiles) <-
42 then Utils.run (getBuildRecipe (Flag.src_dir flags) builtIns rootFile)
43 else return (Recipe [rootFile] [])
45 moduleName <- File.build flags builtIns elmFiles
47 let elmos = map (Utils.elmo flags) elmFiles
48 js <- foldM appendToOutput BS.empty (elmos ++ jsFiles)
52 then do putStr "Generating JavaScript ... "
54 else do putStr "Generating HTML ... "
55 makeHtml js moduleName
57 let targetFile = Utils.buildPath flags rootFile extension
58 createDirectoryIfMissing True (takeDirectory targetFile)
59 BS.writeFile targetFile code
63 appendToOutput :: BS.ByteString -> FilePath -> IO BS.ByteString
64 appendToOutput js filePath = do
65 src <- BS.readFile filePath
66 return (BS.append src js)
68 getRuntime :: IO Html.JSSource
70 let runtimePath = Maybe.fromMaybe Path.runtime (Flag.set_runtime flags) in
71 case Flag.bundle_runtime flags of
72 False -> return (Html.Link runtimePath)
73 True -> Html.Source `fmap` BS.readFile runtimePath
75 makeJs :: BS.ByteString -> IO (String, BS.ByteString)
77 do runtime <- getRuntime
79 Html.Link _ -> return ("js", js)
80 Html.Source rts -> return ("js", BS.append rts js)
82 makeHtml :: BS.ByteString -> String -> IO (String, BS.ByteString)
83 makeHtml js moduleName =
84 do runtime <- getRuntime
85 return ("html", BS.pack $ renderHtml (html runtime))
87 sources js = map Html.Link (Flag.scripts flags) ++ [ Html.Source js ]
89 Html.generate runtime (takeBaseName rootFile) (sources js) moduleName ""
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