-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathCodeGenerator.hs
40 lines (34 loc) · 1.13 KB
/
CodeGenerator.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
import System.Environment
import ConfigParser
import Control.Applicative
import Elixir
import Head
import Helpers
import JSONParser (parseJson)
import Parser
filename dest p = dest ++ "/lib/generated_code/" ++ snake p ++ ".ex"
writeCode dest m (p, code) =
let f = filename dest p
in writeFile f code >> return f
writeStarter dest (name, code) =
let f = dest ++ "/lib/mix/tasks/" ++ snake name ++ "_starter.ex"
in writeFile f code >> return f
convert name init next dest config (m, ds) = do
files <- mapM (writeCode dest name) (generate (Spec m init next ds) config)
starter <- mapM (writeStarter dest . generateStarter (Spec m init next ds)) (processNames config)
return (starter, files)
main = do
(configFile:_) <- getArgs
config <- parseConfig configFile
case config of
Left e -> putStrLn e
Right (Config _ _ _ i n _ mode file _ _ dest) -> do
ls <-
if mode == "tla"
then parseTla file
else parseJson file
case liftA2 (convert file i n dest) config ls of
Left e -> putStrLn e
Right f -> do
a <- f
putStrLn ("Elixirs files written to " ++ show a)