Learn to initialise projects with configurable themes
[xyz.git] / app / Main.hs
index 21dfb7e..742b739 100644 (file)
@@ -7,29 +7,41 @@ import System.Directory
 import Prelude hiding (init)
 import Data.List (intercalate)
 import Text.JSON
+import Text.JSON.Generic
 import Data.Text hiding (intercalate, unlines, init)
-
-data Project = Project {
-  name :: Text,
-  description :: Text
-  } deriving (Show)
+import System.File.Tree hiding (mapM, mapM_)
+import System.Directory (doesFileExist)
 
 main :: IO ()
 main = getArgs >>= parse
 
 init :: IO ()
 init = do
-  dirExists <- doesDirectoryExist "entries"
+  dirExists <- doesFileExist "xyz.json"
   if dirExists
     then putStrLn "Project already initialised"
     else do createDirectory "entries"
+            home <- getHomeDirectory
+            templates <- allFilesIn $ home ++ "/.xyz/themes"
             putStrLn "Enter a name for your project:"
             projectName <- getLine
             putStrLn "Enter short description for your project:"
             projectDescription <- getLine
-            writeFile "xyz.json" . encode . toJSObject $ [("name", projectName), ("description", projectDescription), ("theme", "xyz")]
+            putStrLn $ "Which theme would you like to use?\n\n" ++ (ununlines templates)
+            theme <- getLine
+            writeFile "xyz.json" . encode . toJSObject $ [("name", projectName), ("description", projectDescription), ("theme", theme)]
             putStrLn "Initialised empty project"
 
+build :: IO ()
+build = do
+  fileExists <- doesFileExist "xyz.json"
+  if fileExists
+    then do
+        files <- allFilesIn "entries"
+        home <- getHomeDirectory
+        config <- readFile "xyz.json"
+        someFunc (decodeJSON config :: ProjectConfig) files >> putStrLn "Build successful"
+    else putStrLn "This does not appear to be a valid project directory"
 
 ununlines :: [String] -> String
 ununlines = intercalate "\n\n"
@@ -44,7 +56,7 @@ usage =  putStr . ununlines $ [
   ]
 
 parse ["init"] = init >> exit
-parse ["build"] = someFunc >> exit
+parse ["build"] = build >> exit
 parse [_] = usage >> exit
 parse [] = usage >> exit