-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSite.hs
More file actions
96 lines (74 loc) · 2.79 KB
/
Copy pathSite.hs
File metadata and controls
96 lines (74 loc) · 2.79 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
{-# LANGUAGE LambdaCase #-}
module Main where
import Control.Lens
import Data.Binary.Builder as BB
import qualified Data.ByteString.Lazy as LBS
import qualified Data.ByteString.Char8 as BS8
import Data.Char (toUpper)
import Development.Shake
import Development.Shake.FilePath
import Heist as H
import Heist.Compiled as HC
dist :: FilePath
dist = "dist"
distFiles :: [FilePath]
distFiles = fmap (dist </>) $ [ "index.html" ]
`mappend` fmap ("games" </>) [ "ur.html" ]
`mappend` fmap ("css" </>) [ "main.css", "ur.css", "index.css" ]
-- `mappend` fmap ("svg" </>) []
`mappend` fmap ("js" </>) [ "ur.bundle.js" ]
templates :: H.HeistConfig m
templates = H.emptyHeistConfig
& H.hcNamespace .~ mempty
& H.hcLoadTimeSplices .~ H.defaultLoadTimeSplices
& H.hcTemplateLocations .~ [H.loadTemplates "templates"]
main :: IO ()
main = do
heist <- H.initHeist templates
shakeArgs shakeOptions $ do
want distFiles
phony "clean" $ do
putNormal "Cleaning files in dist/"
removeFilesAfter "dist" ["//*"]
dist <//> "*.html" %> \out -> do
let templateName = dropDirectory1 $ out -<.> ""
-- NOTE: We want to track the templates so that they get rebuilt on
-- changes
files <- getDirectoryFiles "" ["templates//*.tpl"]
need files
result <- case heist of
Right hs ->
case HC.renderTemplate hs $ BS8.pack templateName of
Just (a, _) -> do
liftIO . LBS.writeFile out . BB.toLazyByteString =<< a
pure True
_ -> pure False
_ -> pure False
if result
then putNormal ("Built template: " `mappend` out)
else putLoud ("Could not build: " `mappend` out)
dist </> "css" </> "*.css" %> \out -> do
let name = dropDirectory1 out
need [ name ]
putNormal $ "# copy (for " `mappend` out `mappend` " )"
copyFileChanged name out
dist </> "svg" </> "*.svg" %> \out -> do
let name = dropDirectory1 out
need [ name ]
copyFileChanged name out
"output" <//> "*.js" %> \_ -> do
pursFiles <- getDirectoryFiles "" ["src//*.purs"]
need pursFiles
unit $ cmd "stack exec psc-package build"
dist </> "js" </> "*.bundle.js" %> \out -> do
let moduleName = toUpperCase $ takeBaseName $ out -<.> ""
need [ "output" </> moduleName </> "index.js" ]
unit $ cmd "stack exec -- purs bundle output/**/*.js --main" moduleName "-m" moduleName "-o" out
-- NOTE: Doesn't properly minify html
-- stripWhiteSpace :: LBS.ByteString -> LBS.ByteString
-- stripWhiteSpace = LBS.filter (\c -> c /= fromIntegral (fromEnum ' ') && c /= fromIntegral (fromEnum '\n'))
-- Applies `toUpper` from "Data.Char" to the first character of a String.
toUpperCase :: String -> String
toUpperCase = \case
[] -> []
(x:xs) -> toUpper x : xs