elm/Build.hs

42 lines
1.3 KiB
Haskell
Raw Normal View History

-- This file compiles all library and runtime code
-- into compiler/elm-runtime.js. It then rebuilds the compiler.
-- Run it with the command "runHaskell Build.hs".
import System.Cmd
import System.Directory
2013-03-11 17:45:43 +00:00
import System.Exit
import System.FilePath
import System.IO
import Language.Elm
rts = "compiler" </> "elm-runtime.js"
getFiles ext dir = do
contents <- map (dir </>) `fmap` getDirectoryContents dir
let files = filter (\f -> takeExtension f == ext) contents
dirs = filter (not . hasExtension) contents
filess <- mapM (getFiles ext) dirs
return (files ++ concat filess)
appendJS file = do
putStrLn (dropExtension file)
str <- readFile file
length str `seq` return ()
appendFile rts str
appendElm file = do
system ("elm --only-js " ++ file)
let jsFile = replaceExtension file ".js"
appendJS jsFile
removeFile jsFile
main = do
writeFile rts "Elm = {}; Elm.Native = {}; Elm.Native.Graphics = {}; Elm.Graphics = {};\n"
mapM_ appendJS =<< getFiles ".js" "libraries"
mapM_ appendElm =<< getFiles ".elm" "libraries"
mapM_ appendJS =<< getFiles ".js" "runtime"
putStrLn "\n+------------------------------------------+\
\\n| Success building runtime and libraries! |\
\\n+------------------------------------------+\n"
system ("cabal install compiler" </> "Elm.cabal")
2013-03-11 17:45:43 +00:00
exitSuccess