2019-03-29 02:37:41 +03:00
|
|
|
module Lib
|
|
|
|
( compile
|
|
|
|
) where
|
|
|
|
|
2019-12-17 23:40:05 +03:00
|
|
|
import CompileOptions (CompileOptions)
|
2020-01-14 01:25:36 +03:00
|
|
|
import qualified CompileOptions
|
2020-01-16 20:32:47 +03:00
|
|
|
import qualified ExternalCode
|
2019-04-19 16:22:14 +03:00
|
|
|
import Parser
|
2019-03-29 02:37:41 +03:00
|
|
|
import Generator
|
2020-01-14 01:25:36 +03:00
|
|
|
import Wasp (setExternalCodeFiles)
|
2020-01-20 13:51:13 +03:00
|
|
|
import qualified Path
|
|
|
|
import qualified Path.Aliases as Path
|
2019-05-04 00:24:57 +03:00
|
|
|
|
2019-02-17 16:04:24 +03:00
|
|
|
|
2019-03-24 14:42:36 +03:00
|
|
|
type CompileError = String
|
|
|
|
|
2020-01-20 13:51:13 +03:00
|
|
|
compile :: Path.AbsFile -> Path.AbsDir -> CompileOptions -> IO (Either CompileError ())
|
2019-12-17 23:40:05 +03:00
|
|
|
compile waspFile outDir options = do
|
2020-01-20 13:51:13 +03:00
|
|
|
waspStr <- readFile (Path.toFilePath waspFile)
|
2019-04-19 16:22:14 +03:00
|
|
|
|
|
|
|
case parseWasp waspStr of
|
|
|
|
Left err -> return $ Left (show err)
|
2020-01-14 01:25:36 +03:00
|
|
|
Right wasp -> do
|
2020-01-16 20:32:47 +03:00
|
|
|
externalCodeFiles <- ExternalCode.readFiles (CompileOptions.externalCodeDirPath options)
|
2020-01-14 01:25:36 +03:00
|
|
|
generateCode $ wasp `setExternalCodeFiles` externalCodeFiles
|
2019-04-19 16:22:14 +03:00
|
|
|
where
|
2020-01-20 13:51:13 +03:00
|
|
|
generateCode wasp = writeWebAppCode wasp (Path.toFilePath outDir) options >> return (Right ())
|