mirror of
https://github.com/wasp-lang/wasp.git
synced 2024-12-27 02:52:22 +03:00
Adapt Prisma for the new structure (#1604)
This commit is contained in:
parent
d3e9fdc4c6
commit
df5a1358e6
@ -16,13 +16,19 @@ import Wasp.Cli.Command (Command, CommandError (..))
|
||||
import Wasp.Cli.Command.Compile (compileIOWithOptions, printCompilationResult)
|
||||
import Wasp.Cli.Command.Message (cliSendMessageC)
|
||||
import Wasp.Cli.Command.Require (InWaspProject (InWaspProject), require)
|
||||
import qualified Wasp.Cli.Common as Common
|
||||
import Wasp.Cli.Message (cliSendMessage)
|
||||
import Wasp.CompileOptions (CompileOptions (..))
|
||||
import qualified Wasp.Generator
|
||||
import Wasp.Generator.Monad (GeneratorWarning (GeneratorNeedsMigrationWarning))
|
||||
import qualified Wasp.Message as Msg
|
||||
import Wasp.Project (CompileError, CompileWarning)
|
||||
import Wasp.Project (CompileError, CompileWarning, WaspProjectDir)
|
||||
import Wasp.Project.Common
|
||||
( buildDirInDotWaspDir,
|
||||
dotWaspDirInWaspProjectDir,
|
||||
extClientCodeDirInWaspProjectDir,
|
||||
extServerCodeDirInWaspProjectDir,
|
||||
extSharedCodeDirInWaspProjectDir,
|
||||
)
|
||||
|
||||
-- | Builds Wasp project that the current working directory is part of.
|
||||
-- Does all the steps, from analysis to generation, and at the end writes generated code
|
||||
@ -35,8 +41,8 @@ build :: Command ()
|
||||
build = do
|
||||
InWaspProject waspProjectDir <- require
|
||||
let buildDir =
|
||||
waspProjectDir </> Common.dotWaspDirInWaspProjectDir
|
||||
</> Common.buildDirInDotWaspDir
|
||||
waspProjectDir </> dotWaspDirInWaspProjectDir
|
||||
</> buildDirInDotWaspDir
|
||||
buildDirFilePath = SP.fromAbsDir buildDir
|
||||
|
||||
doesBuildDirExist <- liftIO $ doesDirectoryExist buildDirFilePath
|
||||
@ -58,16 +64,16 @@ build = do
|
||||
CommandError "Building of wasp project failed" $ show (length errors) ++ " errors found"
|
||||
|
||||
buildIO ::
|
||||
Path' Abs (Dir Common.WaspProjectDir) ->
|
||||
Path' Abs (Dir WaspProjectDir) ->
|
||||
Path' Abs (Dir Wasp.Generator.ProjectRootDir) ->
|
||||
IO ([CompileWarning], [CompileError])
|
||||
buildIO waspProjectDir buildDir = compileIOWithOptions options waspProjectDir buildDir
|
||||
where
|
||||
options =
|
||||
CompileOptions
|
||||
{ externalClientCodeDirPath = waspProjectDir </> Common.extClientCodeDirInWaspProjectDir,
|
||||
externalServerCodeDirPath = waspProjectDir </> Common.extServerCodeDirInWaspProjectDir,
|
||||
externalSharedCodeDirPath = waspProjectDir </> Common.extSharedCodeDirInWaspProjectDir,
|
||||
{ externalClientCodeDirPath = waspProjectDir </> extClientCodeDirInWaspProjectDir,
|
||||
externalServerCodeDirPath = waspProjectDir </> extServerCodeDirInWaspProjectDir,
|
||||
externalSharedCodeDirPath = waspProjectDir </> extSharedCodeDirInWaspProjectDir,
|
||||
isBuild = True,
|
||||
sendMessage = cliSendMessage,
|
||||
-- Ignore "DB needs migration warnings" during build, as that is not a required step.
|
||||
|
@ -12,13 +12,13 @@ import System.Directory
|
||||
import Wasp.Cli.Command (Command)
|
||||
import Wasp.Cli.Command.Message (cliSendMessageC)
|
||||
import Wasp.Cli.Command.Require (InWaspProject (InWaspProject), require)
|
||||
import qualified Wasp.Cli.Common as Common
|
||||
import qualified Wasp.Message as Msg
|
||||
import Wasp.Project.Common (dotWaspDirInWaspProjectDir)
|
||||
|
||||
clean :: Command ()
|
||||
clean = do
|
||||
InWaspProject waspProjectDir <- require
|
||||
let dotWaspDirFp = SP.toFilePath $ waspProjectDir SP.</> Common.dotWaspDirInWaspProjectDir
|
||||
let dotWaspDirFp = SP.toFilePath $ waspProjectDir SP.</> dotWaspDirInWaspProjectDir
|
||||
cliSendMessageC $ Msg.Start "Deleting .wasp/ directory..."
|
||||
doesDotWaspDirExist <- liftIO $ doesDirectoryExist dotWaspDirFp
|
||||
if doesDotWaspDirExist
|
||||
|
@ -10,8 +10,8 @@ import StrongPath (Abs, Dir, Path')
|
||||
import StrongPath.Operations
|
||||
import System.Directory (findExecutable)
|
||||
import Wasp.Cli.Command (Command, CommandError (..))
|
||||
import qualified Wasp.Cli.Common as Cli.Common
|
||||
import Wasp.Project (WaspProjectDir)
|
||||
import qualified Wasp.Project.Common as Project.Common
|
||||
import Wasp.Util (ifM)
|
||||
import qualified Wasp.Util.IO as IOUtil
|
||||
|
||||
@ -23,9 +23,9 @@ readWaspCompileInfo waspDir =
|
||||
(return "No compile information found")
|
||||
where
|
||||
dotWaspInfoFile =
|
||||
waspDir </> Cli.Common.dotWaspDirInWaspProjectDir
|
||||
</> Cli.Common.generatedCodeDirInDotWaspDir
|
||||
</> Cli.Common.dotWaspInfoFileInGeneratedCodeDir
|
||||
waspDir </> Project.Common.dotWaspDirInWaspProjectDir
|
||||
</> Project.Common.generatedCodeDirInDotWaspDir
|
||||
</> Project.Common.dotWaspInfoFileInGeneratedCodeDir
|
||||
|
||||
throwIfExeIsNotAvailable :: String -> String -> Command ()
|
||||
throwIfExeIsNotAvailable exeName explanationMsg = do
|
||||
|
@ -20,13 +20,13 @@ import qualified Wasp.AppSpec as AS
|
||||
import Wasp.Cli.Command (Command, CommandError (..))
|
||||
import Wasp.Cli.Command.Message (cliSendMessageC)
|
||||
import Wasp.Cli.Command.Require (InWaspProject (InWaspProject), require)
|
||||
import qualified Wasp.Cli.Common as Common
|
||||
import Wasp.Cli.Message (cliSendMessage)
|
||||
import Wasp.CompileOptions (CompileOptions (..))
|
||||
import qualified Wasp.Generator
|
||||
import qualified Wasp.Message as Msg
|
||||
import Wasp.Project (CompileError, CompileWarning, WaspProjectDir)
|
||||
import qualified Wasp.Project
|
||||
import Wasp.Project.Common (dotWaspDirInWaspProjectDir, extClientCodeDirInWaspProjectDir, extServerCodeDirInWaspProjectDir, extSharedCodeDirInWaspProjectDir, generatedCodeDirInDotWaspDir)
|
||||
|
||||
-- | Same like 'compileWithOptions', but with default compile options.
|
||||
compile :: Command [CompileWarning]
|
||||
@ -47,8 +47,8 @@ compileWithOptions :: CompileOptions -> Command [CompileWarning]
|
||||
compileWithOptions options = do
|
||||
InWaspProject waspProjectDir <- require
|
||||
let outDir =
|
||||
waspProjectDir </> Common.dotWaspDirInWaspProjectDir
|
||||
</> Common.generatedCodeDirInDotWaspDir
|
||||
waspProjectDir </> dotWaspDirInWaspProjectDir
|
||||
</> generatedCodeDirInDotWaspDir
|
||||
|
||||
cliSendMessageC $ Msg.Start "Compiling wasp project..."
|
||||
(warnings, errors) <- liftIO $ compileIOWithOptions options waspProjectDir outDir
|
||||
@ -115,9 +115,9 @@ compileIOWithOptions options waspProjectDir outDir =
|
||||
defaultCompileOptions :: Path' Abs (Dir WaspProjectDir) -> CompileOptions
|
||||
defaultCompileOptions waspProjectDir =
|
||||
CompileOptions
|
||||
{ externalServerCodeDirPath = waspProjectDir </> Common.extServerCodeDirInWaspProjectDir,
|
||||
externalClientCodeDirPath = waspProjectDir </> Common.extClientCodeDirInWaspProjectDir,
|
||||
externalSharedCodeDirPath = waspProjectDir </> Common.extSharedCodeDirInWaspProjectDir,
|
||||
{ externalServerCodeDirPath = waspProjectDir </> extServerCodeDirInWaspProjectDir,
|
||||
externalClientCodeDirPath = waspProjectDir </> extClientCodeDirInWaspProjectDir,
|
||||
externalSharedCodeDirPath = waspProjectDir </> extSharedCodeDirInWaspProjectDir,
|
||||
isBuild = False,
|
||||
sendMessage = cliSendMessage,
|
||||
generatorWarningsFilter = id
|
||||
|
@ -39,8 +39,8 @@ import Wasp.Cli.Command.CreateNewProject.ProjectDescription
|
||||
parseWaspProjectNameIntoAppName,
|
||||
)
|
||||
import Wasp.Cli.Command.CreateNewProject.StarterTemplates (readWaspProjectSkeletonFiles)
|
||||
import Wasp.Cli.Common (WaspProjectDir)
|
||||
import qualified Wasp.Cli.Interactive as Interactive
|
||||
import Wasp.Project.Common (WaspProjectDir)
|
||||
import qualified Wasp.Util as U
|
||||
import qualified Wasp.Util.Aeson as Utils.Aeson
|
||||
import qualified Wasp.Util.Terminal as T
|
||||
|
@ -15,10 +15,10 @@ import Data.Foldable (find)
|
||||
import Data.Text (Text)
|
||||
import StrongPath (Dir', File', Path, Path', Rel, Rel', System, reldir, (</>))
|
||||
import qualified System.FilePath as FP
|
||||
import Wasp.Cli.Common (WaspProjectDir)
|
||||
import qualified Wasp.Cli.GithubRepo as GhRepo
|
||||
import qualified Wasp.Cli.Interactive as Interactive
|
||||
import qualified Wasp.Data as Data
|
||||
import Wasp.Project.Common (WaspProjectDir)
|
||||
import Wasp.Util.IO (listDirectoryDeep, readFileStrict)
|
||||
import qualified Wasp.Util.Terminal as Term
|
||||
|
||||
|
@ -10,11 +10,11 @@ import StrongPath (Abs, Dir, Path', (</>))
|
||||
import Wasp.Cli.Command (Command, CommandError (..))
|
||||
import Wasp.Cli.Command.Message (cliSendMessageC)
|
||||
import Wasp.Cli.Command.Require (InWaspProject (InWaspProject), require)
|
||||
import qualified Wasp.Cli.Common as Cli.Common
|
||||
import Wasp.Generator.Common (ProjectRootDir)
|
||||
import Wasp.Generator.DbGenerator.Common (MigrateArgs (..), defaultMigrateArgs)
|
||||
import qualified Wasp.Generator.DbGenerator.Operations as DbOps
|
||||
import qualified Wasp.Message as Msg
|
||||
import Wasp.Project.Common (dotWaspDirInWaspProjectDir, generatedCodeDirInDotWaspDir)
|
||||
import Wasp.Project.Db.Migrations (DbMigrationsDir, dbMigrationsDirInWaspProjectDir)
|
||||
|
||||
-- | NOTE(shayne): Performs database schema migration (based on current schema) in the generated project.
|
||||
@ -26,8 +26,8 @@ migrateDev optionalMigrateArgs = do
|
||||
let waspDbMigrationsDir = waspProjectDir </> dbMigrationsDirInWaspProjectDir
|
||||
let projectRootDir =
|
||||
waspProjectDir
|
||||
</> Cli.Common.dotWaspDirInWaspProjectDir
|
||||
</> Cli.Common.generatedCodeDirInDotWaspDir
|
||||
</> dotWaspDirInWaspProjectDir
|
||||
</> generatedCodeDirInDotWaspDir
|
||||
|
||||
migrateDatabase optionalMigrateArgs projectRootDir waspDbMigrationsDir
|
||||
|
||||
|
@ -8,15 +8,15 @@ import StrongPath ((</>))
|
||||
import Wasp.Cli.Command (Command)
|
||||
import Wasp.Cli.Command.Message (cliSendMessageC)
|
||||
import Wasp.Cli.Command.Require (InWaspProject (InWaspProject), require)
|
||||
import qualified Wasp.Cli.Common as Common
|
||||
import Wasp.Generator.DbGenerator.Operations (dbReset)
|
||||
import qualified Wasp.Message as Msg
|
||||
import Wasp.Project.Common (dotWaspDirInWaspProjectDir, generatedCodeDirInDotWaspDir)
|
||||
|
||||
reset :: Command ()
|
||||
reset = do
|
||||
InWaspProject waspProjectDir <- require
|
||||
let genProjectDir =
|
||||
waspProjectDir </> Common.dotWaspDirInWaspProjectDir </> Common.generatedCodeDirInDotWaspDir
|
||||
waspProjectDir </> dotWaspDirInWaspProjectDir </> generatedCodeDirInDotWaspDir
|
||||
|
||||
cliSendMessageC $ Msg.Start "Resetting the database..."
|
||||
|
||||
|
@ -19,15 +19,15 @@ import Wasp.Cli.Command (Command, CommandError (CommandError))
|
||||
import Wasp.Cli.Command.Compile (analyze)
|
||||
import Wasp.Cli.Command.Message (cliSendMessageC)
|
||||
import Wasp.Cli.Command.Require (InWaspProject (InWaspProject), require)
|
||||
import qualified Wasp.Cli.Common as Common
|
||||
import Wasp.Generator.DbGenerator.Operations (dbSeed)
|
||||
import qualified Wasp.Message as Msg
|
||||
import Wasp.Project.Common (dotWaspDirInWaspProjectDir, generatedCodeDirInDotWaspDir)
|
||||
|
||||
seed :: Maybe String -> Command ()
|
||||
seed maybeUserProvidedSeedName = do
|
||||
InWaspProject waspProjectDir <- require
|
||||
let genProjectDir =
|
||||
waspProjectDir </> Common.dotWaspDirInWaspProjectDir </> Common.generatedCodeDirInDotWaspDir
|
||||
waspProjectDir </> dotWaspDirInWaspProjectDir </> generatedCodeDirInDotWaspDir
|
||||
|
||||
appSpec <- analyze waspProjectDir
|
||||
|
||||
|
@ -10,16 +10,16 @@ import StrongPath ((</>))
|
||||
import Wasp.Cli.Command (Command)
|
||||
import Wasp.Cli.Command.Message (cliSendMessageC)
|
||||
import Wasp.Cli.Command.Require (InWaspProject (InWaspProject), require)
|
||||
import qualified Wasp.Cli.Common as Common
|
||||
import Wasp.Generator.DbGenerator.Jobs (runStudio)
|
||||
import Wasp.Generator.Job.IO (readJobMessagesAndPrintThemPrefixed)
|
||||
import qualified Wasp.Message as Msg
|
||||
import Wasp.Project.Common (dotWaspDirInWaspProjectDir, generatedCodeDirInDotWaspDir)
|
||||
|
||||
studio :: Command ()
|
||||
studio = do
|
||||
InWaspProject waspProjectDir <- require
|
||||
let genProjectDir =
|
||||
waspProjectDir </> Common.dotWaspDirInWaspProjectDir </> Common.generatedCodeDirInDotWaspDir
|
||||
waspProjectDir </> dotWaspDirInWaspProjectDir </> generatedCodeDirInDotWaspDir
|
||||
|
||||
cliSendMessageC $ Msg.Start "Running studio..."
|
||||
|
||||
|
@ -37,9 +37,9 @@ import qualified StrongPath as SP
|
||||
import System.Directory (doesFileExist, doesPathExist, getCurrentDirectory)
|
||||
import qualified System.FilePath as FP
|
||||
import Wasp.Cli.Command (CommandError (CommandError), Requirable (checkRequirement), require)
|
||||
import Wasp.Cli.Common (WaspProjectDir)
|
||||
import qualified Wasp.Cli.Common as Cli.Common
|
||||
import Wasp.Generator.DbGenerator.Operations (isDbConnectionPossible, testDbConnection)
|
||||
import Wasp.Project.Common (WaspProjectDir)
|
||||
import qualified Wasp.Project.Common as Project.Common
|
||||
|
||||
data DbConnectionEstablished = DbConnectionEstablished deriving (Typeable)
|
||||
|
||||
@ -48,7 +48,10 @@ instance Requirable DbConnectionEstablished where
|
||||
-- NOTE: 'InWaspProject' does not depend on this requirement, so this
|
||||
-- call to 'require' will not result in an infinite loop.
|
||||
InWaspProject waspProjectDir <- require
|
||||
let outDir = waspProjectDir SP.</> Cli.Common.dotWaspDirInWaspProjectDir SP.</> Cli.Common.generatedCodeDirInDotWaspDir
|
||||
let outDir =
|
||||
waspProjectDir
|
||||
SP.</> Project.Common.dotWaspDirInWaspProjectDir
|
||||
SP.</> Project.Common.generatedCodeDirInDotWaspDir
|
||||
dbIsRunning <- liftIO $ isDbConnectionPossible <$> testDbConnection outDir
|
||||
|
||||
if dbIsRunning
|
||||
@ -82,7 +85,7 @@ instance Requirable InWaspProject where
|
||||
let absCurrentDirFp = SP.fromAbsDir currentDir
|
||||
doesCurrentDirExist <- liftIO $ doesPathExist absCurrentDirFp
|
||||
unless doesCurrentDirExist (throwError notFoundError)
|
||||
let dotWaspRootFilePath = absCurrentDirFp FP.</> SP.fromRelFile Cli.Common.dotWaspRootFileInWaspProjectDir
|
||||
let dotWaspRootFilePath = absCurrentDirFp FP.</> SP.fromRelFile Project.Common.dotWaspRootFileInWaspProjectDir
|
||||
isCurrentDirRoot <- liftIO $ doesFileExist dotWaspRootFilePath
|
||||
if isCurrentDirRoot
|
||||
then return $ InWaspProject $ SP.castDir currentDir
|
||||
|
@ -14,17 +14,17 @@ import Wasp.Cli.Command.Compile (compile, printWarningsAndErrorsIfAny)
|
||||
import Wasp.Cli.Command.Message (cliSendMessageC)
|
||||
import Wasp.Cli.Command.Require (DbConnectionEstablished (DbConnectionEstablished), InWaspProject (InWaspProject), require)
|
||||
import Wasp.Cli.Command.Watch (watch)
|
||||
import qualified Wasp.Cli.Common as Common
|
||||
import qualified Wasp.Generator
|
||||
import qualified Wasp.Message as Msg
|
||||
import Wasp.Project (CompileError, CompileWarning)
|
||||
import Wasp.Project.Common (dotWaspDirInWaspProjectDir, generatedCodeDirInDotWaspDir)
|
||||
|
||||
-- | Does initial compile of wasp code and then runs the generated project.
|
||||
-- It also listens for any file changes and recompiles and restarts generated project accordingly.
|
||||
start :: Command ()
|
||||
start = do
|
||||
InWaspProject waspRoot <- require
|
||||
let outDir = waspRoot </> Common.dotWaspDirInWaspProjectDir </> Common.generatedCodeDirInDotWaspDir
|
||||
let outDir = waspRoot </> dotWaspDirInWaspProjectDir </> generatedCodeDirInDotWaspDir
|
||||
|
||||
cliSendMessageC $ Msg.Start "Starting compilation and setup phase. Hold tight..."
|
||||
|
||||
|
@ -22,8 +22,8 @@ import Wasp.Cli.Command.Common (throwIfExeIsNotAvailable)
|
||||
import Wasp.Cli.Command.Compile (analyze)
|
||||
import Wasp.Cli.Command.Message (cliSendMessageC)
|
||||
import Wasp.Cli.Command.Require (InWaspProject (InWaspProject), require)
|
||||
import Wasp.Cli.Common (WaspProjectDir)
|
||||
import qualified Wasp.Message as Msg
|
||||
import Wasp.Project.Common (WaspProjectDir)
|
||||
import Wasp.Project.Db (databaseUrlEnvVarName)
|
||||
import Wasp.Project.Db.Dev (makeDevDbUniqueId)
|
||||
import qualified Wasp.Project.Db.Dev.Postgres as Dev.Postgres
|
||||
|
@ -29,8 +29,8 @@ import Wasp.Cli.Command (Command, CommandError (CommandError))
|
||||
import Wasp.Cli.Command.Compile (analyze)
|
||||
import Wasp.Cli.Command.Message (cliSendMessageC)
|
||||
import Wasp.Cli.Command.Require (InWaspProject (InWaspProject), require)
|
||||
import qualified Wasp.Cli.Common as Common
|
||||
import qualified Wasp.Message as Msg
|
||||
import Wasp.Project.Common (dotWaspDirInWaspProjectDir, generatedCodeDirInDotWaspDir)
|
||||
import qualified Wasp.Project.Studio
|
||||
|
||||
studio :: Command ()
|
||||
@ -123,8 +123,8 @@ studio = do
|
||||
]
|
||||
|
||||
let generatedProjectDir =
|
||||
waspDir </> Common.dotWaspDirInWaspProjectDir
|
||||
</> Common.generatedCodeDirInDotWaspDir
|
||||
waspDir </> dotWaspDirInWaspProjectDir
|
||||
</> generatedCodeDirInDotWaspDir
|
||||
|
||||
let waspStudioDataJsonFilePath = generatedProjectDir </> [relfile|.wasp-studio-data.json|]
|
||||
liftIO $ do
|
||||
|
@ -14,10 +14,10 @@ import Wasp.Cli.Command.Compile (compile)
|
||||
import Wasp.Cli.Command.Message (cliSendMessageC)
|
||||
import Wasp.Cli.Command.Require (InWaspProject (InWaspProject), require)
|
||||
import Wasp.Cli.Command.Watch (watch)
|
||||
import qualified Wasp.Cli.Common as Common
|
||||
import qualified Wasp.Generator
|
||||
import Wasp.Generator.Common (ProjectRootDir)
|
||||
import qualified Wasp.Message as Msg
|
||||
import Wasp.Project.Common (dotWaspDirInWaspProjectDir, generatedCodeDirInDotWaspDir)
|
||||
|
||||
test :: [String] -> Command ()
|
||||
test [] = throwError $ CommandError "Not enough arguments" "Expected: wasp test client <args>"
|
||||
@ -28,7 +28,7 @@ test _ = throwError $ CommandError "Invalid arguments" "Expected: wasp test clie
|
||||
watchAndTest :: (Path' Abs (Dir ProjectRootDir) -> IO (Either String ())) -> Command ()
|
||||
watchAndTest testRunner = do
|
||||
InWaspProject waspRoot <- require
|
||||
let outDir = waspRoot </> Common.dotWaspDirInWaspProjectDir </> Common.generatedCodeDirInDotWaspDir
|
||||
let outDir = waspRoot </> dotWaspDirInWaspProjectDir </> generatedCodeDirInDotWaspDir
|
||||
|
||||
cliSendMessageC $ Msg.Start "Starting compilation and setup phase. Hold tight..."
|
||||
|
||||
|
@ -15,11 +15,11 @@ import qualified StrongPath as SP
|
||||
import qualified System.FSNotify as FSN
|
||||
import qualified System.FilePath as FP
|
||||
import Wasp.Cli.Command.Compile (compileIO, printCompilationResult)
|
||||
import qualified Wasp.Cli.Common as Common
|
||||
import Wasp.Cli.Message (cliSendMessage)
|
||||
import qualified Wasp.Generator.Common as Wasp.Generator
|
||||
import qualified Wasp.Message as Msg
|
||||
import Wasp.Project (CompileError, CompileWarning, WaspProjectDir)
|
||||
import Wasp.Project.Common (extClientCodeDirInWaspProjectDir, extServerCodeDirInWaspProjectDir, extSharedCodeDirInWaspProjectDir)
|
||||
|
||||
-- TODO: Idea: Read .gitignore file, and ignore everything from it. This will then also cover the
|
||||
-- .wasp dir, and users can easily add any custom stuff they want ignored. But, we also have to
|
||||
@ -41,9 +41,9 @@ watch waspProjectDir outDir ongoingCompilationResultMVar = FSN.withManager $ \mg
|
||||
chan <- newChan
|
||||
_ <- FSN.watchDirChan mgr (SP.fromAbsDir waspProjectDir) eventFilter chan
|
||||
let watchProjectSubdirTree path = FSN.watchTreeChan mgr (SP.fromAbsDir $ waspProjectDir </> path) eventFilter chan
|
||||
_ <- watchProjectSubdirTree Common.extClientCodeDirInWaspProjectDir
|
||||
_ <- watchProjectSubdirTree Common.extServerCodeDirInWaspProjectDir
|
||||
_ <- watchProjectSubdirTree Common.extSharedCodeDirInWaspProjectDir
|
||||
_ <- watchProjectSubdirTree extClientCodeDirInWaspProjectDir
|
||||
_ <- watchProjectSubdirTree extServerCodeDirInWaspProjectDir
|
||||
_ <- watchProjectSubdirTree extSharedCodeDirInWaspProjectDir
|
||||
listenForEvents chan currentTime
|
||||
where
|
||||
listenForEvents :: Chan FSN.Event -> UTCTime -> IO ()
|
||||
|
@ -1,57 +1,15 @@
|
||||
module Wasp.Cli.Common
|
||||
( WaspProjectDir,
|
||||
DotWaspDir,
|
||||
CliTemplatesDir,
|
||||
dotWaspDirInWaspProjectDir,
|
||||
dotWaspRootFileInWaspProjectDir,
|
||||
dotWaspInfoFileInGeneratedCodeDir,
|
||||
extServerCodeDirInWaspProjectDir,
|
||||
extClientCodeDirInWaspProjectDir,
|
||||
extSharedCodeDirInWaspProjectDir,
|
||||
generatedCodeDirInDotWaspDir,
|
||||
buildDirInDotWaspDir,
|
||||
( CliTemplatesDir,
|
||||
waspSays,
|
||||
waspWarns,
|
||||
waspScreams,
|
||||
)
|
||||
where
|
||||
|
||||
import StrongPath (Dir, File', Path', Rel, reldir, relfile)
|
||||
import Wasp.AppSpec.ExternalCode (SourceExternalCodeDir)
|
||||
import qualified Wasp.Generator.Common
|
||||
import Wasp.Project (WaspProjectDir)
|
||||
import qualified Wasp.Util.Terminal as Term
|
||||
|
||||
data DotWaspDir -- Here we put everything that wasp generates.
|
||||
|
||||
data CliTemplatesDir
|
||||
|
||||
-- TODO: SHould this be renamed to include word "root"?
|
||||
dotWaspDirInWaspProjectDir :: Path' (Rel WaspProjectDir) (Dir DotWaspDir)
|
||||
dotWaspDirInWaspProjectDir = [reldir|.wasp|]
|
||||
|
||||
-- TODO: Hm this has different name than it has in Generator.
|
||||
generatedCodeDirInDotWaspDir :: Path' (Rel DotWaspDir) (Dir Wasp.Generator.Common.ProjectRootDir)
|
||||
generatedCodeDirInDotWaspDir = [reldir|out|]
|
||||
|
||||
buildDirInDotWaspDir :: Path' (Rel DotWaspDir) (Dir Wasp.Generator.Common.ProjectRootDir)
|
||||
buildDirInDotWaspDir = [reldir|build|]
|
||||
|
||||
dotWaspRootFileInWaspProjectDir :: Path' (Rel WaspProjectDir) File'
|
||||
dotWaspRootFileInWaspProjectDir = [relfile|.wasproot|]
|
||||
|
||||
dotWaspInfoFileInGeneratedCodeDir :: Path' (Rel Wasp.Generator.Common.ProjectRootDir) File'
|
||||
dotWaspInfoFileInGeneratedCodeDir = [relfile|.waspinfo|]
|
||||
|
||||
extServerCodeDirInWaspProjectDir :: Path' (Rel WaspProjectDir) (Dir SourceExternalCodeDir)
|
||||
extServerCodeDirInWaspProjectDir = [reldir|src|]
|
||||
|
||||
extClientCodeDirInWaspProjectDir :: Path' (Rel WaspProjectDir) (Dir SourceExternalCodeDir)
|
||||
extClientCodeDirInWaspProjectDir = [reldir|src|]
|
||||
|
||||
extSharedCodeDirInWaspProjectDir :: Path' (Rel WaspProjectDir) (Dir SourceExternalCodeDir)
|
||||
extSharedCodeDirInWaspProjectDir = [reldir|src|]
|
||||
|
||||
waspSays :: String -> IO ()
|
||||
waspSays what = putStrLn $ Term.applyStyles [Term.Yellow] what
|
||||
|
||||
|
@ -17,5 +17,5 @@
|
||||
"https://github.com/wasp-lang/wasp/pull/634#issuecomment-1158802302 ."
|
||||
]
|
||||
}
|
||||
],
|
||||
]
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ COPY server/ ./server/
|
||||
RUN cd server && npm install
|
||||
{=# usingPrisma =}
|
||||
COPY db/schema.prisma ./db/
|
||||
RUN cd server && {= serverPrismaClientOutputDirEnv =} npx prisma generate --schema='{= dbSchemaFileFromServerDir =}'
|
||||
RUN cd server && npx prisma generate --schema='{= dbSchemaFileFromServerDir =}'
|
||||
{=/ usingPrisma =}
|
||||
# Building the server should come after Prisma generation.
|
||||
RUN cd server && npm run build
|
||||
|
@ -10,7 +10,6 @@ datasource db {
|
||||
|
||||
generator client {
|
||||
provider = "prisma-client-js"
|
||||
output = {=& prismaClientOutputDir =}
|
||||
{=# prismaPreviewFeatures =}
|
||||
previewFeatures = {=& . =}
|
||||
{=/ prismaPreviewFeatures =}
|
||||
|
@ -2,7 +2,6 @@
|
||||
"name": "prototype",
|
||||
"dependencies": {
|
||||
"wasp": "file:.wasp/out/sdk/wasp",
|
||||
"@prisma/client": "4.16.2",
|
||||
"react": "^18.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
@ -30,7 +30,6 @@ import Wasp.Generator.DbGenerator.Common
|
||||
dbSchemaFileInDbTemplatesDir,
|
||||
dbSchemaFileInProjectRootDir,
|
||||
dbTemplatesDirInTemplatesDir,
|
||||
prismaClientOutputDirEnvVar,
|
||||
)
|
||||
import qualified Wasp.Generator.DbGenerator.Operations as DbOps
|
||||
import Wasp.Generator.FileDraft (FileDraft, createCopyDirFileDraft, createTemplateFileDraft)
|
||||
@ -71,7 +70,6 @@ genPrismaSchema spec = do
|
||||
[ "modelSchemas" .= map entityToPslModelSchema entities,
|
||||
"datasourceProvider" .= datasourceProvider,
|
||||
"datasourceUrl" .= datasourceUrl,
|
||||
"prismaClientOutputDir" .= makeEnvVarField Wasp.Generator.DbGenerator.Common.prismaClientOutputDirEnvVar,
|
||||
"prismaPreviewFeatures" .= prismaPreviewFeatures,
|
||||
"dbExtensions" .= dbExtensions
|
||||
]
|
||||
@ -106,7 +104,7 @@ genMigrationsDir spec = return $ createCopyDirFileDraft RemoveExistingDstDir gen
|
||||
postWriteDbGeneratorActions :: AppSpec -> Path' Abs (Dir ProjectRootDir) -> IO ([GeneratorWarning], [GeneratorError])
|
||||
postWriteDbGeneratorActions spec dstDir = do
|
||||
dbGeneratorWarnings <- maybeToList <$> warnIfDbNeedsMigration spec dstDir
|
||||
dbGeneratorErrors <- maybeToList <$> genPrismaClients spec dstDir
|
||||
dbGeneratorErrors <- maybeToList <$> generatePrismaClient spec dstDir
|
||||
return (dbGeneratorWarnings, dbGeneratorErrors)
|
||||
|
||||
-- | Checks if user needs to run `wasp db migrate-dev` due to changes in schema.prisma, and if so, returns a warning.
|
||||
@ -184,12 +182,12 @@ warnProjectDiffersFromDb projectRootDir = do
|
||||
"Wasp was unable to verify your database is up to date."
|
||||
<> " Running `wasp db migrate-dev` may fix this and will provide more info."
|
||||
|
||||
genPrismaClients :: AppSpec -> Path' Abs (Dir ProjectRootDir) -> IO (Maybe GeneratorError)
|
||||
genPrismaClients spec projectRootDir =
|
||||
generatePrismaClient :: AppSpec -> Path' Abs (Dir ProjectRootDir) -> IO (Maybe GeneratorError)
|
||||
generatePrismaClient spec projectRootDir =
|
||||
ifM
|
||||
wasCurrentSchemaAlreadyGenerated
|
||||
(return Nothing)
|
||||
generatePrismaClientsIfEntitiesExist
|
||||
generatePrismaClientIfEntitiesExist
|
||||
where
|
||||
wasCurrentSchemaAlreadyGenerated :: IO Bool
|
||||
wasCurrentSchemaAlreadyGenerated =
|
||||
@ -197,10 +195,10 @@ genPrismaClients spec projectRootDir =
|
||||
projectRootDir
|
||||
Wasp.Generator.DbGenerator.Common.dbSchemaChecksumOnLastGenerateFileProjectRootDir
|
||||
|
||||
generatePrismaClientsIfEntitiesExist :: IO (Maybe GeneratorError)
|
||||
generatePrismaClientsIfEntitiesExist
|
||||
generatePrismaClientIfEntitiesExist :: IO (Maybe GeneratorError)
|
||||
generatePrismaClientIfEntitiesExist
|
||||
| entitiesExist =
|
||||
either (Just . GenericGeneratorError) (const Nothing) <$> DbOps.generatePrismaClients projectRootDir
|
||||
either (Just . GenericGeneratorError) (const Nothing) <$> DbOps.generatePrismaClient projectRootDir
|
||||
| otherwise = return Nothing
|
||||
|
||||
entitiesExist = not . null $ getEntities spec
|
||||
|
@ -1,8 +1,5 @@
|
||||
module Wasp.Generator.DbGenerator.Common
|
||||
( dbMigrationsDirInDbRootDir,
|
||||
serverPrismaClientOutputDirEnv,
|
||||
webAppPrismaClientOutputDirEnv,
|
||||
prismaClientOutputDirInAppComponentDir,
|
||||
dbSchemaFileFromAppComponentDir,
|
||||
dbRootDirInProjectRootDir,
|
||||
dbSchemaChecksumOnLastDbConcurrenceFileProjectRootDir,
|
||||
@ -19,13 +16,11 @@ module Wasp.Generator.DbGenerator.Common
|
||||
serverRootDirFromDbRootDir,
|
||||
webAppRootDirFromDbRootDir,
|
||||
dbSchemaFileInProjectRootDir,
|
||||
prismaClientOutputDirEnvVar,
|
||||
DbSchemaChecksumFile,
|
||||
)
|
||||
where
|
||||
|
||||
import StrongPath (Dir, File, File', Path', Rel, reldir, relfile, (</>))
|
||||
import qualified StrongPath as SP
|
||||
import Wasp.Generator.Common (AppComponentRootDir, DbRootDir, ProjectRootDir, ServerRootDir)
|
||||
import Wasp.Generator.Templates (TemplatesDir)
|
||||
import Wasp.Project.Db.Migrations (DbMigrationsDir)
|
||||
@ -93,22 +88,6 @@ dbSchemaChecksumOnLastGenerateFileInDbRootDir = [relfile|schema.prisma.wasp-gene
|
||||
dbSchemaChecksumOnLastGenerateFileProjectRootDir :: Path' (Rel ProjectRootDir) (File DbSchemaChecksumOnLastGenerateFile)
|
||||
dbSchemaChecksumOnLastGenerateFileProjectRootDir = dbRootDirInProjectRootDir </> dbSchemaChecksumOnLastGenerateFileInDbRootDir
|
||||
|
||||
prismaClientOutputDirEnvVar :: String
|
||||
prismaClientOutputDirEnvVar = "PRISMA_CLIENT_OUTPUT_DIR"
|
||||
|
||||
prismaClientOutputDirInAppComponentDir :: AppComponentRootDir d => Path' (Rel d) (Dir ServerRootDir)
|
||||
prismaClientOutputDirInAppComponentDir = [reldir|node_modules/.prisma/client|]
|
||||
|
||||
serverPrismaClientOutputDirEnv :: (String, String)
|
||||
serverPrismaClientOutputDirEnv = appComponentPrismaClientOutputDirEnv serverRootDirFromDbRootDir
|
||||
|
||||
webAppPrismaClientOutputDirEnv :: (String, String)
|
||||
webAppPrismaClientOutputDirEnv = appComponentPrismaClientOutputDirEnv webAppRootDirFromDbRootDir
|
||||
|
||||
appComponentPrismaClientOutputDirEnv :: AppComponentRootDir d => Path' (Rel DbRootDir) (Dir d) -> (String, String)
|
||||
appComponentPrismaClientOutputDirEnv appComponentDirFromDbRootDir =
|
||||
(prismaClientOutputDirEnvVar, SP.fromRelDir $ appComponentDirFromDbRootDir </> prismaClientOutputDirInAppComponentDir)
|
||||
|
||||
data MigrateArgs = MigrateArgs
|
||||
{ _migrationName :: Maybe String,
|
||||
_isCreateOnlyMigration :: Bool
|
||||
|
@ -13,24 +13,20 @@ module Wasp.Generator.DbGenerator.Jobs
|
||||
)
|
||||
where
|
||||
|
||||
import StrongPath (Abs, Dir, File, File', Path', (</>))
|
||||
import StrongPath (Abs, Dir, File', Path', (</>))
|
||||
import qualified StrongPath as SP
|
||||
import StrongPath.TH (relfile)
|
||||
import qualified System.Info
|
||||
import Wasp.Generator.Common (ProjectRootDir)
|
||||
import Wasp.Generator.DbGenerator.Common
|
||||
( MigrateArgs (..),
|
||||
PrismaDbSchema,
|
||||
dbSchemaFileInProjectRootDir,
|
||||
)
|
||||
import Wasp.Generator.Job (JobType)
|
||||
import Wasp.Generator.DbGenerator.Common (MigrateArgs (..), dbSchemaFileInProjectRootDir)
|
||||
import qualified Wasp.Generator.Job as J
|
||||
import Wasp.Generator.Job.Process (runNodeCommandAsJob, runNodeCommandAsJobWithExtraEnv)
|
||||
import Wasp.Generator.ServerGenerator.Common (serverRootDirInProjectRootDir)
|
||||
import Wasp.Generator.ServerGenerator.Db.Seed (dbSeedNameEnvVarName)
|
||||
import Wasp.Project.Common (WaspProjectDir, waspProjectDirFromProjectRootDir)
|
||||
|
||||
migrateDev :: Path' Abs (Dir ProjectRootDir) -> MigrateArgs -> J.Job
|
||||
migrateDev projectDir migrateArgs =
|
||||
migrateDev projectRootDir migrateArgs =
|
||||
-- NOTE(matija): We are running this command from server's root dir since that is where
|
||||
-- Prisma packages (cli and client) are currently installed.
|
||||
-- NOTE(martin): `prisma migrate dev` refuses to execute when interactivity is needed if stdout is being piped,
|
||||
@ -40,8 +36,8 @@ migrateDev projectDir migrateArgs =
|
||||
-- we are using `script` to trick Prisma into thinking it is running in TTY (interactively).
|
||||
runNodeCommandAsJob serverDir "script" scriptArgs J.Db
|
||||
where
|
||||
serverDir = projectDir </> serverRootDirInProjectRootDir
|
||||
schemaFile = projectDir </> dbSchemaFileInProjectRootDir
|
||||
serverDir = projectRootDir </> serverRootDirInProjectRootDir
|
||||
schemaFile = projectRootDir </> dbSchemaFileInProjectRootDir
|
||||
|
||||
scriptArgs =
|
||||
if System.Info.os == "darwin"
|
||||
@ -57,7 +53,7 @@ migrateDev projectDir migrateArgs =
|
||||
-- * Linux - we are passing the command as one argument, so we MUST quote the paths.
|
||||
buildPrismaMigrateCmd :: (String -> String) -> [String]
|
||||
buildPrismaMigrateCmd argQuoter =
|
||||
[ argQuoter $ absPrismaExecutableFp projectDir,
|
||||
[ argQuoter $ absPrismaExecutableFp (projectRootDir </> waspProjectDirFromProjectRootDir),
|
||||
"migrate",
|
||||
"dev",
|
||||
"--schema",
|
||||
@ -85,15 +81,19 @@ asPrismaCliArgs migrateArgs = do
|
||||
-- Because of the --exit-code flag, it changes the exit code behavior
|
||||
-- to signal if the diff is empty or not (Empty: 0, Error: 1, Not empty: 2)
|
||||
migrateDiff :: Path' Abs (Dir ProjectRootDir) -> J.Job
|
||||
migrateDiff projectDir = runPrismaCommandAsDbJob projectDir $ \schema ->
|
||||
[ "migrate",
|
||||
"diff",
|
||||
"--from-schema-datamodel",
|
||||
SP.fromAbsFile schema,
|
||||
"--to-schema-datasource",
|
||||
SP.fromAbsFile schema,
|
||||
"--exit-code"
|
||||
]
|
||||
migrateDiff projectRootDir =
|
||||
runPrismaCommandAsJob
|
||||
projectRootDir
|
||||
[ "migrate",
|
||||
"diff",
|
||||
"--from-schema-datamodel",
|
||||
SP.fromAbsFile schema,
|
||||
"--to-schema-datasource",
|
||||
SP.fromAbsFile schema,
|
||||
"--exit-code"
|
||||
]
|
||||
where
|
||||
schema = projectRootDir </> dbSchemaFileInProjectRootDir
|
||||
|
||||
-- | Checks to see if all migrations are applied to the DB.
|
||||
-- An exit code of 0 means we successfully verified all migrations are applied.
|
||||
@ -101,27 +101,34 @@ migrateDiff projectDir = runPrismaCommandAsDbJob projectDir $ \schema ->
|
||||
-- or (b) there are pending migrations to apply.
|
||||
-- Therefore, this should be checked **after** a command that ensures connectivity.
|
||||
migrateStatus :: Path' Abs (Dir ProjectRootDir) -> J.Job
|
||||
migrateStatus projectDir = runPrismaCommandAsDbJob projectDir $ \schema ->
|
||||
["migrate", "status", "--schema", SP.fromAbsFile schema]
|
||||
migrateStatus projectRootDir =
|
||||
runPrismaCommandAsJob
|
||||
projectRootDir
|
||||
["migrate", "status", "--schema", SP.fromAbsFile schema]
|
||||
where
|
||||
schema = projectRootDir </> dbSchemaFileInProjectRootDir
|
||||
|
||||
-- | Runs `prisma migrate reset`, which drops the tables (so schemas and data is lost) and then
|
||||
-- reapplies all the migrations.
|
||||
reset :: Path' Abs (Dir ProjectRootDir) -> J.Job
|
||||
reset projectDir = runPrismaCommandAsDbJob projectDir $ \schema ->
|
||||
-- NOTE(martin): We do "--skip-seed" here because I just think seeding happening automatically on
|
||||
-- reset is too aggressive / confusing.
|
||||
["migrate", "reset", "--schema", SP.fromAbsFile schema, "--skip-generate", "--skip-seed"]
|
||||
reset projectRootDir =
|
||||
runPrismaCommandAsJob
|
||||
projectRootDir
|
||||
-- NOTE(martin): We do "--skip-seed" here because I just think seeding happening automatically on
|
||||
-- reset is too aggressive / confusing.
|
||||
["migrate", "reset", "--schema", SP.fromAbsFile schema, "--skip-generate", "--skip-seed"]
|
||||
where
|
||||
schema = projectRootDir </> dbSchemaFileInProjectRootDir
|
||||
|
||||
-- | Runs `prisma db seed`, which executes the seeding script specified in package.json in
|
||||
-- prisma.seed field.
|
||||
seed :: Path' Abs (Dir ProjectRootDir) -> String -> J.Job
|
||||
-- NOTE: Since v 0.3, Prisma doesn't use --schema parameter for `db seed`.
|
||||
seed projectDir seedName =
|
||||
seed projectRootDir seedName =
|
||||
runPrismaCommandAsJobWithExtraEnv
|
||||
J.Db
|
||||
[(dbSeedNameEnvVarName, seedName)]
|
||||
projectDir
|
||||
(const ["db", "seed"])
|
||||
projectRootDir
|
||||
["db", "seed"]
|
||||
|
||||
-- | Checks if the DB is running and connectable by running
|
||||
-- `prisma db execute --stdin --schema <path to db schema>`.
|
||||
@ -130,56 +137,43 @@ seed projectDir seedName =
|
||||
-- Since nothing is passed to stdin, `prisma db execute` just runs an empty
|
||||
-- SQL command, which works perfectly for checking if the database is running.
|
||||
dbExecuteTest :: Path' Abs (Dir ProjectRootDir) -> J.Job
|
||||
dbExecuteTest projectDir =
|
||||
let absSchemaPath = projectDir </> dbSchemaFileInProjectRootDir
|
||||
in runPrismaCommandAsDbJob
|
||||
projectDir
|
||||
(const ["db", "execute", "--stdin", "--schema", SP.fromAbsFile absSchemaPath])
|
||||
dbExecuteTest projectRootDir =
|
||||
runPrismaCommandAsJob projectRootDir ["db", "execute", "--stdin", "--schema", SP.fromAbsFile schema]
|
||||
where
|
||||
schema = projectRootDir </> dbSchemaFileInProjectRootDir
|
||||
|
||||
-- | Runs `prisma studio` - Prisma's db inspector.
|
||||
runStudio :: Path' Abs (Dir ProjectRootDir) -> J.Job
|
||||
runStudio projectDir = runPrismaCommandAsDbJob projectDir $ \schema ->
|
||||
["studio", "--schema", SP.fromAbsFile schema]
|
||||
|
||||
generatePrismaClient :: Path' Abs (Dir ProjectRootDir) -> (String, String) -> JobType -> J.Job
|
||||
generatePrismaClient projectDir prismaClientOutputDirEnv jobType =
|
||||
runPrismaCommandAsJobWithExtraEnv jobType envVars projectDir $ \schema ->
|
||||
["generate", "--schema", SP.fromAbsFile schema]
|
||||
runStudio projectRootDir =
|
||||
runPrismaCommandAsJob projectRootDir ["studio", "--schema", SP.fromAbsFile schema]
|
||||
where
|
||||
envVars = [prismaClientOutputDirEnv]
|
||||
schema = projectRootDir </> dbSchemaFileInProjectRootDir
|
||||
|
||||
runPrismaCommandAsDbJob ::
|
||||
Path' Abs (Dir ProjectRootDir) ->
|
||||
(Path' Abs (File PrismaDbSchema) -> [String]) ->
|
||||
J.Job
|
||||
runPrismaCommandAsDbJob projectDir makeCmdArgs =
|
||||
runPrismaCommandAsJob J.Db projectDir makeCmdArgs
|
||||
generatePrismaClient :: Path' Abs (Dir ProjectRootDir) -> J.Job
|
||||
generatePrismaClient projectRootDir =
|
||||
runPrismaCommandAsJob projectRootDir ["generate", "--schema", SP.fromAbsFile schema]
|
||||
where
|
||||
schema = projectRootDir </> dbSchemaFileInProjectRootDir
|
||||
|
||||
runPrismaCommandAsJob ::
|
||||
JobType ->
|
||||
Path' Abs (Dir ProjectRootDir) ->
|
||||
(Path' Abs (File PrismaDbSchema) -> [String]) ->
|
||||
J.Job
|
||||
runPrismaCommandAsJob jobType projectDir makeCmdArgs =
|
||||
runPrismaCommandAsJobWithExtraEnv jobType [] projectDir makeCmdArgs
|
||||
runPrismaCommandAsJob :: Path' Abs (Dir ProjectRootDir) -> [String] -> J.Job
|
||||
runPrismaCommandAsJob projectRootDir cmdArgs =
|
||||
runPrismaCommandAsJobWithExtraEnv [] projectRootDir cmdArgs
|
||||
|
||||
runPrismaCommandAsJobWithExtraEnv ::
|
||||
JobType ->
|
||||
[(String, String)] ->
|
||||
Path' Abs (Dir ProjectRootDir) ->
|
||||
(Path' Abs (File PrismaDbSchema) -> [String]) ->
|
||||
[String] ->
|
||||
J.Job
|
||||
runPrismaCommandAsJobWithExtraEnv jobType envVars projectDir makeCmdArgs =
|
||||
runNodeCommandAsJobWithExtraEnv envVars serverDir (absPrismaExecutableFp projectDir) (makeCmdArgs schemaFile) jobType
|
||||
runPrismaCommandAsJobWithExtraEnv envVars projectRootDir cmdArgs =
|
||||
runNodeCommandAsJobWithExtraEnv envVars waspProjectDir (absPrismaExecutableFp waspProjectDir) cmdArgs J.Db
|
||||
where
|
||||
serverDir = projectDir </> serverRootDirInProjectRootDir
|
||||
schemaFile = projectDir </> dbSchemaFileInProjectRootDir
|
||||
waspProjectDir = projectRootDir </> waspProjectDirFromProjectRootDir
|
||||
|
||||
-- | NOTE: The expectation is that `npm install` was already executed
|
||||
-- such that we can use the locally installed package.
|
||||
-- This assumption is ok since it happens during compilation now.
|
||||
absPrismaExecutableFp :: Path' Abs (Dir ProjectRootDir) -> FilePath
|
||||
absPrismaExecutableFp projectDir = SP.fromAbsFile prismaExecutableAbs
|
||||
absPrismaExecutableFp :: Path' Abs (Dir WaspProjectDir) -> FilePath
|
||||
absPrismaExecutableFp waspProjectDir = SP.fromAbsFile prismaExecutableAbs
|
||||
where
|
||||
prismaExecutableAbs :: Path' Abs File'
|
||||
prismaExecutableAbs = projectDir </> serverRootDirInProjectRootDir </> [relfile|./node_modules/.bin/prisma|]
|
||||
prismaExecutableAbs = waspProjectDir </> [relfile|./node_modules/.bin/prisma|]
|
||||
|
@ -1,6 +1,6 @@
|
||||
module Wasp.Generator.DbGenerator.Operations
|
||||
( migrateDevAndCopyToSource,
|
||||
generatePrismaClients,
|
||||
generatePrismaClient,
|
||||
doesSchemaMatchDb,
|
||||
writeDbSchemaChecksumToFile,
|
||||
areAllMigrationsAppliedToDb,
|
||||
@ -12,13 +12,10 @@ module Wasp.Generator.DbGenerator.Operations
|
||||
)
|
||||
where
|
||||
|
||||
import Control.Applicative (liftA2)
|
||||
import Control.Concurrent (newChan)
|
||||
import Control.Concurrent.Async (concurrently)
|
||||
import Control.Monad (when)
|
||||
import Control.Monad.Catch (catch)
|
||||
import Control.Monad.Extra (whenM)
|
||||
import Data.Either (isRight)
|
||||
import qualified Data.Text as T
|
||||
import qualified Path as P
|
||||
import StrongPath (Abs, Dir, File, Path', Rel, (</>))
|
||||
@ -36,12 +33,9 @@ import Wasp.Generator.DbGenerator.Common
|
||||
dbSchemaChecksumOnLastGenerateFileProjectRootDir,
|
||||
dbSchemaFileInProjectRootDir,
|
||||
getOnLastDbConcurrenceChecksumFileRefreshAction,
|
||||
serverPrismaClientOutputDirEnv,
|
||||
webAppPrismaClientOutputDirEnv,
|
||||
)
|
||||
import qualified Wasp.Generator.DbGenerator.Jobs as DbJobs
|
||||
import Wasp.Generator.FileDraft.WriteableMonad (WriteableMonad (copyDirectoryRecursive, doesDirectoryExist))
|
||||
import qualified Wasp.Generator.Job as J
|
||||
import Wasp.Generator.Job.IO
|
||||
( collectJobTextOutputUntilExitReceived,
|
||||
printJobMsgsUntilExitReceived,
|
||||
@ -184,31 +178,21 @@ isDbConnectionPossible DbConnectionSuccess = True
|
||||
isDbConnectionPossible DbNotCreated = True
|
||||
isDbConnectionPossible _ = False
|
||||
|
||||
generatePrismaClients :: Path' Abs (Dir ProjectRootDir) -> IO (Either String ())
|
||||
generatePrismaClients projectRootDir = do
|
||||
generateResult <- liftA2 (>>) generatePrismaClientForServer generatePrismaClientForWebApp projectRootDir
|
||||
when (isRight generateResult) updateDbSchemaChecksumOnLastGenerate
|
||||
return generateResult
|
||||
where
|
||||
generatePrismaClientForServer = generatePrismaClient serverPrismaClientOutputDirEnv J.Server
|
||||
generatePrismaClientForWebApp = generatePrismaClient webAppPrismaClientOutputDirEnv J.WebApp
|
||||
updateDbSchemaChecksumOnLastGenerate =
|
||||
writeDbSchemaChecksumToFile projectRootDir dbSchemaChecksumOnLastGenerateFileProjectRootDir
|
||||
|
||||
generatePrismaClient ::
|
||||
(String, String) ->
|
||||
J.JobType ->
|
||||
Path' Abs (Dir ProjectRootDir) ->
|
||||
IO (Either String ())
|
||||
generatePrismaClient prismaClientOutputDirEnv jobType projectRootDir = do
|
||||
generatePrismaClient :: Path' Abs (Dir ProjectRootDir) -> IO (Either String ())
|
||||
generatePrismaClient projectRootDir = do
|
||||
chan <- newChan
|
||||
(_, exitCode) <-
|
||||
concurrently
|
||||
(readJobMessagesAndPrintThemPrefixed chan)
|
||||
(DbJobs.generatePrismaClient projectRootDir prismaClientOutputDirEnv jobType chan)
|
||||
return $ case exitCode of
|
||||
ExitSuccess -> Right ()
|
||||
ExitFailure code -> Left $ "Prisma client generation failed with exit code: " ++ show code
|
||||
(DbJobs.generatePrismaClient projectRootDir chan)
|
||||
case exitCode of
|
||||
ExitFailure code -> return $ Left $ "Prisma client generation failed with exit code: " ++ show code
|
||||
ExitSuccess -> do
|
||||
updateDbSchemaChecksumOnLastGenerate
|
||||
return $ Right ()
|
||||
where
|
||||
updateDbSchemaChecksumOnLastGenerate =
|
||||
writeDbSchemaChecksumToFile projectRootDir dbSchemaChecksumOnLastGenerateFileProjectRootDir
|
||||
|
||||
-- | Checks `prisma migrate diff` exit code to determine if schema.prisma is
|
||||
-- different than the DB. Returns Nothing on error as we do not know the current state.
|
||||
|
@ -24,14 +24,12 @@ import Wasp.Generator.Common
|
||||
import Wasp.Generator.DbGenerator.Common
|
||||
( PrismaDbSchema,
|
||||
dbSchemaFileFromAppComponentDir,
|
||||
serverPrismaClientOutputDirEnv,
|
||||
)
|
||||
import Wasp.Generator.FileDraft (FileDraft (..), createTemplateFileDraft)
|
||||
import qualified Wasp.Generator.FileDraft.TemplateFileDraft as TmplFD
|
||||
import Wasp.Generator.Monad (Generator, GeneratorError, runGenerator)
|
||||
import Wasp.Generator.Templates (TemplatesDir, compileAndRenderTemplate)
|
||||
import qualified Wasp.SemanticVersion as SV
|
||||
import Wasp.Util (getEnvVarDefinition)
|
||||
|
||||
genDockerFiles :: AppSpec -> Generator [FileDraft]
|
||||
genDockerFiles spec = sequence [genDockerfile spec, genDockerignore spec]
|
||||
@ -47,7 +45,6 @@ genDockerfile spec = do
|
||||
( Just $
|
||||
object
|
||||
[ "usingPrisma" .= not (null $ AS.getDecls @AS.Entity.Entity spec),
|
||||
"serverPrismaClientOutputDirEnv" .= getEnvVarDefinition serverPrismaClientOutputDirEnv,
|
||||
"dbSchemaFileFromServerDir" .= SP.fromRelFile dbSchemaFileFromServerDir,
|
||||
"nodeMajorVersion" .= show (SV.major $ getLowestNodeVersionUserAllows spec),
|
||||
"userDockerfile" .= fromMaybe "" (AS.userDockerfileContents spec)
|
||||
|
@ -158,8 +158,8 @@ combineNpmDepsForPackage npmDepsForWasp npmDepsForUser =
|
||||
allWaspDepsByName = waspDepsByName `Map.union` waspDevDepsByName
|
||||
conflictErrors = determineConflictErrors allWaspDepsByName userDepsByName
|
||||
devConflictErrors = determineConflictErrors allWaspDepsByName userDevDepsByName
|
||||
remainingWapsDeps = allWaspDepsByName `Map.difference` userDepsByName
|
||||
remainingWaspDevDeps = allWaspDepsByName `Map.difference` userDevDepsByName
|
||||
remainingWapsDeps = waspDepsByName `Map.difference` userDepsByName
|
||||
remainingWaspDevDeps = waspDevDepsByName `Map.difference` userDevDepsByName
|
||||
|
||||
type DepsByName = Map.Map String D.Dependency
|
||||
|
||||
|
@ -15,6 +15,7 @@ import qualified Wasp.Generator.Job as J
|
||||
import Wasp.Generator.Job.Process (runNodeCommandAsJob)
|
||||
import Wasp.Generator.Monad (Generator)
|
||||
import qualified Wasp.Generator.NpmDependencies as N
|
||||
import qualified Wasp.Generator.ServerGenerator.AuthG as ServerAuthG
|
||||
import Wasp.Generator.Templates (TemplatesDir, getTemplatesDirAbsPath)
|
||||
import Wasp.Project.Common (WaspProjectDir)
|
||||
import qualified Wasp.SemanticVersion as SV
|
||||
@ -65,7 +66,14 @@ genPackageJson spec =
|
||||
("superjson", "^1.12.2"),
|
||||
("@types/express-serve-static-core", "^4.17.13")
|
||||
]
|
||||
++ depsRequiredForAuth spec,
|
||||
++ depsRequiredForAuth spec
|
||||
-- This must be installed in the SDK because it lists prisma/client as a dependency.
|
||||
-- Installing it inside .wasp/out/server/node_modules would also
|
||||
-- install prisma/client in the same folder, which would cause our
|
||||
-- runtime to load the wrong (uninitialized prisma/client)
|
||||
-- TODO(filip): Find a better way to handle duplicate
|
||||
-- dependencies: https://github.com/wasp-lang/wasp/issues/1640
|
||||
++ ServerAuthG.depsRequiredByAuth spec,
|
||||
N.devDependencies = AS.Dependency.fromList []
|
||||
}
|
||||
|
||||
|
@ -45,7 +45,6 @@ import Wasp.Env (envVarsToDotEnvContent)
|
||||
import Wasp.Generator.Common
|
||||
( ServerRootDir,
|
||||
makeJsonWithEntityData,
|
||||
prismaVersion,
|
||||
)
|
||||
import qualified Wasp.Generator.DbGenerator.Auth as DbAuth
|
||||
import Wasp.Generator.FileDraft (FileDraft, createTextFileDraft)
|
||||
@ -53,7 +52,7 @@ import Wasp.Generator.Monad (Generator)
|
||||
import qualified Wasp.Generator.NpmDependencies as N
|
||||
import Wasp.Generator.ServerGenerator.ApiRoutesG (genApis)
|
||||
import Wasp.Generator.ServerGenerator.Auth.OAuthAuthG (depsRequiredByPassport)
|
||||
import Wasp.Generator.ServerGenerator.AuthG (depsRequiredByAuth, genAuth)
|
||||
import Wasp.Generator.ServerGenerator.AuthG (genAuth)
|
||||
import qualified Wasp.Generator.ServerGenerator.Common as C
|
||||
import Wasp.Generator.ServerGenerator.ConfigG (genConfigFile)
|
||||
import Wasp.Generator.ServerGenerator.CrudG (genCrud)
|
||||
@ -165,7 +164,6 @@ npmDepsForWasp spec =
|
||||
("cors", "^2.8.5"),
|
||||
("express", "~4.18.1"),
|
||||
("morgan", "~1.10.0"),
|
||||
("@prisma/client", show prismaVersion),
|
||||
("jsonwebtoken", "^8.5.1"),
|
||||
-- NOTE: secure-password has a package.json override for sodium-native.
|
||||
("secure-password", "^4.0.0"),
|
||||
@ -177,7 +175,6 @@ npmDepsForWasp spec =
|
||||
("rate-limiter-flexible", "^2.4.1"),
|
||||
("superjson", "^1.12.2")
|
||||
]
|
||||
++ depsRequiredByAuth spec
|
||||
++ depsRequiredByPassport spec
|
||||
++ depsRequiredByJobs spec
|
||||
++ depsRequiredByEmail spec
|
||||
@ -186,7 +183,6 @@ npmDepsForWasp spec =
|
||||
AS.Dependency.fromList
|
||||
[ ("nodemon", "^2.0.19"),
|
||||
("standard", "^17.0.0"),
|
||||
("prisma", show prismaVersion),
|
||||
-- TODO: Allow users to choose whether they want to use TypeScript
|
||||
-- in their projects and install these dependencies accordingly.
|
||||
("typescript", "^5.1.0"),
|
||||
|
@ -4,17 +4,63 @@ module Wasp.Project.Common
|
||||
CompileWarning,
|
||||
WaspProjectDir,
|
||||
packageJsonInWaspProjectDir,
|
||||
DotWaspDir,
|
||||
dotWaspDirInWaspProjectDir,
|
||||
dotWaspRootFileInWaspProjectDir,
|
||||
dotWaspInfoFileInGeneratedCodeDir,
|
||||
extServerCodeDirInWaspProjectDir,
|
||||
extClientCodeDirInWaspProjectDir,
|
||||
extSharedCodeDirInWaspProjectDir,
|
||||
generatedCodeDirInDotWaspDir,
|
||||
buildDirInDotWaspDir,
|
||||
waspProjectDirFromProjectRootDir,
|
||||
)
|
||||
where
|
||||
|
||||
import StrongPath (Abs, Dir, File', Path', Rel, relfile, toFilePath, (</>))
|
||||
import StrongPath (Abs, Dir, File', Path', Rel, reldir, relfile, toFilePath, (</>))
|
||||
import System.Directory (doesFileExist)
|
||||
import Wasp.AppSpec.ExternalCode (SourceExternalCodeDir)
|
||||
import qualified Wasp.Generator.Common
|
||||
|
||||
data WaspProjectDir -- Root dir of Wasp project, containing source files.
|
||||
|
||||
type CompileError = String
|
||||
data DotWaspDir -- Here we put everything that wasp generates.
|
||||
|
||||
type CompileWarning = String
|
||||
-- | NOTE: If you change the depth of this path, also update @waspProjectDirFromProjectRootDir@ below.
|
||||
-- TODO: SHould this be renamed to include word "root"?
|
||||
dotWaspDirInWaspProjectDir :: Path' (Rel WaspProjectDir) (Dir DotWaspDir)
|
||||
dotWaspDirInWaspProjectDir = [reldir|.wasp|]
|
||||
|
||||
-- | NOTE: If you change the depth of this path, also update @waspProjectDirFromProjectRootDir@ below.
|
||||
-- TODO: Hm this has different name than it has in Generator.
|
||||
generatedCodeDirInDotWaspDir :: Path' (Rel DotWaspDir) (Dir Wasp.Generator.Common.ProjectRootDir)
|
||||
generatedCodeDirInDotWaspDir = [reldir|out|]
|
||||
|
||||
-- | NOTE: If you change the depth of this path, also update @waspProjectDirFromProjectRootDir@ below.
|
||||
buildDirInDotWaspDir :: Path' (Rel DotWaspDir) (Dir Wasp.Generator.Common.ProjectRootDir)
|
||||
buildDirInDotWaspDir = [reldir|build|]
|
||||
|
||||
-- | NOTE: This path is calculated from the values of @dotWaspDirInWaspProjectDir@,
|
||||
-- @generatedCodeDirInDotWaspDir@ and @buildDirInDotWaspDir@., which are the three functions just above.
|
||||
-- Also, it assumes @generatedCodeDirInDotWaspDir@ and @buildDirInDotWaspDir@ have same depth.
|
||||
-- If any of those change significantly (their depth), this path should be adjusted.
|
||||
waspProjectDirFromProjectRootDir :: Path' (Rel Wasp.Generator.Common.ProjectRootDir) (Dir WaspProjectDir)
|
||||
waspProjectDirFromProjectRootDir = [reldir|../../|]
|
||||
|
||||
dotWaspRootFileInWaspProjectDir :: Path' (Rel WaspProjectDir) File'
|
||||
dotWaspRootFileInWaspProjectDir = [relfile|.wasproot|]
|
||||
|
||||
dotWaspInfoFileInGeneratedCodeDir :: Path' (Rel Wasp.Generator.Common.ProjectRootDir) File'
|
||||
dotWaspInfoFileInGeneratedCodeDir = [relfile|.waspinfo|]
|
||||
|
||||
extServerCodeDirInWaspProjectDir :: Path' (Rel WaspProjectDir) (Dir SourceExternalCodeDir)
|
||||
extServerCodeDirInWaspProjectDir = [reldir|src|]
|
||||
|
||||
extClientCodeDirInWaspProjectDir :: Path' (Rel WaspProjectDir) (Dir SourceExternalCodeDir)
|
||||
extClientCodeDirInWaspProjectDir = [reldir|src|]
|
||||
|
||||
extSharedCodeDirInWaspProjectDir :: Path' (Rel WaspProjectDir) (Dir SourceExternalCodeDir)
|
||||
extSharedCodeDirInWaspProjectDir = [reldir|src|]
|
||||
|
||||
packageJsonInWaspProjectDir :: Path' (Rel WaspProjectDir) File'
|
||||
packageJsonInWaspProjectDir = [relfile|package.json|]
|
||||
@ -27,3 +73,7 @@ findFileInWaspProjectDir waspDir file = do
|
||||
let fileAbsFp = waspDir </> file
|
||||
fileExists <- doesFileExist $ toFilePath fileAbsFp
|
||||
return $ if fileExists then Just fileAbsFp else Nothing
|
||||
|
||||
type CompileError = String
|
||||
|
||||
type CompileWarning = String
|
||||
|
Loading…
Reference in New Issue
Block a user