mirror of
https://github.com/wasp-lang/wasp.git
synced 2024-12-25 10:03:07 +03:00
Factor out this function into its own module
We also need to reuse it during watch
This commit is contained in:
parent
ae5f498b65
commit
988929fbdc
38
waspc/cli/Wasp/Cli/Command/CompileAndSetup.hs
Normal file
38
waspc/cli/Wasp/Cli/Command/CompileAndSetup.hs
Normal file
@ -0,0 +1,38 @@
|
||||
module Wasp.Cli.Command.CompileAndSetup (compileAndSetup) where
|
||||
|
||||
import Control.Monad.Except (throwError)
|
||||
import Control.Monad.IO.Class (liftIO)
|
||||
import StrongPath (Abs, Dir, Path')
|
||||
import Wasp.Cli.Command (Command, CommandError (..))
|
||||
import Wasp.Cli.Command.Common
|
||||
( waspSaysC,
|
||||
)
|
||||
import Wasp.Cli.Command.Compile (compileIO)
|
||||
import qualified Wasp.Cli.Common as Common
|
||||
import Wasp.Cli.Terminal (asWaspFailureMessage, asWaspStartMessage, asWaspSuccessMessage)
|
||||
import qualified Wasp.Generator.Common
|
||||
import qualified Wasp.Lib
|
||||
|
||||
compileAndSetup ::
|
||||
Path' Abs (Dir Common.WaspProjectDir) ->
|
||||
Path' Abs (Dir Wasp.Generator.Common.ProjectRootDir) ->
|
||||
Command ()
|
||||
compileAndSetup waspRoot outDir = do
|
||||
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."
|
@ -6,17 +6,16 @@ where
|
||||
import Control.Concurrent.Async (race)
|
||||
import Control.Monad.Except (throwError)
|
||||
import Control.Monad.IO.Class (liftIO)
|
||||
import StrongPath (Abs, Dir, Path', (</>))
|
||||
import StrongPath ((</>))
|
||||
import Wasp.Cli.Command (Command, CommandError (..))
|
||||
import Wasp.Cli.Command.Common
|
||||
( findWaspProjectRootDirFromCwd,
|
||||
waspSaysC,
|
||||
)
|
||||
import Wasp.Cli.Command.Compile (compileIO)
|
||||
import Wasp.Cli.Command.CompileAndSetup (compileAndSetup)
|
||||
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 Wasp.Cli.Terminal (asWaspFailureMessage, asWaspStartMessage)
|
||||
import qualified Wasp.Lib
|
||||
|
||||
-- | Does initial compile of wasp code and then runs the generated project.
|
||||
@ -36,27 +35,3 @@ start = do
|
||||
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."
|
||||
|
||||
compileAndSetup ::
|
||||
Path' Abs (Dir Common.WaspProjectDir) ->
|
||||
Path' Abs (Dir Wasp.Generator.Common.ProjectRootDir) ->
|
||||
Command ()
|
||||
compileAndSetup waspRoot outDir = do
|
||||
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 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."
|
Loading…
Reference in New Issue
Block a user