@@ -19,8 +19,9 @@ import Control.Monad.Supply.Class
19import Text.Printf
19import Text.Printf
21import System.Environment
21import System.Environment
22−import System.Directory (createDirectoryIfMissing, doesDirectoryExist, doesFileExist, getModificationTime)
22+import System.Directory (createDirectoryIfMissing, doesDirectoryExist, doesFileExist, getCurrentDirectory, getModificationTime)
23import System.FilePath ((</>), joinPath, splitDirectories, takeDirectory)
23import System.FilePath ((</>), joinPath, splitDirectories, takeDirectory)
24+import System.FilePath.Find
25import Data.Text (Text)
26import Data.Text (Text)
26import qualified Data.Text as T
27import qualified Data.Text as T
@@ -53,25 +54,48 @@ jsonToModule value =
53main :: IO ()
54main :: IO ()
55 args <- getArgs
56 args <- getArgs
56− if null args
57+ let (opts, files) = partition (isPrefixOf "--") args
57− then return ()
58+ opts' = (map . map) toLower opts
59+ if "--tests" `elem` opts'
59− let (opts, files) = partition (isPrefixOf "--") args
60− opts' = (map . map) toLower opts
61− if "--tests" `elem` opts'
64− when ("--makefile" `elem` opts') $
62+ when ("--makefile" `elem` opts') $
65− B.writeFile "Makefile" $(embedFile "support/Makefile")
63+ B.writeFile "Makefile" $(embedFile "support/Makefile")
66− when ("--help" `elem` opts') $
64+ when ("--help" `elem` opts') $
67− putStrLn help
65+ putStrLn help
68− when (not $ null files) $ do
66+ if null files then do
67+ currentDir <- getCurrentDirectory
68+ processFiles opts' [currentDir]
70+ processFiles opts' files
73+ processFiles :: [String] -> [FilePath] -> IO ()
74+ processFiles opts [file] = do
75+ isDir <- doesDirectoryExist file
77+ files <- find always (fileName ==? corefn) file
78+ if null files then do
81+ generateFiles opts files
83+ generateFiles opts [file]
84+ processFiles opts files = do
85+ let baseOutpath = basePath files
86+ writeRuntimeFiles baseOutpath
87+ Par.mapM (generateCode opts baseOutpath) files
89+ basePath :: [FilePath] -> FilePath
69− let filepath = takeDirectory (head files)
91+ let filepath = takeDirectory (head files) in
70− baseOutpath = joinPath $ (init $ splitDirectories filepath) ++ [outdir]
92+ joinPath $ (init $ splitDirectories filepath) ++ [outdir]
93+ generateFiles :: [String] -> [FilePath] -> IO ()
94+ generateFiles opts files = do
95+ let baseOutpath = basePath files
71− writeRuntimeFiles baseOutpath
96+ writeRuntimeFiles baseOutpath
72− Par.mapM (generateCode opts' baseOutpath) files
97+ Par.mapM (generateCode opts baseOutpath) files
74− return ()
98+ return ()
76generateCode :: [String] -> FilePath -> FilePath -> IO ()
100generateCode :: [String] -> FilePath -> FilePath -> IO ()
77generateCode opts baseOutpath jsonFile = do
101generateCode opts baseOutpath jsonFile = do
@@ -128,3 +152,10 @@ help = "Usage: psgo OPTIONS COREFN-FILES\n\
128 \ --tests Run test cases (under construction)\n\n\
152 \ --tests Run test cases (under construction)\n\n\
129 \See also:\n\
153 \See also:\n\
130 \ purs compile --help\n"
154 \ purs compile --help\n"
157+corefn = "corefn.json"
161+ putStrLn $ "No compiled purescript files (" <> corefn <> ") found"