-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathBuild.hs
76 lines (61 loc) · 2.23 KB
/
Build.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
import Development.Shake
import Development.Shake.Command
import Development.Shake.FilePath
import Development.Shake.Util
import Control.Monad (forM_, unless)
import System.Directory (createDirectoryIfMissing)
jsexe :: FilePath
jsexe = ghcjsDist </> "build/flatris-reflex/flatris-reflex.jsexe"
scripts :: [FilePath]
scripts = ["all.js", "lib.js", "out.js", "rts.js", "runmain.js"]
jsexeFiles :: [FilePath]
jsexeFiles = map (jsexe </>) scripts
ghcjsDist :: FilePath
ghcjsDist = "dist-ghcjs"
main :: IO ()
main = shakeArgs shakeOptions{shakeFiles="dist"} $ do
want ["docs/index.html", "docs/.nojekyll"]
phony "cabalBuild" $
need [jsexe </> "all.js"]
phony "clean" $ do
putNormal "Cleaning files in dist"
removeFilesAfter "dist" ["//*"]
ghcjsDist </> "setup-config" %> \out -> do
need ["flatris.cabal"]
cmd "nix-shell --argstr compiler ghcjs --run" ["cabal configure --ghcjs --builddir=" ++ ghcjsDist]
jsexeFiles &%> \out -> do
needHaskellSources
() <- cmd "cabal build" ["--builddir=" ++ ghcjsDist]
copyAssets jsexe
jsexe </> "*.min.js" %> \out -> do
let maxi = dropExtension out -<.> "js"
externs = maxi <.> "externs"
need [maxi]
Stdout mini <- cmd "closure-compiler" [maxi] "--compilation_level=ADVANCED_OPTIMIZATIONS" ["--externs=" ++ externs]
writeFileChanged out mini
jsexe </> "*.js.gz" %> \out -> do
let js = dropExtension out
need [js]
cmd "zopfli -i1000" [js]
-- site needs index.html, minified js, and stylesheets
"docs/index.html" %> \out -> do
forM_ ["all.min.js", "all.min.js.gz"] $ \js ->
copyFileChanged (jsexe </> js) ("docs" </> js)
copyAssets "docs"
copyFile' "static/index-min.html" out
return ()
-- github pages jekyll filters some things
"docs/.nojekyll" %> \out -> writeFile' out ""
needHaskellSources :: Action ()
needHaskellSources = do
sources <- getDirectoryFiles "" ["src//*.hs", "app-reflex//*.hs"]
need ((ghcjsDist </> "setup-config") : sources)
copyAssets :: FilePath -> Action ()
copyAssets dst = do
assets <- getDirectoryFiles "" ["static//*"]
need assets
forM_ assets $ \f -> do
let dst' = dst </> dropDirectory1 f
need [f]
liftIO $ createDirectoryIfMissing True (takeDirectory dst')
copyFile' f dst'