-
-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathyst.hs
73 lines (65 loc) · 2.47 KB
/
yst.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
{-
Copyright (C) 2009 John MacFarlane <jgm@berkeley.edu>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-}
module Main
where
import Paths_yst
import Yst.Util
import Yst.Config
import Yst.Build
import System.FilePath
import System.Environment
import System.Directory
import System.Exit
-- Note: ghc >= 6.12 (base >=4.2) supports unicode through iconv
-- So we use System.IO.UTF8 only if we have an earlier version
#if MIN_VERSION_base(4,2,0)
import System.IO (hPutStrLn)
#else
import Prelude hiding (readFile, putStrLn, print, writeFile)
import System.IO.UTF8
#endif
import System.IO (stderr)
import Control.Monad
createSite :: FilePath -> IO ()
createSite path = do
existsd <- doesDirectoryExist path
existsf <- doesFileExist path
when (existsd || existsf) $ do
hPutStrLn stderr $ "Aborting! " ++ path ++ " already exists."
exitWith $ ExitFailure 5
demoDir <- getDataFileName "demo"
contents <- liftM (filter (/=".") . map (makeRelative demoDir)) $ getDirectoryContentsRecursive demoDir
forM_ contents $ \file -> do
let dest = path </> file
createDirectoryIfMissing True $ takeDirectory dest
copyFile (demoDir </> file) dest
readme <- getDataFileName "README.markdown"
copyFile readme (path </> "README")
hPutStrLn stderr $ "Created starter site in " ++ path
usageMessage :: IO ()
usageMessage = hPutStrLn stderr $
"yst - create static website from string templates and YAML data\n" ++
"Usage:\n" ++
"yst [-f CONFIGFILE] # build website\n" ++
"yst create DIRECTORY # create starter site in DIRECTORY"
main :: IO ()
main = do
args <- getArgs
site <- case args of
["-f",x] -> parseConfigFile x
[] -> parseConfigFile "config.yaml"
["create",d] -> createSite d >> exitWith ExitSuccess
_ -> usageMessage >> exitWith (ExitFailure 1)
buildSite site