-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathSetup.hs
83 lines (73 loc) · 3 KB
/
Setup.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import Distribution.Simple
import Distribution.Simple.Setup
import Distribution.Simple.LocalBuildInfo
import Distribution.PackageDescription
import System.IO
import System.Exit
import System.Process
import Control.Monad
import System.FilePath
import System.Directory
main :: IO ()
main = defaultMainWithHooks simpleUserHooks { postBuild = myPostBuild }
myPostBuild :: Args -> BuildFlags -> PackageDescription -> LocalBuildInfo -> IO ()
myPostBuild args flags pd lbi =
do putStrLn "Building debug panel interface"
buildInterface ("elm-reactor" </> "slider")
concatJS
copyPanelImages
buildInterface :: FilePath -> IO ()
buildInterface workingDir =
do exitCode <- compile $ args "debuggerInterface.elm"
case exitCode of
ExitFailure _ ->
putStrLn "Build failed: debuggerInterface"
ExitSuccess ->
do let compiledFile = workingDir </> "build" </> "debuggerInterface.js"
let destinationFile = "elm-reactor" </> "assets" </> "_reactor" </> "debuggerInterface.js"
copyFile compiledFile destinationFile
removeFile compiledFile
removeEverything workingDir "Slider.elm"
removeEverything workingDir "debuggerInterface.elm"
where
args file =
[ "--make"
, "--only-js"
, file
]
compile args =
do let workingDir' = Just workingDir
handle <- runProcess "elm" args workingDir' Nothing Nothing Nothing Nothing
exitCode <- waitForProcess handle
return exitCode
removeEverything dir file =
do remove "cache" "elmi"
remove "cache" "elmo"
remove "build" "js"
where
remove :: String -> String -> IO ()
remove subdir ext =
do let path = dir </> subdir </> file`replaceExtension` ext
exists <- doesFileExist path
when exists (removeFile path)
concatJS :: IO ()
concatJS =
do let files =
[ "elm-reactor" </> "assets" </> "_reactor" </> "debuggerInterface.js"
, "elm-reactor" </> "assets" </> "_reactor" </> "toString.js"
, "elm-reactor" </> "assets" </> "_reactor" </> "core.js"
, "resources" </> "debugger" </> "debug-panel.js"
]
megaJS <- concat `fmap` mapM readFile files
_ <- putStrLn "Writing composite debugger.js"
writeFile ("resources" </> "debugger.js") megaJS
copyPanelImages :: IO ()
copyPanelImages =
do let serverImageDir = "elm-reactor" </> "assets" </> "_reactor" </> "debugger"
files <- getDirectoryContents serverImageDir
let images = filter (\x -> ".png" == takeExtensions x) files
let destinationDir = "resources" </> "_reactor" </> "debugger"
createDirectoryIfMissing True destinationDir
let srcImgs = map (serverImageDir </>) images
let destImgs = map (destinationDir </>) images
mapM_ (uncurry copyFile) $ zip srcImgs destImgs