mirror of
https://github.com/wasp-lang/wasp.git
synced 2024-12-29 03:53:14 +03:00
Warn if .env file found (#746)
This commit is contained in:
parent
3f63340fc1
commit
4cdc06dd13
@ -5,6 +5,7 @@ where
|
||||
|
||||
import Control.Monad.Except (throwError)
|
||||
import Control.Monad.IO.Class (liftIO)
|
||||
import Data.List.NonEmpty (toList)
|
||||
import Wasp.AppSpec (AppSpec)
|
||||
import qualified Wasp.AppSpec.App.Dependency as AS.Dependency
|
||||
import Wasp.Cli.Command (Command, CommandError (..))
|
||||
@ -20,12 +21,12 @@ import qualified Wasp.Util.Terminal as Term
|
||||
deps :: Command ()
|
||||
deps = do
|
||||
waspProjectDir <- findWaspProjectRootDirFromCwd
|
||||
appSpecOrCompileErrors <- liftIO $ analyzeWaspProject waspProjectDir (defaultCompileOptions waspProjectDir)
|
||||
(_, appSpecOrAnalyzerErrors) <- liftIO $ analyzeWaspProject waspProjectDir (defaultCompileOptions waspProjectDir)
|
||||
appSpec <-
|
||||
either
|
||||
(throwError . CommandError "Determining dependencies failed due to a compilation error in your Wasp project" . unwords)
|
||||
(throwError . CommandError "Determining dependencies failed due to a compilation error in your Wasp project" . unwords . toList)
|
||||
return
|
||||
appSpecOrCompileErrors
|
||||
appSpecOrAnalyzerErrors
|
||||
|
||||
liftIO . putStrLn $ depsMessage appSpec
|
||||
|
||||
|
@ -15,6 +15,7 @@ import StrongPath
|
||||
Posix,
|
||||
Rel,
|
||||
relfile,
|
||||
(</>),
|
||||
)
|
||||
import StrongPath.TH (reldirP)
|
||||
import Wasp.AppSpec (AppSpec)
|
||||
|
@ -8,7 +8,8 @@ module Wasp.Lib
|
||||
where
|
||||
|
||||
import Data.List (find, isSuffixOf)
|
||||
import StrongPath (Abs, Dir, File', Path')
|
||||
import Data.List.NonEmpty (NonEmpty, fromList, toList)
|
||||
import StrongPath (Abs, Dir, File', Path', relfile)
|
||||
import qualified StrongPath as SP
|
||||
import System.Directory (doesDirectoryExist, doesFileExist)
|
||||
import qualified Wasp.Analyzer as Analyzer
|
||||
@ -36,9 +37,9 @@ compile ::
|
||||
CompileOptions ->
|
||||
IO ([CompileWarning], [CompileError])
|
||||
compile waspDir outDir options = do
|
||||
appSpecOrCompileErrors <- analyzeWaspProject waspDir options
|
||||
case appSpecOrCompileErrors of
|
||||
Left compileErrors -> return ([], compileErrors)
|
||||
(analyzerWarnings, appSpecOrAnalyzerErrors) <- analyzeWaspProject waspDir options
|
||||
compilerWarningsAndErrors <- case appSpecOrAnalyzerErrors of
|
||||
Left analyzerErrors -> return ([], toList analyzerErrors)
|
||||
Right appSpec ->
|
||||
case ASV.validateAppSpec appSpec of
|
||||
[] -> do
|
||||
@ -46,21 +47,23 @@ compile waspDir outDir options = do
|
||||
return (map show $ generatorWarningsFilter options generatorWarnings, map show generatorErrors)
|
||||
validationErrors -> do
|
||||
return ([], map show validationErrors)
|
||||
return $ (analyzerWarnings, []) <> compilerWarningsAndErrors
|
||||
|
||||
analyzeWaspProject ::
|
||||
Path' Abs (Dir WaspProjectDir) ->
|
||||
CompileOptions ->
|
||||
IO (Either [CompileError] AS.AppSpec)
|
||||
IO ([CompileWarning], Either (NonEmpty CompileError) AS.AppSpec)
|
||||
analyzeWaspProject waspDir options = do
|
||||
maybeWaspFilePath <- findWaspFile waspDir
|
||||
case maybeWaspFilePath of
|
||||
Nothing -> return $ Left ["Couldn't find a single *.wasp file."]
|
||||
appSpecOrAnalyzerErrors <- case maybeWaspFilePath of
|
||||
Nothing -> return $ Left $ fromList ["Couldn't find a single *.wasp file."]
|
||||
Just waspFilePath -> do
|
||||
waspFileContent <- readFile (SP.fromAbsFile waspFilePath)
|
||||
case Analyzer.analyze waspFileContent of
|
||||
Left analyzeError ->
|
||||
return $
|
||||
Left
|
||||
Left $
|
||||
fromList
|
||||
[ showCompilerErrorForTerminal
|
||||
(waspFilePath, waspFileContent)
|
||||
(getErrorMessageAndCtx analyzeError)
|
||||
@ -82,6 +85,16 @@ analyzeWaspProject waspDir options = do
|
||||
AS.dotEnvClientFile = maybeDotEnvClientFile,
|
||||
AS.isBuild = CompileOptions.isBuild options
|
||||
}
|
||||
analyzerWarnings <- warnIfDotEnvPresent waspDir
|
||||
return (analyzerWarnings, appSpecOrAnalyzerErrors)
|
||||
|
||||
-- | Checks the wasp directory for potential problems, and issues warnings if any are found.
|
||||
warnIfDotEnvPresent :: Path' Abs (Dir WaspProjectDir) -> IO [CompileWarning]
|
||||
warnIfDotEnvPresent waspDir = do
|
||||
maybeDotEnvFile <- findDotEnv waspDir
|
||||
case maybeDotEnvFile of
|
||||
Nothing -> return []
|
||||
Just _ -> return ["Wasp .env files should be named .env.server or .env.client, depending on their use."]
|
||||
|
||||
findWaspFile :: Path' Abs (Dir WaspProjectDir) -> IO (Maybe (Path' Abs File'))
|
||||
findWaspFile waspDir = do
|
||||
@ -98,6 +111,9 @@ findDotEnvServer waspDir = findFileInWaspProjectDir waspDir dotEnvServer
|
||||
findDotEnvClient :: Path' Abs (Dir WaspProjectDir) -> IO (Maybe (Path' Abs File'))
|
||||
findDotEnvClient waspDir = findFileInWaspProjectDir waspDir dotEnvClient
|
||||
|
||||
findDotEnv :: Path' Abs (Dir WaspProjectDir) -> IO (Maybe (Path' Abs File'))
|
||||
findDotEnv waspDir = findFileInWaspProjectDir waspDir [relfile|.env|]
|
||||
|
||||
findFileInWaspProjectDir ::
|
||||
Path' Abs (Dir WaspProjectDir) ->
|
||||
Path' (SP.Rel WaspProjectDir) File' ->
|
||||
|
Loading…
Reference in New Issue
Block a user