From 901a9b9f0e26b361ed7b96fed2e05c7d6d0e0c13 Mon Sep 17 00:00:00 2001 From: Martijn Faassen Date: Mon, 7 Feb 2022 11:46:15 +0100 Subject: [PATCH] Factor out a compileAndInstall --- waspc/cli/Wasp/Cli/Command/Start.hs | 49 ++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/waspc/cli/Wasp/Cli/Command/Start.hs b/waspc/cli/Wasp/Cli/Command/Start.hs index b23e658e1..b909bb9fb 100644 --- a/waspc/cli/Wasp/Cli/Command/Start.hs +++ b/waspc/cli/Wasp/Cli/Command/Start.hs @@ -6,7 +6,7 @@ where import Control.Concurrent.Async (race) import Control.Monad.Except (throwError) import Control.Monad.IO.Class (liftIO) -import StrongPath (()) +import StrongPath (Abs, Dir, Path', ()) import Wasp.Cli.Command (Command, CommandError (..)) import Wasp.Cli.Command.Common ( findWaspProjectRootDirFromCwd, @@ -16,6 +16,7 @@ import Wasp.Cli.Command.Compile (compileIO) import Wasp.Cli.Command.Watch (watch) import qualified Wasp.Cli.Common as Common import Wasp.Cli.Terminal (asWaspFailureMessage, asWaspStartMessage, asWaspSuccessMessage) +import qualified Wasp.Generator.Common import qualified Wasp.Lib -- | Does initial compile of wasp code and then runs the generated project. @@ -25,6 +26,41 @@ start = do waspRoot <- findWaspProjectRootDirFromCwd let outDir = waspRoot Common.dotWaspDirInWaspProjectDir Common.generatedCodeDirInDotWaspDir + compileAndNpmInstall waspRoot outDir + + -- waspSaysC $ asWaspStartMessage "Compiling wasp code..." + -- compilationResult <- liftIO $ compileIO waspRoot outDir + -- case compilationResult of + -- Left compileError -> throwError $ CommandError $ asWaspFailureMessage "Compilation failed:" ++ compileError + -- Right () -> waspSaysC $ asWaspSuccessMessage "Code has been successfully compiled, project has been generated." + + -- -- TODO: Do smart npm install -> if we need to install stuff, install it, otherwise don't. + -- -- 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. + -- waspSaysC $ asWaspStartMessage "Setting up generated project..." + -- setupResult <- liftIO $ Wasp.Lib.setup outDir + -- case setupResult of + -- Left setupError -> throwError $ CommandError $ asWaspFailureMessage "Setup failed:" ++ setupError + -- Right () -> waspSaysC $ asWaspSuccessMessage "Setup successful." + + waspSaysC $ asWaspStartMessage "Listening for file changes..." + waspSaysC $ asWaspStartMessage "Starting up generated project..." + watchOrStartResult <- liftIO $ race (watch waspRoot outDir) (Wasp.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 $ asWaspFailureMessage "Start failed:" ++ startError + Right () -> error "This should never happen, start should never end but it did." + +compileAndNpmInstall :: + Path' Abs (Dir Common.WaspProjectDir) -> + Path' Abs (Dir Wasp.Generator.Common.ProjectRootDir) -> + Command () +compileAndNpmInstall waspRoot outDir = do waspSaysC $ asWaspStartMessage "Compiling wasp code..." compilationResult <- liftIO $ compileIO waspRoot outDir case compilationResult of @@ -42,13 +78,4 @@ start = do setupResult <- liftIO $ Wasp.Lib.setup outDir case setupResult of Left setupError -> throwError $ CommandError $ asWaspFailureMessage "Setup failed:" ++ setupError - Right () -> waspSaysC $ asWaspSuccessMessage "Setup successful." - - waspSaysC $ asWaspStartMessage "Listening for file changes..." - waspSaysC $ asWaspStartMessage "Starting up generated project..." - watchOrStartResult <- liftIO $ race (watch waspRoot outDir) (Wasp.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 $ asWaspFailureMessage "Start failed:" ++ startError - Right () -> error "This should never happen, start should never end but it did." + Right () -> waspSaysC $ asWaspSuccessMessage "Setup successful." \ No newline at end of file