17
17
{-# OPTIONS_GHC -Wno-safe #-}
18
18
{-# OPTIONS_GHC -Wno-unsafe #-}
19
19
{-# OPTIONS_GHC -fprint-potential-instances #-}
20
- #if MIN_VERSION_ghc(9,0,0)
20
+ #if __GLASGOW_HASKELL__ >= 900
21
21
{-# OPTIONS_GHC -Wno-missing-kind-signatures #-}
22
22
{-# OPTIONS_GHC -Wno-prepositive-qualified-module #-}
23
23
{-# OPTIONS_GHC -Wno-missing-safe-haskell-mode #-}
@@ -28,31 +28,10 @@ import Distribution.Simple hiding (Module (..))
28
28
import Distribution.Simple.LocalBuildInfo (LocalBuildInfo (.. ))
29
29
import Distribution.Simple.Utils (writeUTF8File )
30
30
import Functora.Prelude hiding (empty )
31
- import GHC (runGhc )
32
- import GHC.Paths (libdir )
33
- import GHC.SourceGen
34
31
import qualified System.Directory as Directory
35
32
import System.Environment (getProgName )
36
33
import qualified Text.Casing as Casing
37
34
38
- #if MIN_VERSION_ghc(9,0,0)
39
- import "ghc" GHC.Driver.Session (getDynFlags )
40
- import "ghc" GHC.Utils.Outputable
41
- ( Outputable (.. ),
42
- text ,
43
- vcat ,
44
- ($+$) ,
45
- )
46
- #else
47
- import "ghc" DynFlags (getDynFlags )
48
- import "ghc" Outputable
49
- ( Outputable (.. ),
50
- text ,
51
- vcat ,
52
- ($+$) ,
53
- )
54
- #endif
55
-
56
35
main :: IO ()
57
36
main =
58
37
defaultMainWithHooks
@@ -62,86 +41,40 @@ main =
62
41
>> buildHook simpleUserHooks p l h f
63
42
}
64
43
65
- data Module = Module
66
- { moduleHeader :: [String ],
67
- moduleBody :: HsModule'
68
- }
69
-
70
- instance Outputable Module where
71
- ppr m =
72
- vcat (text <$> moduleHeader m)
73
- $+$ ppr (moduleBody m)
74
-
75
44
codeGenHook :: LocalBuildInfo -> IO ()
76
45
codeGenHook _ = do
77
46
prog <- getProgName
78
- runGhc (Just libdir) $ do
79
- dflags <- getDynFlags
80
- cssRaw <- liftIO $ Directory. listDirectory " dist/themes/"
81
- let cssKebab =
82
- sort . fmap (dropEnd 8 ) $ filter (isSuffixOf " .min.css" ) cssRaw
83
- let cssPascal =
84
- fmap Casing. pascal cssKebab
85
- if cssKebab == fmap Casing. kebab cssPascal
86
- then putStrLn $ inspect @ Text cssPascal
87
- else
88
- error
89
- $ " Bad kebab <-> pascal isomorphism in "
90
- <> inspect @ Text cssKebab
91
- liftIO
92
- . writeFileIfChanged
93
- . showPpr dflags
94
- $ generateCode prog cssPascal
47
+ cssRaw <- liftIO $ Directory. listDirectory " dist/themes/"
48
+ let cssKebab =
49
+ sort . fmap (dropEnd 8 ) $ filter (isSuffixOf " .min.css" ) cssRaw
50
+ let cssPascal =
51
+ fmap Casing. pascal cssKebab
52
+ if cssKebab == fmap Casing. kebab cssPascal
53
+ then putStrLn $ inspect @ Text cssPascal
54
+ else
55
+ error
56
+ $ " Bad kebab <-> pascal isomorphism in "
57
+ <> inspect @ Text cssKebab
58
+ liftIO
59
+ . writeFileIfChanged
60
+ $ generateCode prog cssPascal
95
61
96
- generateCode :: String -> [String ] -> Module
62
+ generateCode :: String -> [String ] -> String
97
63
generateCode prog css =
98
- Module
99
- { moduleHeader = header,
100
- moduleBody =
101
- module'
102
- (Just " Functora.Miso.Theme" )
103
- (Just [thingAll " Theme" ])
104
- ( fmap
105
- import'
106
- [ " Prelude" ,
107
- " Data.Data" ,
108
- " Data.Binary" ,
109
- " GHC.Generics"
110
- ]
111
- )
112
- [ data'
113
- " Theme"
114
- mempty
115
- ( fmap (flip prefixCon mempty . fromString) css
116
- )
117
- [ derivingStock
118
- $ fmap
119
- var
120
- [ " Eq" ,
121
- " Ord" ,
122
- " Show" ,
123
- " Read" ,
124
- " Data" ,
125
- " Generic" ,
126
- " Enum" ,
127
- " Bounded"
128
- ]
129
- ],
130
- instance' (var " Binary" @@ var " Theme" ) mempty
131
- ]
132
- }
133
- where
134
- header =
135
- [ " {- DO NOT EDIT. This file was auto-generated by the "
136
- <> prog
137
- <> " program. -}"
138
- -- languagePragma "DeriveDataTypeable",
139
- -- optionsGhcPragma "-Wno-missing-export-lists"
140
- ]
141
-
142
- -- languagePragma, optionsGhcPragma :: String -> String
143
- -- languagePragma s = "{-# LANGUAGE " <> s <> "#-}"
144
- -- optionsGhcPragma s = "{-# OPTIONS_GHC " <> s <> "#-}"
64
+ intercalate
65
+ " \n "
66
+ [ " {- DO NOT EDIT. This file was auto-generated by the "
67
+ <> prog
68
+ <> " program. -}" ,
69
+ " module Functora.Miso.Theme (Theme(..)) where" ,
70
+ " import Prelude" ,
71
+ " import Data.Data" ,
72
+ " import Data.Binary" ,
73
+ " import GHC.Generics" ,
74
+ " data Theme = " <> intercalate " \n | " css,
75
+ " deriving stock (Eq, Ord, Show, Read, Data, Generic, Enum, Bounded)" ,
76
+ " instance Binary Theme"
77
+ ]
145
78
146
79
writeFileIfChanged :: String -> IO ()
147
80
writeFileIfChanged newFile = do
0 commit comments