@@ -22,11 +22,9 @@ import Control.Monad.Error
22import Data.Version (showVersion)
22import Data.Version (showVersion)
24import System.Console.CmdTheLine
24import System.Console.CmdTheLine
25−import System.Directory
25+import System.Directory (createDirectoryIfMissing)
26− (doesFileExist, getModificationTime, createDirectoryIfMissing)
27import System.FilePath (takeDirectory)
26import System.FilePath (takeDirectory)
28import System.Exit (exitSuccess, exitFailure)
27import System.Exit (exitSuccess, exitFailure)
29−import System.IO.Error (tryIOError)
31import Text.Parsec (ParseError)
29import Text.Parsec (ParseError)
@@ -48,59 +46,26 @@ readInput (Just input) = fmap collect $ forM input $ \inputFile -> do
48 collect :: [(FilePath, Either ParseError [P.Module])] -> Either ParseError [(FilePath, P.Module)]
46 collect :: [(FilePath, Either ParseError [P.Module])] -> Either ParseError [(FilePath, P.Module)]
49 collect = fmap concat . sequence . map (\(fp, e) -> fmap (map ((,) fp)) e)
47 collect = fmap concat . sequence . map (\(fp, e) -> fmap (map ((,) fp)) e)
51−newtype Make a = Make { unMake :: ErrorT String IO a } deriving (Functor, Monad, MonadIO, MonadError String)
53−runMake :: Make a -> IO (Either String a)
54−runMake = runErrorT . unMake
56−makeIO :: IO a -> Make a
57−makeIO = Make . ErrorT . fmap (either (Left . show) Right) . tryIOError
59−instance P.MonadMake Make where
60− getTimestamp path = makeIO $ do
61− exists <- doesFileExist path
63− True -> Just <$> getModificationTime path
64− False -> return Nothing
65− readTextFile path = makeIO $ do
66− U.putStrLn $ "Reading " ++ path
68− writeTextFile path text = makeIO $ do
70− U.putStrLn $ "Writing " ++ path
71− U.writeFile path text
72− liftError = either throwError return
74−compile :: Bool -> P.Options -> Maybe [FilePath] -> Maybe FilePath -> Maybe FilePath -> IO ()
49+compile :: P.Options -> Maybe [FilePath] -> Maybe FilePath -> Maybe FilePath -> IO ()
75−compile makeMode opts input output externs = do
50+compile opts input output externs = do
76 modules <- readInput input
51 modules <- readInput input
77 case modules of
52 case modules of
78 Left err -> do
53 Left err -> do
79 U.print err
54 U.print err
80 exitFailure
55 exitFailure
81− Right ms ->
56+ Right ms -> do
84− e <- runMake $ P.make opts ms
92− case P.compile opts (map snd ms) of
57+ case P.compile opts (map snd ms) of
93− Left err -> do
58+ Left err -> do
94− U.putStrLn err
59+ U.putStrLn err
95− exitFailure
60+ exitFailure
96− Right (js, exts, _) -> do
61+ Right (js, exts, _) -> do
97− case output of
62+ case output of
98− Just path -> mkdirp path >> U.writeFile path js
63+ Just path -> mkdirp path >> U.writeFile path js
99− Nothing -> U.putStrLn js
64+ Nothing -> U.putStrLn js
100− case externs of
65+ case externs of
101− Just path -> mkdirp path >> U.writeFile path exts
66+ Just path -> mkdirp path >> U.writeFile path exts
102− Nothing -> return ()
67+ Nothing -> return ()
103− exitSuccess
68+ exitSuccess
105mkdirp :: FilePath -> IO ()
70mkdirp :: FilePath -> IO ()
106mkdirp = createDirectoryIfMissing True . takeDirectory
71mkdirp = createDirectoryIfMissing True . takeDirectory
@@ -145,10 +110,6 @@ noOpts :: Term Bool
145noOpts = value $ flag $ (optInfo [ "no-opts" ])
110noOpts = value $ flag $ (optInfo [ "no-opts" ])
146 { optDoc = "Skip the optimization phase." }
111 { optDoc = "Skip the optimization phase." }
149−make = value $ flag $ (optInfo [ "make" ])
150− { optDoc = "Run in make mode" }
152browserNamespace :: Term String
113browserNamespace :: Term String
153browserNamespace = value $ opt "PS" $ (optInfo [ "browser-namespace" ])
114browserNamespace = value $ opt "PS" $ (optInfo [ "browser-namespace" ])
154 { optDoc = "Specify the namespace that PureScript modules will be exported to when running in the browser." }
115 { optDoc = "Specify the namespace that PureScript modules will be exported to when running in the browser." }
@@ -172,7 +133,7 @@ stdInOrInputFiles prelude = combine <$> useStdIn <*> (not <$> noPrelude) <*> inp
172 combine True _ _ = Nothing
133 combine True _ _ = Nothing
174term :: FilePath -> Term (IO ())
135term :: FilePath -> Term (IO ())
175−term prelude = compile <$> make <*> options <*> stdInOrInputFiles prelude <*> outputFile <*> externsFile
136+term prelude = compile <$> options <*> stdInOrInputFiles prelude <*> outputFile <*> externsFile
177termInfo :: TermInfo
138termInfo :: TermInfo
178termInfo = defTI
139termInfo = defTI