git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Make psgo able to find and build corefn.json files from a dir
commit91a535d4849f844a449817bef68d174072bff98d authorAndy Arvanitis <andyarvanitis@gmail.com> dateThu 4 Jul 2019, 12:20 (7 years ago) parentba2cc5c
2 files changed+51−19
app/Main.hs+50−19 package.yaml+1
app/Main.hs+50−19
@@ -19,8 +19,9 @@ import Control.Monad.Supply.Class
1919import Text.Printf
2020
2121import System.Environment
22−import System.Directory (createDirectoryIfMissing, doesDirectoryExist, doesFileExist, getModificationTime)
22+import System.Directory (createDirectoryIfMissing, doesDirectoryExist, doesFileExist, getCurrentDirectory, getModificationTime)
2323import System.FilePath ((</>), joinPath, splitDirectories, takeDirectory)
24+import System.FilePath.Find
2425
2526import Data.Text (Text)
2627import qualified Data.Text as T
@@ -53,25 +54,48 @@ jsonToModule value =
5354main :: IO ()
5455main = do
5556 args <- getArgs
56− if null args
57− then return ()
57+ let (opts, files) = partition (isPrefixOf "--") args
58+ opts' = (map . map) toLower opts
59+ if "--tests" `elem` opts'
60+ then runTests
5861 else do
59− let (opts, files) = partition (isPrefixOf "--") args
60− opts' = (map . map) toLower opts
61− if "--tests" `elem` opts'
62− then runTests
63− else do
64− when ("--makefile" `elem` opts') $
65− B.writeFile "Makefile" $(embedFile "support/Makefile")
66− when ("--help" `elem` opts') $
67− putStrLn help
68− when (not $ null files) $ do
69− let filepath = takeDirectory (head files)
70− baseOutpath = joinPath $ (init $ splitDirectories filepath) ++ [outdir]
71− writeRuntimeFiles baseOutpath
72− Par.mapM (generateCode opts' baseOutpath) files
73− return ()
74− return ()
62+ when ("--makefile" `elem` opts') $
63+ B.writeFile "Makefile" $(embedFile "support/Makefile")
64+ when ("--help" `elem` opts') $
65+ putStrLn help
66+ if null files then do
67+ currentDir <- getCurrentDirectory
68+ processFiles opts' [currentDir]
69+ else do
70+ processFiles opts' files
71+ return ()
72+ where
73+ processFiles :: [String] -> [FilePath] -> IO ()
74+ processFiles opts [file] = do
75+ isDir <- doesDirectoryExist file
76+ if isDir then do
77+ files <- find always (fileName ==? corefn) file
78+ if null files then do
79+ noneFound
80+ else do
81+ generateFiles opts files
82+ else do
83+ generateFiles opts [file]
84+ processFiles opts files = do
85+ let baseOutpath = basePath files
86+ writeRuntimeFiles baseOutpath
87+ Par.mapM (generateCode opts baseOutpath) files
88+ return ()
89+ basePath :: [FilePath] -> FilePath
90+ basePath files =
91+ let filepath = takeDirectory (head files) in
92+ joinPath $ (init $ splitDirectories filepath) ++ [outdir]
93+ generateFiles :: [String] -> [FilePath] -> IO ()
94+ generateFiles opts files = do
95+ let baseOutpath = basePath files
96+ writeRuntimeFiles baseOutpath
97+ Par.mapM (generateCode opts baseOutpath) files
98+ return ()
7599
76100generateCode :: [String] -> FilePath -> FilePath -> IO ()
77101generateCode opts baseOutpath jsonFile = do
@@ -128,3 +152,10 @@ help = "Usage: psgo OPTIONS COREFN-FILES\n\
128152 \ --tests Run test cases (under construction)\n\n\
129153 \See also:\n\
130154 \ purs compile --help\n"
155+
156+corefn :: String
157+corefn = "corefn.json"
158+
159+noneFound :: IO ()
160+noneFound = do
161+ putStrLn $ "No compiled purescript files (" <> corefn <> ") found"
package.yaml+1
@@ -40,6 +40,7 @@ dependencies:
4040- directory -any
4141- process -any
4242- file-embed -any
43+- filemanip -any
4344
4445library:
4546 source-dirs: src