Skip to content

Commit

Permalink
Revert "Fix syntax error"
Browse files Browse the repository at this point in the history
This reverts commit a1842e8.
  • Loading branch information
sodic committed Sep 9, 2024
1 parent 4fbbf52 commit 78b2be9
Showing 1 changed file with 7 additions and 80 deletions.
87 changes: 7 additions & 80 deletions waspc/src/Wasp/Project/Analyze.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,13 @@ module Wasp.Project.Analyze
findWaspFile,
findPackageJsonFile,
analyzePrismaSchema,
WaspFile (..),
)
where

import Control.Applicative ((<|>))
import Control.Arrow (ArrowChoice (left))
import Control.Concurrent (newChan, readChan)
import Control.Concurrent.Async (concurrently)
import Control.Concurrent.Chan (Chan)
import Control.Monad.IO.Class (liftIO)
import qualified Data.Aeson as Aeson
import qualified Data.Conduit.Combinators as T
import Data.Conduit.Process.Typed (ExitCode (..))
import Data.List (find, isSuffixOf)
import qualified Data.Text as T
import StrongPath (Abs, Dir, File', Path', toFilePath, (</>))
import qualified StrongPath as SP
import StrongPath.Types (File)
import qualified Wasp.Analyzer as Analyzer
import Wasp.Analyzer.AnalyzeError (getErrorMessageAndCtx)
import Wasp.Analyzer.Parser.Ctx (Ctx)
Expand All @@ -34,10 +23,6 @@ import qualified Wasp.CompileOptions as CompileOptions
import qualified Wasp.ConfigFile as CF
import Wasp.Error (showCompilerErrorForTerminal)
import qualified Wasp.Generator.ConfigFile as G.CF
import qualified Wasp.Generator.Job as J
import Wasp.Generator.Job.IO (readJobMessagesAndPrintThemPrefixed)
import Wasp.Generator.Job.IO.PrefixedWriter (printJobMessagePrefixed, runPrefixedWriter)
import Wasp.Generator.Job.Process (runNodeCommandAsJob)
import Wasp.Project.Common
( CompileError,
CompileWarning,
Expand Down Expand Up @@ -84,57 +69,8 @@ analyzeWaspProject waspDir options = do
where
fileNotFoundMessage = "Couldn't find the *.wasp file in the " ++ toFilePath waspDir ++ " directory"

analyzeWaspFile :: Psl.Schema.Schema -> WaspFile -> IO (Either [CompileError] [AS.Decl])
analyzeWaspFile prismaSchemaAst = \case
WaspLangFile waspFilePath -> analyzeWaspLangFile prismaSchemaAst waspFilePath
WaspTsFile waspFilePath -> analyzeWaspTsFile prismaSchemaAst waspFilePath

analyzeWaspTsFile :: Psl.Schema.Schema -> Path' Abs File' -> IO (Either [CompileError] [AS.Decl])
analyzeWaspTsFile _prismaSchemaAst waspFilePath = do
let workingDir = SP.parent waspFilePath
chan <- newChan
(_, tscExitCode) <-
concurrently
(readJobMessagesAndPrintThemPrefixed chan)
(runNodeCommandAsJob workingDir "npx" ["tsc", "-p", "tsconfig.node.json"] J.Wasp chan)

case tscExitCode of
ExitFailure _status -> return $ Left ["Error while running TypeScript compiler on the *.wasp.mts file."]
ExitSuccess -> do
otherChan <- newChan
(_, runExitCode) <-
concurrently
(handleRunJsMessages otherChan)
( runNodeCommandAsJob
workingDir
"node"
[ SP.fromAbsDir workingDir ++ "node_modules/wasp-ts-sdk/dist/run.js",
SP.fromAbsDir workingDir ++ ".wasp/config/main.wasp.mjs"
]
J.Wasp
otherChan
)
case runExitCode of
ExitFailure _status -> return $ Left ["Error while running the compiled *.wasp.mts file."]
ExitSuccess -> return $ Right []
where
handleRunJsMessages :: Chan J.JobMessage -> IO ()
handleRunJsMessages = runPrefixedWriter . processMessages
processMessages chan = do
jobMsg <- liftIO $ readChan chan
case J._data jobMsg of
J.JobOutput payload J.Stdout -> do
-- let payload:: String = read $ T.unpack text
liftIO $ putStrLn "Ovo smo dobili na stdout"
-- parse payload as json
let json = Aeson.toJSON payload
liftIO $ print json
return ()
J.JobOutput _ J.Stderr -> printJobMessagePrefixed jobMsg >> processMessages chan
J.JobExit {} -> return ()

analyzeWaspLangFile :: Psl.Schema.Schema -> Path' Abs File' -> IO (Either [CompileError] [AS.Decl])
analyzeWaspLangFile prismaSchemaAst waspFilePath = do
analyzeWaspFile :: Psl.Schema.Schema -> Path' Abs File' -> IO (Either [CompileError] [AS.Decl])
analyzeWaspFile prismaSchemaAst waspFilePath = do
waspFileContent <- IOUtil.readFile waspFilePath
left (map $ showCompilerErrorForTerminal (waspFilePath, waspFileContent))
<$> analyzeWaspFileContent prismaSchemaAst waspFileContent
Expand Down Expand Up @@ -182,25 +118,16 @@ constructAppSpec waspDir options packageJson parsedPrismaSchema decls = do

return $ runValidation ASV.validateAppSpec appSpec

data WaspFile
= WaspLangFile {_path :: !(Path' Abs File')}
| WaspTsFile {_path :: !(Path' Abs File')}
deriving (Show)

findWaspFile :: Path' Abs (Dir WaspProjectDir) -> IO (Maybe WaspFile)
findWaspFile :: Path' Abs (Dir WaspProjectDir) -> IO (Maybe (Path' Abs File'))
findWaspFile waspDir = do
files <- fst <$> IOUtil.listDirectory waspDir
return $ findWaspTsFile files <|> findWaspLangFile files
return $ (waspDir </>) <$> find isWaspFile files
where
findWaspTsFile files = WaspTsFile . (waspDir </>) <$> find (`hasExtension` ".wasp.mts") files
findWaspLangFile files = WaspLangFile . (waspDir </>) <$> find isWaspLangFile files
isWaspLangFile path =
path `hasExtension` ".wasp"
isWaspFile path =
".wasp"
`isSuffixOf` toFilePath path
&& (length (toFilePath path) > length (".wasp" :: String))

hasExtension :: Path' s (File f) -> String -> Bool
hasExtension path ext = ext `isSuffixOf` toFilePath path

analyzePackageJsonContent :: Path' Abs (Dir WaspProjectDir) -> IO (Either [CompileError] PackageJson)
analyzePackageJsonContent waspProjectDir =
findPackageJsonFile waspProjectDir >>= \case
Expand Down

0 comments on commit 78b2be9

Please sign in to comment.