{-# LANGUAGE RecordWildCards #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE DataKinds #-} module Main where import Prelude hiding (elem,notElem,lookup) import Data.Maybe import Data.Monoid ((<>)) import qualified Data.List as List import qualified Data.Map as Map import qualified Data.Text as T import qualified Data.Text.Lazy.IO as TL import qualified Data.Text.Lazy.Builder as TB import Control.Monad.State import Control.Monad.Except import System.IO (hPutStr,stderr) import System.FilePath ((>)) import System.Directory (createDirectoryIfMissing,listDirectory) import Options.Applicative import Language.PureScript.Externs import Language.PureScript.Environment import Language.PureScript.Names import Language.PureScript.TsdGen.Module import Data.Version (showVersion) import Paths_purescript_tsd_gen (version) processModules :: FilePath -> Maybe FilePath -> [String] -> Bool -> ExceptT ModuleProcessingError IO () processModules inputDir mOutputDir modules importAll = do let loadOneModule = recursivelyLoadExterns inputDir . moduleNameFromString . T.pack -- TODO: Check efVersion (env,m) <- execStateT (mapM_ loadOneModule modules) (initEnvironment, Map.empty) forM_ (catMaybes $ Map.elems m) $ \ef -> do let moduleName = runModuleName (efModuleName ef) modTsd <- processLoadedModule env ef importAll liftIO $ case mOutputDir of Just outputDir -> do let moduleDir = outputDir > T.unpack moduleName createDirectoryIfMissing True moduleDir TL.writeFile (moduleDir > "index.d.ts") (TB.toLazyText modTsd) Nothing -> do -- write to stdout TL.putStr (TB.toLazyText modTsd) data TsdOutput = TsdOutputDirectory FilePath | StdOutput | SameAsInput data PursTsdGen = PursTsdGen { pursOutputDirectory :: FilePath , tsdOutput :: TsdOutput , importAll :: Bool , moduleNames :: [String] } tsdOutputParser :: Parser TsdOutput tsdOutputParser = (TsdOutputDirectory <$> strOption (long "tsd-directory" <> metavar "