on db44b15 help sign in
elk/Build.hs
39 lines 1.1 kB history raw
1-- This file compiles all library and runtime code
2-- into elm-runtime.js. Use the following command to run it:
3--
4-- runHaskell Build.hs
5--
6-- Note: This does NOT compile the compiler! Run `cabal install`
7-- from the compiler/ directory to do that.
9import System.Cmd
10import System.Directory
11import System.FilePath
12import System.IO
13import Language.Elm
15getFiles ext dir = do
16 contents <- map (dir </>) `fmap` getDirectoryContents dir
17 let files = filter (\f -> takeExtension f == ext) contents
18 dirs = filter (not . hasExtension) contents
19 filess <- mapM (getFiles ext) dirs
20 return (files ++ concat filess)
22appendJS file = do
23 putStrLn (dropExtension file)
24 str <- readFile file
25 length str `seq` return ()
26 appendFile "elm-runtime.js" str
28appendElm file = do
29 system ("elm --only-js " ++ file)
30 let jsFile = replaceExtension file ".js"
31 appendJS jsFile
32 removeFile jsFile
34main = do
35 writeFile "elm-runtime.js" "Elm = {}; Elm.Native = {};\n"
36 mapM_ appendJS =<< getFiles ".js" "libraries"
37 mapM_ appendElm =<< getFiles ".elm" "libraries"
38 mapM_ appendJS =<< getFiles ".js" "runtime"