@@ -12,6 +12,7 @@ import StrongPath
12
12
castFile ,
13
13
fromAbsDir ,
14
14
fromRelFile ,
15
+ relfile ,
15
16
(</>) ,
16
17
)
17
18
import qualified Wasp.AppSpec as AS
@@ -28,24 +29,29 @@ import qualified Wasp.Util.IO as IOUtil
28
29
29
30
findWaspFile :: Path' Abs (Dir WaspProjectDir ) -> IO (Either String WaspFilePath )
30
31
findWaspFile waspDir = do
31
- files <- fst <$> IOUtil. listDirectory waspDir
32
- return $ case (findWaspTsFile files, findWaspLangFile files) of
33
- (Just _, Just _) -> Left bothFilesFoundMessage
34
- (Nothing , Nothing ) -> Left fileNotFoundMessage
35
- (Just waspTsFile, Nothing ) -> Right waspTsFile
36
- (Nothing , Just waspLangFile) -> Right waspLangFile
32
+ let dotWaspPath = waspDir </> [relfile |.wasp|]
33
+ isFile <- IOUtil. doesFileExist dotWaspPath
34
+ if isFile
35
+ then return $ Left " Invalid file name for the .wasp file. Please rename it to [something].wasp."
36
+ else do
37
+ files <- fst <$> IOUtil. listDirectory waspDir
38
+ return $ case (findWaspTsFile files, findWaspLangFile files) of
39
+ (tsFiles, langFiles)
40
+ | not (null tsFiles) && not (null langFiles) -> Left bothFilesFoundMessage
41
+ | null tsFiles && null langFiles -> Left fileNotFoundMessage
42
+ | [waspTsFile] <- tsFiles, null langFiles -> Right waspTsFile
43
+ | null tsFiles, [waspLangFile] <- langFiles -> Right waspLangFile
44
+ | otherwise -> Left multipleFilesFoundMessage
37
45
where
38
46
findWaspTsFile files = WaspTs <$> findFileThatEndsWith " .wasp.ts" files
39
47
findWaspLangFile files = WaspLang <$> findFileThatEndsWith " .wasp" files
40
- findFileThatEndsWith suffix files =
41
- castFile
42
- . (waspDir </> )
43
- <$> find ((suffix `isSuffixOf` ) . fromRelFile) files
44
-
45
- fileNotFoundMessage = " Couldn't find a *.wasp or a *.wasp.ts file in directory " ++ fromAbsDir waspDir ++ " ."
48
+ findFileThatEndsWith suffix files = castFile . (waspDir </> ) <$> findFilesThatEndWith suffix files
49
+ findFilesThatEndWith suffix files = filter ((suffix `isSuffixOf` ) . fromRelFile) files
50
+ fileNotFoundMessage = " Couldn't find the *.wasp or a *.wasp.ts file in the " ++ fromAbsDir waspDir ++ " directory"
46
51
bothFilesFoundMessage =
47
52
" Found both *.wasp and *.wasp.ts files in the project directory. "
48
53
++ " You must choose how you want to define your app (using Wasp or TypeScript) and only keep one of them."
54
+ multipleFilesFoundMessage = " Found multiple *.wasp or *.wasp.ts files in the project directory. Please keep only one."
49
55
50
56
analyzeWaspFile ::
51
57
Path' Abs (Dir WaspProjectDir ) ->
0 commit comments