wasp/src/Lib.hs

28 lines
853 B
Haskell
Raw Normal View History

module Lib
( compile
) where
import CompileOptions (CompileOptions)
import qualified CompileOptions
import qualified ExternalCode
2019-04-19 16:22:14 +03:00
import Parser
import Generator
import Wasp (setExternalCodeFiles)
import qualified Path
import qualified Path.Aliases as Path
type CompileError = String
compile :: Path.AbsFile -> Path.AbsDir -> CompileOptions -> IO (Either CompileError ())
compile waspFile outDir options = do
waspStr <- readFile (Path.toFilePath waspFile)
2019-04-19 16:22:14 +03:00
case parseWasp waspStr of
Left err -> return $ Left (show err)
Right wasp -> do
externalCodeFiles <- ExternalCode.readFiles (CompileOptions.externalCodeDirPath options)
generateCode $ wasp `setExternalCodeFiles` externalCodeFiles
2019-04-19 16:22:14 +03:00
where
generateCode wasp = writeWebAppCode wasp (Path.toFilePath outDir) options >> return (Right ())