-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
28 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,38 @@ | ||
module Wasp.Cli.Command.TsConfigSetup (tsConfigSetup) where | ||
|
||
import Control.Concurrent (newChan) | ||
import Control.Concurrent (Chan, newChan) | ||
import Control.Concurrent.Async (concurrently) | ||
import Control.Monad.Except (throwError) | ||
import Control.Monad.IO.Class (liftIO) | ||
import Wasp.Cli.Command (Command, require) | ||
import StrongPath (Abs, Dir, Path') | ||
import System.Exit (ExitCode (..)) | ||
import Wasp.Cli.Command (Command, CommandError (..), require) | ||
import Wasp.Cli.Command.Require (InWaspProject (InWaspProject)) | ||
import Wasp.Generator.NpmInstall (installProjectNpmDependencies) | ||
import qualified Wasp.Generator.Job as J | ||
import Wasp.Generator.Job.IO (readJobMessagesAndPrintThemPrefixed) | ||
import Wasp.Generator.Job.Process (runNodeCommandAsJob) | ||
import Wasp.NodePackageFFI (InstallablePackage (WaspConfigPackage), getPackageInstallationPath) | ||
|
||
-- | Prepares the project for using Wasp's TypeScript SDK. | ||
tsConfigSetup :: Command () | ||
tsConfigSetup = do | ||
InWaspProject waspProjectDir <- require | ||
messageChan <- liftIO newChan | ||
-- TODO: Both of these should be eaiser when Miho finishes the package.json | ||
-- and tsconfig.json validation: | ||
-- - Edit package.json to contain the SDK package | ||
-- - Adapt TSconfigs to fit with the TS SDK project structure | ||
liftIO $ | ||
-- NOTE: We're only installing the user's package.json dependencies here | ||
-- This is to provide proper IDE support for users working with the TS SDK | ||
-- (it needs the `wasp-config` package). | ||
-- Calling this function here shouldn't break anything for later | ||
-- installations. | ||
-- TODO: What about doing this during Wasp start? Can we make Wasp start | ||
-- pick up whether the user wants to use the TS SDK automatically? | ||
installProjectNpmDependencies messageChan waspProjectDir >>= \case | ||
Left e -> putStrLn $ "npm install failed: " ++ show e | ||
Right _ -> return () | ||
-- NOTE: We're also installing the user's package.json dependencies here | ||
-- This is to provide proper IDE support for users working with the TS SDK | ||
-- (it needs the `wasp-config` package). | ||
liftIO (installWaspConfigPackage messageChan waspProjectDir) | ||
>>= onLeftThrowError | ||
where | ||
onLeftThrowError = either (throwError . CommandError "npm install failed") pure | ||
|
||
installWaspConfigPackage :: Chan J.JobMessage -> Path' Abs (Dir a) -> IO (Either String ()) | ||
installWaspConfigPackage chan projectDir = do | ||
installationPath <- getPackageInstallationPath WaspConfigPackage | ||
(_, exitCode) <- | ||
concurrently | ||
(readJobMessagesAndPrintThemPrefixed chan) | ||
(runNodeCommandAsJob projectDir "npm" ["install", "--save-dev", "file:" ++ installationPath] J.Wasp chan) | ||
return $ case exitCode of | ||
ExitSuccess -> Right () | ||
ExitFailure _ -> Left "Failed to install wasp-config package" |