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)
|
|
|
|
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)
|
|
|
|
import Command.Db.Migrate (migrateSave, migrateUp)
|
|
|
|
import Command.Start (start)
|
|
|
|
import qualified Command.Telemetry as Telemetry
|
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
|
|
|
|
_ -> 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
|
|
|
|
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
|
|
|
|
[ "Usage:"
|
|
|
|
, " wasp <command> [command-args]"
|
|
|
|
, ""
|
|
|
|
, "Commands:"
|
|
|
|
, " new <project-name>"
|
|
|
|
, " start"
|
|
|
|
, " clean"
|
2020-09-15 17:39:56 +03:00
|
|
|
, " db <commmand> [command-args]"
|
2021-02-05 16:23:22 +03:00
|
|
|
, " build"
|
2020-10-29 15:15:13 +03:00
|
|
|
, " version"
|
2020-09-07 22:55:13 +03:00
|
|
|
, ""
|
|
|
|
, "Examples:"
|
2020-10-15 19:17:40 +03:00
|
|
|
, " wasp new MyApp"
|
2020-09-07 22:55:13 +03:00
|
|
|
, " wasp start"
|
2020-10-29 15:15:13 +03:00
|
|
|
, " wasp db migrate-save \"init\""
|
|
|
|
, ""
|
|
|
|
, "Documentation is available at https://wasp-lang.dev/docs ."
|
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
|
2020-10-20 12:02:00 +03:00
|
|
|
["migrate-save", migrationName] -> runDbCommand $ migrateSave migrationName
|
|
|
|
["migrate-up"] -> runDbCommand migrateUp
|
2020-11-04 17:26:35 +03:00
|
|
|
["studio"] -> runDbCommand studio
|
2020-09-15 17:39:56 +03:00
|
|
|
_ -> 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
|
|
|
|
[ "Usage:"
|
|
|
|
, " wasp db <command> [command-args]"
|
|
|
|
, ""
|
|
|
|
, "Commands:"
|
|
|
|
, " migrate-save <migration-name>"
|
|
|
|
, " migrate-up"
|
2020-11-04 17:26:35 +03:00
|
|
|
, " studio"
|
2020-09-18 17:14:14 +03:00
|
|
|
, ""
|
|
|
|
, "Examples:"
|
|
|
|
, " wasp db migrate-save \"Added description field.\""
|
|
|
|
, " wasp db migrate-up"
|
|
|
|
]
|