Skip to content

Commit

Permalink
Fail if you find both wasp files
Browse files Browse the repository at this point in the history
  • Loading branch information
sodic committed Oct 7, 2024
1 parent 3513b68 commit e9ef283
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ replaceTemplatePlaceholdersInWaspFile ::
NewProjectAppName -> NewProjectName -> Path' Abs (Dir WaspProjectDir) -> IO ()
replaceTemplatePlaceholdersInWaspFile appName projectName projectDir =
findWaspFile projectDir >>= \case
Nothing -> return ()
Just (WaspLang absMainWaspFile) -> replaceTemplatePlaceholders absMainWaspFile
Just (WaspTs absMainTsFile) -> replaceTemplatePlaceholders absMainTsFile
Left _error -> return ()
Right (WaspLang absMainWaspFile) -> replaceTemplatePlaceholders absMainWaspFile
Right (WaspTs absMainTsFile) -> replaceTemplatePlaceholders absMainTsFile
where
replaceTemplatePlaceholders = replaceTemplatePlaceholdersInFileOnDisk appName projectName

Expand Down
18 changes: 11 additions & 7 deletions waspc/src/Wasp/Project/Analyze.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ module Wasp.Project.Analyze
)
where

import Control.Applicative ((<|>))
import Control.Arrow (ArrowChoice (left))
import Control.Concurrent (newChan)
import Control.Concurrent.Async (concurrently)
Expand Down Expand Up @@ -52,7 +51,6 @@ import qualified Wasp.Psl.Ast.Schema as Psl.Schema
import qualified Wasp.Psl.Parser.Schema as Psl.Parser
import Wasp.Psl.Valid (getValidDbSystemFromPrismaSchema)
import qualified Wasp.Psl.Valid as PslV
import Wasp.Util (maybeToEither)
import Wasp.Util.Aeson (encodeToString)
import qualified Wasp.Util.IO as IOUtil
import Wasp.Util.StrongPath (replaceRelExtension)
Expand All @@ -64,7 +62,7 @@ analyzeWaspProject ::
CompileOptions ->
IO (Either [CompileError] AS.AppSpec, [CompileWarning])
analyzeWaspProject waspDir options = do
waspFilePathOrError <- maybeToEither [fileNotFoundMessage] <$> findWaspFile waspDir
waspFilePathOrError <- left (: []) <$> findWaspFile waspDir

case waspFilePathOrError of
Left err -> return (Left err, [])
Expand All @@ -79,8 +77,6 @@ analyzeWaspProject waspDir options = do
EC.analyzeExternalConfigs waspDir >>= \case
Left errors -> return (Left errors, [])
Right externalConfigs -> constructAppSpec waspDir options externalConfigs prismaSchemaAst declarations
where
fileNotFoundMessage = "Couldn't find the *.wasp file in the " ++ toFilePath waspDir ++ " directory"

data WaspFile
= WaspLang !(Path' Abs (File WaspLangFile))
Expand Down Expand Up @@ -242,14 +238,22 @@ constructAppSpec waspDir options externalConfigs parsedPrismaSchema decls = do

return $ runValidation ASV.validateAppSpec appSpec

findWaspFile :: Path' Abs (Dir WaspProjectDir) -> IO (Maybe WaspFile)
findWaspFile :: Path' Abs (Dir WaspProjectDir) -> IO (Either String WaspFile)
findWaspFile waspDir = do
files <- fst <$> IOUtil.listDirectory waspDir
return $ findWaspTsFile files <|> findWaspLangFile files
return $ case (findWaspTsFile files, findWaspLangFile files) of
(Just _, Just _) -> Left bothFilesFoundMessage
(Nothing, Nothing) -> Left fileNotFoundMessage
(Just waspTsFile, Nothing) -> Right waspTsFile
(Nothing, Just waspLangFile) -> Right waspLangFile
where
findWaspTsFile files = WaspTs <$> findFileThatEndsWith ".wasp.mts" files
findWaspLangFile files = WaspLang <$> findFileThatEndsWith ".wasp" files
findFileThatEndsWith suffix files = SP.castFile . (waspDir </>) <$> find ((suffix `isSuffixOf`) . toFilePath) files
fileNotFoundMessage = "Couldn't find the *.wasp or a *.wasp.mts file in the " ++ toFilePath waspDir ++ " directory"
bothFilesFoundMessage =
"Found both *.wasp and *.wasp.mts files in the project directory. "
++ "You must choose how you want to define your app (using Wasp or TypeScript) and only keep one of them."

analyzePrismaSchema :: Path' Abs (Dir WaspProjectDir) -> IO (Either [CompileError] Psl.Schema.Schema, [CompileWarning])
analyzePrismaSchema waspProjectDir = do
Expand Down

0 comments on commit e9ef283

Please sign in to comment.