2020-09-07 22:55:13 +03:00
|
|
|
module Main where
|
|
|
|
|
2021-01-23 00:53:36 +03:00
|
|
|
import Control.Concurrent (threadDelay)
|
|
|
|
import qualified Control.Concurrent.Async as Async
|
|
|
|
import Control.Monad (void)
|
2021-04-21 15:06:25 +03:00
|
|
|
import Data.Char (isSpace)
|
2021-01-23 00:53:36 +03:00
|
|
|
import Data.Version (showVersion)
|
|
|
|
import Paths_waspc (version)
|
|
|
|
import System.Environment
|
2020-09-07 22:55:13 +03:00
|
|
|
|
2021-01-23 00:53:36 +03:00
|
|
|
import Command (runCommand)
|
2021-02-05 16:23:22 +03:00
|
|
|
import Command.Build (build)
|
|
|
|
import qualified Command.Call
|
2021-01-23 00:53:36 +03:00
|
|
|
import Command.Clean (clean)
|
|
|
|
import Command.Compile (compile)
|
|
|
|
import Command.CreateNewProject (createNewProject)
|
|
|
|
import Command.Db (runDbCommand, studio)
|
2021-04-21 15:06:25 +03:00
|
|
|
import qualified Command.Db.Migrate
|
2021-01-23 00:53:36 +03:00
|
|
|
import Command.Start (start)
|
|
|
|
import qualified Command.Telemetry as Telemetry
|
2021-02-09 13:19:29 +03:00
|
|
|
import qualified Util.Terminal as Term
|
2020-09-07 22:55:13 +03:00
|
|
|
|
|
|
|
|
|
|
|
main :: IO ()
|
|
|
|
main = do
|
|
|
|
args <- getArgs
|
2021-02-05 16:23:22 +03:00
|
|
|
let commandCall = case args of
|
|
|
|
["new", projectName] -> Command.Call.New projectName
|
|
|
|
["start"] -> Command.Call.Start
|
|
|
|
["clean"] -> Command.Call.Clean
|
|
|
|
["compile"] -> Command.Call.Compile
|
|
|
|
("db":dbArgs) -> Command.Call.Db dbArgs
|
|
|
|
["version"] -> Command.Call.Version
|
|
|
|
["build"] -> Command.Call.Build
|
2021-02-22 20:32:04 +03:00
|
|
|
["telemetry"] -> Command.Call.Telemetry
|
2021-02-05 16:23:22 +03:00
|
|
|
_ -> Command.Call.Unknown args
|
|
|
|
|
|
|
|
telemetryThread <- Async.async $ runCommand $ Telemetry.considerSendingData commandCall
|
|
|
|
|
|
|
|
case commandCall of
|
|
|
|
Command.Call.New projectName -> runCommand $ createNewProject projectName
|
|
|
|
Command.Call.Start -> runCommand start
|
|
|
|
Command.Call.Clean -> runCommand clean
|
|
|
|
Command.Call.Compile -> runCommand compile
|
|
|
|
Command.Call.Db dbArgs -> dbCli dbArgs
|
|
|
|
Command.Call.Version -> printVersion
|
|
|
|
Command.Call.Build -> runCommand build
|
2021-02-22 20:32:04 +03:00
|
|
|
Command.Call.Telemetry -> runCommand Telemetry.telemetry
|
2021-02-05 16:23:22 +03:00
|
|
|
Command.Call.Unknown _ -> printUsage
|
2021-01-23 00:53:36 +03:00
|
|
|
|
|
|
|
-- If sending of telemetry data is still not done 1 second since commmand finished, abort it.
|
|
|
|
-- We also make sure here to catch all errors that might get thrown and silence them.
|
|
|
|
void $ Async.race (threadDelaySeconds 1) (Async.waitCatch telemetryThread)
|
|
|
|
where
|
|
|
|
threadDelaySeconds = let microsecondsInASecond = 1000000
|
|
|
|
in threadDelay . (* microsecondsInASecond)
|
2020-09-07 22:55:13 +03:00
|
|
|
|
|
|
|
printUsage :: IO ()
|
|
|
|
printUsage = putStrLn $ unlines
|
2021-02-09 13:19:29 +03:00
|
|
|
[ title "USAGE"
|
|
|
|
, " wasp <command> [command-args]"
|
|
|
|
, ""
|
|
|
|
, title "COMMANDS"
|
|
|
|
, title " GENERAL"
|
|
|
|
, cmd " new <project-name> Creates new Wasp project."
|
|
|
|
, cmd " version Prints current version of CLI."
|
|
|
|
, title " IN PROJECT"
|
|
|
|
, cmd " start Runs Wasp app in development mode, watching for file changes."
|
|
|
|
, cmd " db <db-cmd> [args] Executes a database command. Run 'wasp db' for more info."
|
|
|
|
, 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."
|
2021-02-22 20:32:04 +03:00
|
|
|
, cmd " telemetry Prints telemetry status."
|
2021-02-09 13:19:29 +03:00
|
|
|
, ""
|
|
|
|
, title "EXAMPLES"
|
|
|
|
, " wasp new MyApp"
|
|
|
|
, " wasp start"
|
2021-04-21 15:06:25 +03:00
|
|
|
, " wasp db migrate-dev"
|
2021-02-09 13:19:29 +03:00
|
|
|
, ""
|
|
|
|
, Term.applyStyles [Term.Green] "Docs:" ++ " https://wasp-lang.dev/docs"
|
|
|
|
, Term.applyStyles [Term.Magenta] "Discord (chat):" ++ " https://discord.gg/rzdnErX"
|
2020-09-07 22:55:13 +03:00
|
|
|
]
|
|
|
|
|
2020-10-29 15:15:13 +03:00
|
|
|
printVersion :: IO ()
|
|
|
|
printVersion = putStrLn $ showVersion version
|
|
|
|
|
2020-09-15 17:39:56 +03:00
|
|
|
-- TODO(matija): maybe extract to a separate module, e.g. DbCli.hs?
|
|
|
|
dbCli :: [String] -> IO ()
|
|
|
|
dbCli args = case args of
|
2021-04-21 15:06:25 +03:00
|
|
|
["migrate-dev"] -> runDbCommand Command.Db.Migrate.migrateDev
|
|
|
|
["studio"] -> runDbCommand studio
|
|
|
|
_ -> printDbUsage
|
2020-09-07 22:55:13 +03:00
|
|
|
|
2020-09-15 17:39:56 +03:00
|
|
|
printDbUsage :: IO ()
|
2020-09-18 17:14:14 +03:00
|
|
|
printDbUsage = putStrLn $ unlines
|
2021-02-09 13:19:29 +03:00
|
|
|
[ title "USAGE"
|
|
|
|
, " wasp db <command> [command-args]"
|
|
|
|
, ""
|
|
|
|
, title "COMMANDS"
|
2021-04-21 15:06:25 +03:00
|
|
|
, cmd (
|
|
|
|
" migrate-dev Ensures dev database corresponds to the current state of schema(entities):\n" <>
|
|
|
|
" - Generates a new migration if there are changes in the schema.\n" <>
|
|
|
|
" - Applies any pending migrations to the database."
|
|
|
|
)
|
|
|
|
, cmd " studio GUI for inspecting your database."
|
2021-02-09 13:19:29 +03:00
|
|
|
, ""
|
|
|
|
, title "EXAMPLES"
|
2021-04-21 15:06:25 +03:00
|
|
|
, " wasp db migrate-dev"
|
|
|
|
, " wasp db studio"
|
2020-09-18 17:14:14 +03:00
|
|
|
]
|
2021-02-09 13:19:29 +03:00
|
|
|
|
|
|
|
title :: String -> String
|
|
|
|
title = Term.applyStyles [Term.Bold]
|
|
|
|
|
|
|
|
cmd :: String -> String
|
|
|
|
cmd = mapFirstWord (Term.applyStyles [Term.Yellow, Term.Bold])
|
|
|
|
|
|
|
|
mapFirstWord :: (String -> String) -> String -> String
|
|
|
|
mapFirstWord f s = beforeFirstWord ++ f firstWord ++ afterFirstWord
|
|
|
|
where
|
|
|
|
(beforeFirstWord, firstWordAndAfter) = span isSpace s
|
|
|
|
(firstWord, afterFirstWord) = break isSpace firstWordAndAfter
|