Make module handling nicer/more general
Getty Ritter
6 years ago
19 | 19 |
| SetRoot T.Text
|
20 | 20 |
| AddDep T.Text
|
21 | 21 |
| AddUsualDeps
|
| 22 |
| AddMod T.Text
|
22 | 23 |
deriving (Eq, Show)
|
23 | 24 |
|
24 | 25 |
options :: [Opt.OptDescr Option]
|
|
26 | 27 |
[ Opt.Option ['b'] ["bin"]
|
27 | 28 |
(Opt.ReqArg (AddBinary . T.pack) "PROGRAM NAME")
|
28 | 29 |
"Add another binary target to this Cabal file"
|
| 30 |
, Opt.Option ['m'] ["module"]
|
| 31 |
(Opt.ReqArg (AddMod . T.pack) "MODULE NAME")
|
| 32 |
"Add another library module to this Cabal file"
|
29 | 33 |
, Opt.Option ['r'] ["root"]
|
30 | 34 |
(Opt.ReqArg (SetRoot . T.pack) "DIRECTORY")
|
31 | 35 |
"Set the root directory for this project"
|
|
62 | 66 |
where
|
63 | 67 |
go (AddBinary n) proj =
|
64 | 68 |
proj & C.binDetails %~ (C.mkBinary n :)
|
| 69 |
go (AddMod m) proj =
|
| 70 |
proj & C.libDetails %~ fmap (& C.libMods %~ (m :))
|
65 | 71 |
go (SetCategory s) proj =
|
66 | 72 |
proj & C.projectDetails . C.projectCategory .~ Just s
|
67 | 73 |
go (SetSynopsis s) proj =
|
35 | 35 |
, _execDeps = []
|
36 | 36 |
}
|
37 | 37 |
|
38 | |
mkLibrary :: T.Text -> LibraryDetails
|
39 | |
mkLibrary n = LibraryDetails
|
40 | |
{ _libExposedModules = [capitalize n]
|
| 38 |
mkLibrary :: LibraryDetails
|
| 39 |
mkLibrary = LibraryDetails
|
| 40 |
{ _libMods = []
|
41 | 41 |
, _libDeps = []
|
42 | 42 |
}
|
43 | 43 |
|
|
59 | 59 |
projectBin deets =
|
60 | 60 |
mkProject deets & binDetails .~ [ bin ]
|
61 | 61 |
& libDetails .~ Just lib
|
62 | |
where bin = mkBinary name & execDeps .~ ["name"]
|
63 | |
lib = mkLibrary name
|
| 62 |
where bin = mkBinary name & execDeps .~ [name]
|
| 63 |
lib = mkLibrary & libMods .~ [capitalize name]
|
64 | 64 |
name = deets^.projectName
|
65 | 65 |
|
66 | 66 |
usualDeps :: [T.Text]
|
|
73 | 73 |
|
74 | 74 |
library :: ProjectDetails -> Project
|
75 | 75 |
library deets =
|
76 | |
mkProject deets & libDetails .~ Just lib
|
77 | |
where
|
78 | |
lib = mkLibrary (deets^.projectName)
|
| 76 |
mkProject deets & libDetails .~ Just mkLibrary
|
79 | 77 |
|
80 | 78 |
mkdirBase :: T.Text -> [T.Text] -> IO ()
|
81 | 79 |
mkdirBase base fp = do
|
|
128 | 126 |
case (pr^.libDetails) of
|
129 | 127 |
Nothing -> return ()
|
130 | 128 |
Just lib -> do
|
131 | |
forM_ (lib^.libExposedModules) $ \ m -> do
|
132 | |
let modPath = "src" : T.splitOn "." (m <> ".hs")
|
133 | |
write modPath (defaultLib m)
|
| 129 |
forM_ (lib^.libMods) $ \ m -> do
|
| 130 |
let modPath = "src" : T.splitOn "." m
|
| 131 |
modPath' = init modPath ++ [last modPath <> ".hs"]
|
| 132 |
write modPath' (defaultLib m)
|
134 | 133 |
|
135 | 134 |
forM_ (pr^.binDetails) $ \e -> do
|
136 | 135 |
write [e^.execDir, "Main.hs"] defaultBin
|
42 | 42 |
, " default-extensions: ScopedTypeVariables"
|
43 | 43 |
] <> mods
|
44 | 44 |
where
|
45 | |
mods = case lib^.libExposedModules of
|
| 45 |
mods = case lib^.libMods of
|
46 | 46 |
[] -> []
|
47 | 47 |
(x:xs) ->
|
48 | 48 |
(" exposed-modules: " <> x) :
|
17 | 17 |
}
|
18 | 18 |
|
19 | 19 |
data LibraryDetails = LibraryDetails
|
20 | |
{ _libExposedModules :: [T.Text]
|
21 | |
, _libDeps :: [T.Text]
|
| 20 |
{ _libMods :: [T.Text]
|
| 21 |
, _libDeps :: [T.Text]
|
22 | 22 |
}
|
23 | 23 |
|
24 | 24 |
data ExecutableDetails = ExecutableDetails
|