4 import System.Environment
6 import System.Directory
7 import Prelude hiding (init)
8 import Data.List (intercalate)
10 import Text.JSON.Generic
11 import Data.Text hiding (intercalate, unlines, init)
12 import System.File.Tree hiding (mapM, mapM_)
13 import System.Directory (doesFileExist)
16 main = getArgs >>= parse
20 dirExists <- doesFileExist "xyz.json"
22 then putStrLn "Project already initialised"
23 else do createDirectory "entries"
24 home <- getHomeDirectory
25 templates <- allFilesIn $ home ++ "/.xyz/themes"
26 putStrLn "Enter a name for your project:"
27 projectName <- getLine
28 putStrLn "Enter short description for your project:"
29 projectDescription <- getLine
30 putStrLn $ "Which theme would you like to use?\n\n" ++ (ununlines templates)
32 writeFile "xyz.json" . encode . toJSObject $ [("name", projectName), ("description", projectDescription), ("theme", theme)]
33 putStrLn "Initialised empty project"
37 fileExists <- doesFileExist "xyz.json"
40 files <- allFilesIn "entries"
41 home <- getHomeDirectory
42 config <- readFile "xyz.json"
43 someFunc (decodeJSON config :: ProjectConfig) files >> putStrLn "Build successful"
44 else putStrLn "This does not appear to be a valid project directory"
46 ununlines :: [String] -> String
47 ununlines = intercalate "\n\n"
50 usage = putStr . ununlines $ [
51 "usage: xyz <command>",
52 "Commands:", unlines [
53 "\tinit\t\tInitialise a new site",
54 "\tbuild\t\tBuild the site"
58 parse ["init"] = init >> exit
59 parse ["build"] = build >> exit
60 parse [_] = usage >> exit
61 parse [] = usage >> exit
63 exit = exitWith ExitSuccess