on master help sign in
Start generating documentation again. Does not work on all libraries yet, but should go through.
commit4ca3dbabdd13b1aab28684e5da59ac4e1c71a6c7 authorEvan Czaplicki <info@elm-lang.org> dateTue 10 Sep 2013, 18:47 (13 years ago) parent8ff5814
2 files changed+36−12
Elm.cabal+1−1 Setup.hs+35−11
Elm.cabal+1−1
@@ -22,7 +22,7 @@ Build-type: Custom
2222
2323Extra-source-files: changelog.txt
2424Data-dir: data
25−Data-files: elm-runtime.js interfaces.data
25+Data-files: elm-runtime.js interfaces.data docs.json
2626Cabal-version: >=1.9
2727
2828source-repository head
Setup.hs+35−11
@@ -12,6 +12,7 @@ import System.Process
1212import Control.Monad
1313import qualified Data.Binary as Binary
1414import qualified Data.ByteString.Lazy as BS
15+import qualified Data.List as List
1516
1617-- Part 1
1718-- ------
@@ -42,13 +43,20 @@ tempDir lbi = "temp"
4243rts :: LocalBuildInfo -> FilePath
4344rts lbi = rtsDir lbi </> "elm-runtime.js"
4445
46+-- The runtime is called:
47+docs :: LocalBuildInfo -> FilePath
48+docs lbi = rtsDir lbi </> "docs.json"
49+
4550-- The interfaces for the Standard Libraries live in:
4651interfaces :: LocalBuildInfo -> FilePath
4752interfaces lbi = rtsDir lbi </> "interfaces.data"
4853
49−-- buildDir with LocalBuildInfo points to "dist/build" (usually)
54+elm :: LocalBuildInfo -> FilePath
5055elm lbi = buildDir lbi </> "elm" </> "elm"
5156
57+document :: LocalBuildInfo -> FilePath
58+document lbi = buildDir lbi </> "elm-doc" </> "elm-doc"
59+
5260-- Care! This appears to be based on an unstable API
5361-- See: http://www.haskell.org/cabal/release/cabal-latest/doc/API/Cabal/Distribution-Simple.html#2
5462
@@ -96,7 +104,10 @@ myPostBuild as bfs pd lbi = do
96104 buildInterfaces lbi elmis
97105 putStrLn "Custom build step: build elm-runtime.js"
98106 buildRuntime lbi elmos
107+ putStrLn "Custom build step: build docs.json"
108+ buildDocs lbi
99109 removeDirectoryRecursive (tempDir lbi)
110+ removeDirectoryRecursive ("libraries" </> "docs")
100111 postBuild simpleUserHooks as bfs pd lbi
101112
102113
@@ -107,6 +118,7 @@ compileLibraries lbi = do
107118 createDirectoryIfMissing True rts
108119 out_c <- canonicalizePath temp -- temp (root folder)
109120 elm_c <- canonicalizePath (elm lbi) -- dist/build/elm/elm
121+ doc_c <- canonicalizePath (document lbi) -- dist/build/elm-doc/elm-doc
110122 rtd_c <- canonicalizePath rts -- data
111123
112124 let make file = do
@@ -118,11 +130,11 @@ compileLibraries lbi = do
118130 arg = Just [("Elm_datadir", rtd_c)]
119131 handle <- runProcess elm_c args Nothing arg Nothing Nothing Nothing
120132 exitCode <- waitForProcess handle
133+ rawSystem doc_c [file]
121134 return ( out_c </> replaceExtension file "elmo"
122135 , out_c </> replaceExtension file "elmi")
123136
124137 setCurrentDirectory "libraries"
125− print =<< getCurrentDirectory
126138 files <- getFiles ".elm" "."
127139 files <- unzip `fmap` mapM make files
128140 setCurrentDirectory ".."
@@ -145,11 +157,23 @@ buildInterfaces lbi elmis = do
145157buildRuntime :: LocalBuildInfo -> [FilePath] -> IO ()
146158buildRuntime lbi elmos = do
147159 createDirectoryIfMissing True (rtsDir lbi)
148− writeFile (rts lbi) "var Elm = {}; Elm.Native = {}; Elm.Native.Graphics = {};\n\
149− \var ElmRuntime = {}; ElmRuntime.Render = {};\n"
150− mapM_ (appendJS lbi) =<< getFiles ".js" "libraries"
151− mapM_ (appendJS lbi) elmos
152− mapM_ (appendJS lbi) =<< getFiles ".js" "runtime"
160+ let rts' = rts lbi
161+ writeFile rts' "var Elm = {}; Elm.Native = {}; Elm.Native.Graphics = {};\n\
162+ \var ElmRuntime = {}; ElmRuntime.Render = {};\n"
163+ mapM_ (appendTo rts') =<< getFiles ".js" "libraries"
164+ mapM_ (appendTo rts') elmos
165+ mapM_ (appendTo rts') =<< getFiles ".js" "runtime"
166+
167+buildDocs :: LocalBuildInfo -> IO ()
168+buildDocs lbi = do
169+ createDirectoryIfMissing True (rtsDir lbi)
170+ let docs' = docs lbi
171+ writeFile docs' "[\n"
172+ json <- getFiles ".json" ("libraries" </> "docs")
173+ let appends = map (appendTo docs') json
174+ addCommas = List.intersperse (appendFile docs' ",\n")
175+ sequence_ (addCommas appends)
176+ appendFile docs' "\n]"
153177
154178getFiles ext dir = do
155179 contents <- map (dir </>) `fmap` getDirectoryContents dir
@@ -158,8 +182,8 @@ getFiles ext dir = do
158182 filess <- mapM (getFiles ext) dirs
159183 return (files ++ concat filess)
160184
161−appendJS lbi file = do
162− putStrLn (dropExtension file)
163− str <- readFile file
185+appendTo :: FilePath -> FilePath -> IO ()
186+appendTo destination source = do
187+ str <- readFile source
164188 length str `seq` return ()
165− appendFile (rts lbi) str
189+ appendFile destination str