Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 49 lines (41 sloc) 1.443 kb
9f9c0b1 @dmpots Initial Revision
authored
1 #!/usr/bin/env runhaskell
2 import Distribution.Simple
031c266 @dmpots Added ability to use local run configurations
authored
3 import Control.Monad
4 import Data.List
5 import System.Directory
6 import System.FilePath
7 import System.IO
8
9 main = defaultMainWithHooks simpleUserHooks {postConf = writeLocalConf, postClean = deleteLocalConf}
10
11 writeLocalConf _ _ _ _ = do
12 findLocalConfigModules
13
14 deleteLocalConf _ _ _ _ = do
15 safeDelete importsFileName
16 safeDelete modulesFileName
17
18 safeDelete :: FilePath -> IO ()
19 safeDelete f = do
20 e <- doesFileExist f
21 when e (removeFile f)
22
23 findLocalConfigModules :: IO ()
24 findLocalConfigModules = do
25 fs <- getDirectoryContents configDir
26 putStr "\nLooking for local configuration modules... "
27 let modNames = map dropExtension $ filter (".hs" `isSuffixOf`) fs
28 let imports = map importStmt $ modNames
29 let modules = map importAs $ modNames
30 putStrLn $ "found ("++ (show.length$ modNames)++")"
31 writeToFile importsFileName imports
32 writeToFile modulesFileName modules
33 where
34 importStmt m = "import qualified "++m++" as " ++importAs m
35 writeToFile fName contents = do
36 h <- openFile fName WriteMode
37 putStrLn $ "writing " ++ fName
38 putStrLn $ unlines contents
39 hPutStr h (unlines contents)
40 hClose h
41
42 importAs :: String -> String
43 importAs modName = modName++"_Config"
44
45 importsFileName, modulesFileName :: FilePath
46 configDir = "config"
47 importsFileName = configDir </> "LocalConfigImports.txt"
48 modulesFileName = configDir </> "LocalConfigModules.txt"
Something went wrong with that request. Please try again.