Skip to content

Commit

Permalink
Updated findWaspFile in new location
Browse files Browse the repository at this point in the history
  • Loading branch information
komyg committed Jan 13, 2025
1 parent d01960a commit 285ce4b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 37 deletions.
26 changes: 0 additions & 26 deletions waspc/src/Wasp/Project/Analyze.hs
Original file line number Diff line number Diff line change
Expand Up @@ -118,32 +118,6 @@ constructAppSpec waspDir options externalConfigs parsedPrismaSchema decls = do

return $ runValidation ASV.validateAppSpec appSpec

findWaspFile :: Path' Abs (Dir WaspProjectDir) -> IO (Either String WaspFilePath)
findWaspFile waspDir = do
let dotWaspPath = waspDir </> [relfile|.wasp|]
isFile <- IOUtil.doesFileExist dotWaspPath
if isFile
then return $ Left "Invalid file name for the .wasp file. Please rename it to [something].wasp."
else do
files <- fst <$> IOUtil.listDirectory waspDir
return $ case (findWaspTsFile files, findWaspLangFile files) of
(tsFiles, langFiles)
| not (null tsFiles) && not (null langFiles) -> Left bothFilesFoundMessage
| null tsFiles && null langFiles -> Left fileNotFoundMessage
| [waspTsFile] <- tsFiles, null langFiles -> Right waspTsFile
| null tsFiles, [waspLangFile] <- langFiles -> Right waspLangFile
| otherwise -> Left multipleFilesFoundMessage
where
findWaspTsFile files = WaspTs <$> findFileThatEndsWith ".wasp.ts" files
findWaspLangFile files = WaspLang <$> findFileThatEndsWith ".wasp" files
findFileThatEndsWith suffix files = castFile . (waspDir </>) <$> findFilesThatEndWith suffix files
findFilesThatEndWith suffix files = filter ((suffix `isSuffixOf`) . fromRelFile) files
fileNotFoundMessage = "Couldn't find the *.wasp or a *.wasp.ts file in the " ++ fromAbsDir waspDir ++ " directory"
bothFilesFoundMessage =
"Found both *.wasp and *.wasp.ts 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."
multipleFilesFoundMessage = "Found multiple *.wasp or *.wasp.ts files in the project directory. Please keep only one."

analyzePrismaSchema :: Path' Abs (Dir WaspProjectDir) -> IO (Either [CompileError] Psl.Schema.Schema, [CompileWarning])
analyzePrismaSchema waspProjectDir = do
findPrismaSchemaFile waspProjectDir >>= \case
Expand Down
28 changes: 17 additions & 11 deletions waspc/src/Wasp/Project/WaspFile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import StrongPath
castFile,
fromAbsDir,
fromRelFile,
relfile,
(</>),
)
import qualified Wasp.AppSpec as AS
Expand All @@ -28,24 +29,29 @@ import qualified Wasp.Util.IO as IOUtil

findWaspFile :: Path' Abs (Dir WaspProjectDir) -> IO (Either String WaspFilePath)
findWaspFile waspDir = do
files <- fst <$> IOUtil.listDirectory waspDir
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
let dotWaspPath = waspDir </> [relfile|.wasp|]
isFile <- IOUtil.doesFileExist dotWaspPath
if isFile
then return $ Left "Invalid file name for the .wasp file. Please rename it to [something].wasp."
else do
files <- fst <$> IOUtil.listDirectory waspDir
return $ case (findWaspTsFile files, findWaspLangFile files) of
(tsFiles, langFiles)
| not (null tsFiles) && not (null langFiles) -> Left bothFilesFoundMessage
| null tsFiles && null langFiles -> Left fileNotFoundMessage
| [waspTsFile] <- tsFiles, null langFiles -> Right waspTsFile
| null tsFiles, [waspLangFile] <- langFiles -> Right waspLangFile
| otherwise -> Left multipleFilesFoundMessage
where
findWaspTsFile files = WaspTs <$> findFileThatEndsWith ".wasp.ts" files
findWaspLangFile files = WaspLang <$> findFileThatEndsWith ".wasp" files
findFileThatEndsWith suffix files =
castFile
. (waspDir </>)
<$> find ((suffix `isSuffixOf`) . fromRelFile) files

findFileThatEndsWith suffix files = castFile . (waspDir </>) <$> findFilesThatEndWith suffix files
findFilesThatEndWith suffix files = filter ((suffix `isSuffixOf`) . fromRelFile) files
fileNotFoundMessage = "Couldn't find the *.wasp or a *.wasp.ts file in the " ++ fromAbsDir waspDir ++ " directory"
bothFilesFoundMessage =
"Found both *.wasp and *.wasp.ts 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."
multipleFilesFoundMessage = "Found multiple *.wasp or *.wasp.ts files in the project directory. Please keep only one."

analyzeWaspFile ::
Path' Abs (Dir WaspProjectDir) ->
Expand Down

0 comments on commit 285ce4b

Please sign in to comment.