feat(cli): add 'wasp deps' command that lists dependencies used in the project by wasp (#238)

This commit is contained in:
tolarianwiz 2021-05-20 14:05:42 +02:00 committed by Martin Sosic
parent df619ff943
commit f363ed1c24
7 changed files with 52 additions and 3 deletions

View File

@ -0,0 +1,9 @@
module Cli.Terminal
( title,
)
where
import qualified Util.Terminal as Term
title :: String -> String
title = Term.applyStyles [Term.Bold]

View File

@ -9,4 +9,5 @@ data Call
| Build
| Version
| Telemetry
| Deps
| Unknown [String] -- all args

27
waspc/cli/Command/Deps.hs Normal file
View File

@ -0,0 +1,27 @@
module Command.Deps
( deps,
)
where
import Cli.Terminal (title)
import Command (Command)
import Control.Monad.IO.Class (liftIO)
import qualified Generator.ServerGenerator as ServerGenerator
import qualified Generator.WebAppGenerator as WebAppGenerator
import NpmDependency (printDep)
deps :: Command ()
deps =
liftIO $
putStrLn $
unlines $
[ "",
title "Below are listed the dependencies that Wasp uses in your project. You can import and use these directly in the code as if you specified them yourself, but you can't change their versions.",
"",
title "Server dependencies:"
]
++ map printDep ServerGenerator.waspNpmDeps
++ [ "",
title "Webapp dependencies:"
]
++ map printDep WebAppGenerator.waspNpmDeps

View File

@ -1,5 +1,6 @@
module Main where
import Cli.Terminal (title)
import Command (runCommand)
import Command.Build (build)
import qualified Command.Call
@ -8,6 +9,7 @@ import Command.Compile (compile)
import Command.CreateNewProject (createNewProject)
import Command.Db (runDbCommand, studio)
import qualified Command.Db.Migrate
import Command.Deps (deps)
import Command.Start (start)
import qualified Command.Telemetry as Telemetry
import Control.Concurrent (threadDelay)
@ -31,6 +33,7 @@ main = do
["version"] -> Command.Call.Version
["build"] -> Command.Call.Build
["telemetry"] -> Command.Call.Telemetry
["deps"] -> Command.Call.Deps
_ -> Command.Call.Unknown args
telemetryThread <- Async.async $ runCommand $ Telemetry.considerSendingData commandCall
@ -44,6 +47,7 @@ main = do
Command.Call.Version -> printVersion
Command.Call.Build -> runCommand build
Command.Call.Telemetry -> runCommand Telemetry.telemetry
Command.Call.Deps -> runCommand deps
Command.Call.Unknown _ -> printUsage
-- If sending of telemetry data is still not done 1 second since commmand finished, abort it.
@ -71,6 +75,7 @@ printUsage =
cmd " clean Deletes all generated code and other cached artifacts. Wasp equivalent of 'have you tried closing and opening it again?'.",
cmd " build Generates full web app code, ready for deployment. Use when deploying or ejecting.",
cmd " telemetry Prints telemetry status.",
cmd " deps Prints the dependencies that Wasp uses in your project.",
"",
title "EXAMPLES",
" wasp new MyApp",
@ -111,9 +116,6 @@ printDbUsage =
" wasp db studio"
]
title :: String -> String
title = Term.applyStyles [Term.Bold]
cmd :: String -> String
cmd = mapFirstWord (Term.applyStyles [Term.Yellow, Term.Bold])

View File

@ -2,6 +2,7 @@ module Generator.ServerGenerator
( genServer,
preCleanup,
operationsRouteInRootRouter,
waspNpmDeps,
)
where

View File

@ -1,5 +1,6 @@
module Generator.WebAppGenerator
( generateWebApp,
waspNpmDeps,
)
where

View File

@ -1,10 +1,12 @@
module NpmDependency
( NpmDependency (..),
fromList,
printDep,
)
where
import Data.Aeson (ToJSON (..), object, (.=))
import qualified Util.Terminal as Term
data NpmDependency = NpmDependency
{ _name :: !String,
@ -15,6 +17,12 @@ data NpmDependency = NpmDependency
fromList :: [(String, String)] -> [NpmDependency]
fromList = map (\(name, version) -> NpmDependency {_name = name, _version = version})
printDep :: NpmDependency -> String
printDep dep =
Term.applyStyles [Term.Cyan] (_name dep)
++ "@"
++ Term.applyStyles [Term.Yellow] (_version dep)
instance ToJSON NpmDependency where
toJSON npmDep =
object