Skip to content

Commit

Permalink
Ensure users don't create a .wasp file
Browse files Browse the repository at this point in the history
  • Loading branch information
komyg committed Dec 19, 2024
1 parent 017217d commit 22b4046
Showing 1 changed file with 28 additions and 13 deletions.
41 changes: 28 additions & 13 deletions waspc/src/Wasp/Project/Analyze.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module Wasp.Project.Analyze
)
where

import qualified System.FilePath as FP
import Control.Arrow (ArrowChoice (left))
import Control.Concurrent (newChan)
import Control.Concurrent.Async (concurrently)
Expand All @@ -26,6 +27,7 @@ import StrongPath
fromAbsFile,
fromRelFile,
relfile,
reldir,
(</>),
)
import System.Exit (ExitCode (..))
Expand Down Expand Up @@ -77,21 +79,25 @@ analyzeWaspProject ::
CompileOptions ->
IO (Either [CompileError] AS.AppSpec, [CompileWarning])
analyzeWaspProject waspDir options = do
waspFilePathOrError <- left (: []) <$> findWaspFile waspDir
dirResult <- waspDirExists waspDir
case dirResult of
Left err -> return (Left [err], [])
Right _ -> do
waspFilePathOrError <- left (: []) <$> findWaspFile waspDir

case waspFilePathOrError of
Left err -> return (Left err, [])
Right waspFilePath ->
analyzePrismaSchema waspDir >>= \case
(Left prismaSchemaErrors, prismaSchemaWarnings) -> return (Left prismaSchemaErrors, prismaSchemaWarnings)
-- NOTE: we are ignoring prismaSchemaWarnings if the schema was parsed successfully
(Right prismaSchemaAst, _) ->
analyzeWaspFile waspDir prismaSchemaAst waspFilePath >>= \case
Left errors -> return (Left errors, [])
Right declarations ->
EC.analyzeExternalConfigs waspDir (getSrcTsConfigInWaspProjectDir waspFilePath) >>= \case
case waspFilePathOrError of
Left err -> return (Left err, [])
Right waspFilePath ->
analyzePrismaSchema waspDir >>= \case
(Left prismaSchemaErrors, prismaSchemaWarnings) -> return (Left prismaSchemaErrors, prismaSchemaWarnings)
-- NOTE: we are ignoring prismaSchemaWarnings if the schema was parsed successfully
(Right prismaSchemaAst, _) ->
analyzeWaspFile waspDir prismaSchemaAst waspFilePath >>= \case
Left errors -> return (Left errors, [])
Right externalConfigs -> constructAppSpec waspDir options externalConfigs prismaSchemaAst declarations
Right declarations ->
EC.analyzeExternalConfigs waspDir (getSrcTsConfigInWaspProjectDir waspFilePath) >>= \case
Left errors -> return (Left errors, [])
Right externalConfigs -> constructAppSpec waspDir options externalConfigs prismaSchemaAst declarations

data CompiledWaspJsFile

Expand Down Expand Up @@ -245,6 +251,15 @@ constructAppSpec waspDir options externalConfigs parsedPrismaSchema decls = do

return $ runValidation ASV.validateAppSpec appSpec


waspDirExists :: Path' Abs (Dir WaspProjectDir) -> IO (Either String (Path' Abs (Dir WaspProjectDir)))
waspDirExists waspDir = do
let waspDotWaspPath = waspDir </> [relfile|.wasp|]
isFile <- IOUtil.doesFileExist waspDotWaspPath
if isFile
then return $ Left "The path to the Wasp project is a file, but it should be a directory."
else return $ Right waspDir

findWaspFile :: Path' Abs (Dir WaspProjectDir) -> IO (Either String WaspFilePath)
findWaspFile waspDir = do
files <- fst <$> IOUtil.listDirectory waspDir
Expand Down

0 comments on commit 22b4046

Please sign in to comment.