Skip to content

Commit

Permalink
Merge branch 'filip-ts-sdk' into filip-ts-sdk-setup
Browse files Browse the repository at this point in the history
  • Loading branch information
sodic committed Oct 9, 2024
2 parents 904b8ce + 67f1f9e commit 5041f55
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 44 deletions.
6 changes: 3 additions & 3 deletions waspc/src/Wasp/Generator/ExternalConfig/TsConfig.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{-# LANGUAGE FlexibleInstances #-}

module Wasp.Generator.ExternalConfig.TsConfig
( validateTsConfig,
( validateSrcTsConfig,
)
where

Expand All @@ -23,8 +23,8 @@ instance IsJavascriptValue Bool where

type FieldName = String

validateTsConfig :: T.TsConfig -> [ErrorMsg]
validateTsConfig tsConfig =
validateSrcTsConfig :: T.TsConfig -> [ErrorMsg]
validateSrcTsConfig tsConfig =
concat
[ validateRequiredFieldInCompilerOptions "module" "esnext" T._module,
validateRequiredFieldInCompilerOptions "target" "esnext" T.target,
Expand Down
14 changes: 5 additions & 9 deletions waspc/src/Wasp/Project/Analyze.hs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,13 @@ import Wasp.Generator.Job.Process (runNodeCommandAsJob)
import Wasp.Project.Common
( CompileError,
CompileWarning,
WaspFilePath (..),
WaspLangFile,
WaspProjectDir,
WaspTsFile,
dotWaspDirInWaspProjectDir,
findFileInWaspProjectDir,
getSrcTsConfigInWaspProjectDir,
prismaSchemaFileInWaspProjectDir,
)
import Wasp.Project.Db (makeDevDatabaseUrl)
Expand Down Expand Up @@ -85,18 +89,10 @@ analyzeWaspProject waspDir options = do
analyzeWaspFile waspDir prismaSchemaAst waspFilePath >>= \case
Left errors -> return (Left errors, [])
Right declarations ->
EC.analyzeExternalConfigs waspDir >>= \case
EC.analyzeExternalConfigs waspDir (getSrcTsConfigInWaspProjectDir waspFilePath) >>= \case
Left errors -> return (Left errors, [])
Right externalConfigs -> constructAppSpec waspDir options externalConfigs prismaSchemaAst declarations

data WaspFilePath
= WaspLang !(Path' Abs (File WaspLangFile))
| WaspTs !(Path' Abs (File WaspTsFile))

data WaspLangFile

data WaspTsFile

data CompiledWaspJsFile

data AppSpecDeclsJsonFile
Expand Down
28 changes: 18 additions & 10 deletions waspc/src/Wasp/Project/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ module Wasp.Project.Common
CompileError,
CompileWarning,
PackageJsonFile,
TsConfigFile,
SrcTsConfigFile,
WaspFilePath (..),
WaspLangFile,
WaspTsFile,
findFileInWaspProjectDir,
dotWaspDirInWaspProjectDir,
generatedCodeDirInDotWaspDir,
Expand All @@ -18,9 +21,8 @@ module Wasp.Project.Common
nodeModulesDirInWaspProjectDir,
srcDirInWaspProjectDir,
extPublicDirInWaspProjectDir,
tsconfigInWaspProjectDir,
prismaSchemaFileInWaspProjectDir,
tsConfigInWaspProjectDir,
getSrcTsConfigInWaspProjectDir,
)
where

Expand All @@ -41,7 +43,15 @@ data DotWaspDir -- Here we put everything that wasp generates.

data PackageJsonFile

data TsConfigFile
data SrcTsConfigFile

data WaspFilePath
= WaspLang !(Path' Abs (File WaspLangFile))
| WaspTs !(Path' Abs (File WaspTsFile))

data WaspLangFile

data WaspTsFile

-- | NOTE: If you change the depth of this path, also update @waspProjectDirFromProjectRootDir@ below.
-- TODO: SHould this be renamed to include word "root"?
Expand Down Expand Up @@ -76,9 +86,10 @@ dotWaspInfoFileInGeneratedCodeDir = [relfile|.waspinfo|]
packageJsonInWaspProjectDir :: Path' (Rel WaspProjectDir) (File PackageJsonFile)
packageJsonInWaspProjectDir = [relfile|package.json|]

-- TODO: Do this properly
tsConfigInWaspProjectDir :: Path' (Rel WaspProjectDir) (File TsConfigFile)
tsConfigInWaspProjectDir = [relfile|tsconfig.src.json|]
getSrcTsConfigInWaspProjectDir :: WaspFilePath -> Path' (Rel WaspProjectDir) (File SrcTsConfigFile)
getSrcTsConfigInWaspProjectDir = \case
WaspTs _ -> [relfile|tsconfig.src.json|]
WaspLang _ -> [relfile|tsconfig.json|]

packageLockJsonInWaspProjectDir :: Path' (Rel WaspProjectDir) File'
packageLockJsonInWaspProjectDir = [relfile|package-lock.json|]
Expand All @@ -92,9 +103,6 @@ srcDirInWaspProjectDir = [reldir|src|]
extPublicDirInWaspProjectDir :: Path' (Rel WaspProjectDir) (Dir SourceExternalPublicDir)
extPublicDirInWaspProjectDir = [reldir|public|]

tsconfigInWaspProjectDir :: Path' (Rel WaspProjectDir) File'
tsconfigInWaspProjectDir = [relfile|tsconfig.json|]

findFileInWaspProjectDir ::
Path' Abs (Dir WaspProjectDir) ->
Path' (Rel WaspProjectDir) (File f) ->
Expand Down
14 changes: 9 additions & 5 deletions waspc/src/Wasp/Project/ExternalConfig.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,30 @@ module Wasp.Project.ExternalConfig
where

import Control.Monad.Except (ExceptT (ExceptT), runExceptT)
import StrongPath (Abs, Dir, Path')
import StrongPath (Abs, Dir, File, Path', Rel)
import qualified Wasp.ExternalConfig.PackageJson as P
import qualified Wasp.ExternalConfig.TsConfig as T
import Wasp.Project.Common
( CompileError,
SrcTsConfigFile,
WaspProjectDir,
)
import Wasp.Project.ExternalConfig.PackageJson (analyzePackageJsonFile)
import Wasp.Project.ExternalConfig.TsConfig (analyzeTsConfigFile)
import Wasp.Project.ExternalConfig.TsConfig (analyzeSrcTsConfigFile)

data ExternalConfigs = ExternalConfigs
{ _packageJson :: P.PackageJson,
_tsConfig :: T.TsConfig
}
deriving (Show)

analyzeExternalConfigs :: Path' Abs (Dir WaspProjectDir) -> IO (Either [CompileError] ExternalConfigs)
analyzeExternalConfigs waspDir = runExceptT $ do
analyzeExternalConfigs ::
Path' Abs (Dir WaspProjectDir) ->
Path' (Rel WaspProjectDir) (File SrcTsConfigFile) ->
IO (Either [CompileError] ExternalConfigs)
analyzeExternalConfigs waspDir srcTsConfigFile = runExceptT $ do
packageJsonContent <- ExceptT $ analyzePackageJsonFile waspDir
tsConfigContent <- ExceptT $ analyzeTsConfigFile waspDir
tsConfigContent <- ExceptT $ analyzeSrcTsConfigFile waspDir srcTsConfigFile

return $
ExternalConfigs
Expand Down
33 changes: 16 additions & 17 deletions waspc/src/Wasp/Project/ExternalConfig/TsConfig.hs
Original file line number Diff line number Diff line change
@@ -1,39 +1,38 @@
module Wasp.Project.ExternalConfig.TsConfig
( analyzeTsConfigFile,
( analyzeSrcTsConfigFile,
)
where

import Control.Monad.Except (ExceptT (ExceptT), runExceptT, throwError)
import qualified Data.ByteString.Lazy.UTF8 as BS
import Data.Either.Extra (maybeToEither)
import StrongPath (Abs, Dir, File, Path', toFilePath)
import StrongPath (Abs, Dir, File, Path', Rel, toFilePath)
import qualified Wasp.ExternalConfig.TsConfig as T
import Wasp.Generator.ExternalConfig.TsConfig (validateTsConfig)
import Wasp.Generator.ExternalConfig.TsConfig (validateSrcTsConfig)
import Wasp.Project.Common
( TsConfigFile,
( SrcTsConfigFile,
WaspProjectDir,
findFileInWaspProjectDir,
tsConfigInWaspProjectDir,
)
import qualified Wasp.Util.IO as IOUtil
import Wasp.Util.Json (parseJsonWithComments)

analyzeTsConfigFile :: Path' Abs (Dir WaspProjectDir) -> IO (Either [String] T.TsConfig)
analyzeTsConfigFile waspDir = runExceptT $ do
tsConfigFile <- ExceptT findTsConfigOrError
tsConfig <- ExceptT $ readTsConfigFile tsConfigFile
case validateTsConfig tsConfig of
[] -> return tsConfig
analyzeSrcTsConfigFile ::
Path' Abs (Dir WaspProjectDir) ->
Path' (Rel WaspProjectDir) (File SrcTsConfigFile) ->
IO (Either [String] T.TsConfig)
analyzeSrcTsConfigFile waspDir srcTsConfigFile = runExceptT $ do
tsConfigFileContents <- ExceptT findTsConfigOrError
srcTsConfigContents <- ExceptT $ readSrcTsConfigFile tsConfigFileContents
case validateSrcTsConfig srcTsConfigContents of
[] -> return srcTsConfigContents
errors -> throwError errors
where
findTsConfigOrError = maybeToEither [fileNotFoundMessage] <$> findTsConfigFile waspDir
findTsConfigOrError = maybeToEither [fileNotFoundMessage] <$> findFileInWaspProjectDir waspDir srcTsConfigFile
fileNotFoundMessage = "Couldn't find the tsconfig.json file in the " ++ toFilePath waspDir ++ " directory"

findTsConfigFile :: Path' Abs (Dir WaspProjectDir) -> IO (Maybe (Path' Abs (File TsConfigFile)))
findTsConfigFile waspProjectDir = findFileInWaspProjectDir waspProjectDir tsConfigInWaspProjectDir

readTsConfigFile :: Path' Abs (File TsConfigFile) -> IO (Either [String] T.TsConfig)
readTsConfigFile tsConfigFile = do
readSrcTsConfigFile :: Path' Abs (File SrcTsConfigFile) -> IO (Either [String] T.TsConfig)
readSrcTsConfigFile tsConfigFile = do
tsConfigContent <- IOUtil.readFileBytes tsConfigFile

parseResult <- parseJsonWithComments . BS.toString $ tsConfigContent
Expand Down

0 comments on commit 5041f55

Please sign in to comment.