2020-09-07 22:55:13 +03:00
|
|
|
module Command.Start
|
|
|
|
( start
|
|
|
|
) where
|
|
|
|
|
2020-09-11 18:31:17 +03:00
|
|
|
import Control.Concurrent.Async (race)
|
|
|
|
import Control.Monad.Except (throwError)
|
|
|
|
import Control.Monad.IO.Class (liftIO)
|
|
|
|
|
2021-04-16 13:43:57 +03:00
|
|
|
import qualified Cli.Common as Common
|
2020-09-11 18:31:17 +03:00
|
|
|
import Command (Command, CommandError (..))
|
|
|
|
import Command.Common (findWaspProjectRootDirFromCwd,
|
|
|
|
waspSaysC)
|
2020-09-19 17:11:09 +03:00
|
|
|
import Command.Compile (compileIO)
|
2020-09-11 18:31:17 +03:00
|
|
|
import Command.Watch (watch)
|
|
|
|
import qualified Lib
|
|
|
|
import StrongPath ((</>))
|
2020-09-07 22:55:13 +03:00
|
|
|
|
|
|
|
|
2020-09-11 18:31:17 +03:00
|
|
|
-- | Does initial compile of wasp code and then runs the generated project.
|
|
|
|
-- It also listens for any file changes and recompiles and restarts generated project accordingly.
|
2020-09-07 22:55:13 +03:00
|
|
|
start :: Command ()
|
|
|
|
start = do
|
2020-09-11 18:31:17 +03:00
|
|
|
waspRoot <- findWaspProjectRootDirFromCwd
|
2020-09-07 22:55:13 +03:00
|
|
|
let outDir = waspRoot </> Common.dotWaspDirInWaspProjectDir </> Common.generatedCodeDirInDotWaspDir
|
|
|
|
|
2020-09-11 18:31:17 +03:00
|
|
|
waspSaysC "Compiling wasp code..."
|
2020-09-19 17:11:09 +03:00
|
|
|
compilationResult <- liftIO $ compileIO waspRoot outDir
|
2020-09-11 18:31:17 +03:00
|
|
|
case compilationResult of
|
2020-09-10 17:33:26 +03:00
|
|
|
Left compileError -> throwError $ CommandError $ "Compilation failed: " ++ compileError
|
2020-09-11 18:31:17 +03:00
|
|
|
Right () -> waspSaysC "Code has been successfully compiled, project has been generated.\n"
|
2020-09-07 22:55:13 +03:00
|
|
|
|
2020-09-11 18:31:17 +03:00
|
|
|
-- TODO: Do smart install -> if we need to install stuff, install it, otherwise don't.
|
2020-09-07 22:55:13 +03:00
|
|
|
-- This should be responsibility of Generator, it should tell us how to install stuff.
|
|
|
|
-- But who checks out if stuff needs to be installed at all? That should probably be
|
|
|
|
-- Generator again. After installation, it should return some kind of data that describes that installation.
|
|
|
|
-- Then, next time, we give it data we have about last installation, and it uses that
|
|
|
|
-- to decide if installation needs to happen or not. If it happens, it returnes new data again.
|
|
|
|
-- Right now we have setup/installation being called, but it has not support for being "smart" yet.
|
2020-09-11 18:31:17 +03:00
|
|
|
waspSaysC "Setting up generated project..."
|
2020-09-10 17:33:26 +03:00
|
|
|
setupResult <- liftIO $ Lib.setup outDir
|
2020-09-07 22:55:13 +03:00
|
|
|
case setupResult of
|
2021-03-15 19:11:04 +03:00
|
|
|
Left setupError -> throwError $ CommandError $ "\nSetup failed: " ++ setupError
|
|
|
|
Right () -> waspSaysC "\nSetup successful.\n"
|
2020-09-11 18:31:17 +03:00
|
|
|
|
2021-03-15 19:11:04 +03:00
|
|
|
waspSaysC "\nListening for file changes..."
|
2020-09-11 18:31:17 +03:00
|
|
|
waspSaysC "Starting up generated project..."
|
|
|
|
watchOrStartResult <- liftIO $ race (watch waspRoot outDir) (Lib.start outDir)
|
|
|
|
case watchOrStartResult of
|
|
|
|
Left () -> error "This should never happen, listening for file changes should never end but it did."
|
|
|
|
Right startResult -> case startResult of
|
|
|
|
Left startError -> throwError $ CommandError $ "Start failed: " ++ startError
|
|
|
|
Right () -> error "This should never happen, start should never end but it did."
|