Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TS SDK Setup #2299

Merged
merged 26 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
8a4f788
Improve import
sodic Sep 18, 2024
ce3f118
Add ts-setup command
sodic Sep 18, 2024
4d7d8e7
Add t-setup module
sodic Sep 18, 2024
f14b617
Add wasp-config package
sodic Sep 18, 2024
2083bdb
Merge branch 'filip-ts-sdk' into filip-ts-sdk-setup
sodic Sep 18, 2024
40dbc78
Merge branch 'filip-ts-sdk' into filip-ts-sdk-setup
sodic Sep 30, 2024
934e8ae
Successfully receive entities in TS runtime
sodic Sep 30, 2024
384116a
Replicate Decls in TS wasp-config package
sodic Sep 30, 2024
f81a3e8
Implement AppSpec in TypeScript
sodic Oct 5, 2024
01fc493
Merge branch 'filip-ts-sdk' into filip-ts-sdk-setup
sodic Oct 5, 2024
30621f5
Fix minor issues with wasp-config pacakge
sodic Oct 7, 2024
30c3754
Refactor TS SDK
sodic Oct 7, 2024
ccfd371
Add more refactors to the TS SDK
sodic Oct 7, 2024
2f9981d
Remove console.log
sodic Oct 7, 2024
96f7bba
Merge branch 'filip-ts-sdk' into filip-ts-sdk-setup
sodic Oct 7, 2024
098d0c6
Fix compile error and change tsconfig name
sodic Oct 7, 2024
eddebd1
Merge branch 'filip-ts-sdk' into filip-ts-sdk-setup
sodic Oct 8, 2024
904b8ce
Merge branch 'filip-ts-sdk' into filip-ts-sdk-setup
sodic Oct 8, 2024
5041f55
Merge branch 'filip-ts-sdk' into filip-ts-sdk-setup
sodic Oct 9, 2024
acbd407
Merge branch 'filip-ts-sdk' into filip-ts-sdk-setup
sodic Oct 9, 2024
a77a7b0
Merge branch 'filip-ts-sdk' into filip-ts-sdk-setup
sodic Oct 9, 2024
eb44164
Merge branch 'filip-ts-sdk' into filip-ts-sdk-setup
sodic Oct 9, 2024
a91b88a
Improve TS SDK setup
sodic Oct 9, 2024
5894a58
Fixed small issues in TS SDK userApi.
Martinsos Oct 9, 2024
55690ae
Improve error message on missing default App export
sodic Oct 9, 2024
21cc896
Remove wasp-config path from package.json
sodic Oct 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions waspc/cli/exe/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import qualified Wasp.Cli.Command.Start.Db as Command.Start.Db
import Wasp.Cli.Command.Studio (studio)
import qualified Wasp.Cli.Command.Telemetry as Telemetry
import Wasp.Cli.Command.Test (test)
import Wasp.Cli.Command.TsConfigSetup (tsConfigSetup)
import Wasp.Cli.Command.Uninstall (uninstall)
import Wasp.Cli.Command.WaspLS (runWaspLS)
import Wasp.Cli.Message (cliSendMessage)
Expand All @@ -51,6 +52,7 @@ main = withUtf8 . (`E.catch` handleInternalErrors) $ do
["start"] -> Command.Call.Start
["start", "db"] -> Command.Call.StartDb
["clean"] -> Command.Call.Clean
["ts-setup"] -> Command.Call.TsSetup
sodic marked this conversation as resolved.
Show resolved Hide resolved
["compile"] -> Command.Call.Compile
("db" : dbArgs) -> Command.Call.Db dbArgs
["uninstall"] -> Command.Call.Uninstall
Expand Down Expand Up @@ -102,6 +104,7 @@ main = withUtf8 . (`E.catch` handleInternalErrors) $ do
Command.Call.Start -> runCommand start
Command.Call.StartDb -> runCommand Command.Start.Db.start
Command.Call.Clean -> runCommand clean
Command.Call.TsSetup -> runCommand tsConfigSetup
sodic marked this conversation as resolved.
Show resolved Hide resolved
Command.Call.Compile -> runCommand compile
Command.Call.Db dbArgs -> dbCli dbArgs
Command.Call.Version -> printVersion
Expand Down
1 change: 1 addition & 0 deletions waspc/cli/src/Wasp/Cli/Command/Call.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ data Call
| StartDb
| Clean
| Uninstall
| TsSetup
| Compile
| Db Arguments -- db args
| Build
Expand Down
2 changes: 1 addition & 1 deletion waspc/cli/src/Wasp/Cli/Command/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ module Wasp.Cli.Command.Common
)
where

import Control.Monad.Except
import qualified Control.Monad.Except as E
import Control.Monad.IO.Class (liftIO)
import StrongPath (Abs, Dir, Path')
import qualified StrongPath as SP
import StrongPath.Operations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import qualified Data.Text as T
import StrongPath (Abs, Dir, File, Path')
import Wasp.Cli.Command.CreateNewProject.Common (defaultWaspVersionBounds)
import Wasp.Cli.Command.CreateNewProject.ProjectDescription (NewProjectAppName, NewProjectName)
import Wasp.NodePackageFFI (InstallablePackage (WaspConfigPackage), getPackageInstallationPath)
import Wasp.Project.Analyze (WaspFilePath (..), findWaspFile)
import Wasp.Project.Common (WaspProjectDir)
import Wasp.Project.ExternalConfig.PackageJson (findPackageJsonFile)
Expand Down Expand Up @@ -43,8 +44,16 @@ replaceTemplatePlaceholdersInPackageJsonFile appName projectName projectDir =
Just absPackageJsonFile -> replaceTemplatePlaceholdersInFileOnDisk appName projectName absPackageJsonFile

replaceTemplatePlaceholdersInFileOnDisk :: NewProjectAppName -> NewProjectName -> Path' Abs (File f) -> IO ()
replaceTemplatePlaceholdersInFileOnDisk appName projectName =
updateFileContentWith (replacePlaceholders waspTemplateReplacements)
replaceTemplatePlaceholdersInFileOnDisk appName projectName file = do
waspConfigPackagePath <- getPackageInstallationPath WaspConfigPackage
let waspTemplateReplacements =
[ ("__waspConfigPath__", waspConfigPackagePath),
("__waspAppName__", show appName),
("__waspProjectName__", show projectName),
("__waspVersion__", defaultWaspVersionBounds)
]
-- TODO: We do this in all files, but not all files have all placeholders
sodic marked this conversation as resolved.
Show resolved Hide resolved
updateFileContentWith (replacePlaceholders waspTemplateReplacements) file
where
updateFileContentWith :: (Text -> Text) -> Path' Abs (File f) -> IO ()
updateFileContentWith updateFn absFilePath = IOUtil.readFileStrict absFilePath >>= IOUtil.writeFileFromText absFilePath . updateFn
Expand All @@ -53,9 +62,3 @@ replaceTemplatePlaceholdersInFileOnDisk appName projectName =
replacePlaceholders replacements content = foldl' replacePlaceholder content replacements
where
replacePlaceholder content' (placeholder, value) = T.replace (T.pack placeholder) (T.pack value) content'

waspTemplateReplacements =
[ ("__waspAppName__", show appName),
("__waspProjectName__", show projectName),
("__waspVersion__", defaultWaspVersionBounds)
]
38 changes: 38 additions & 0 deletions waspc/cli/src/Wasp/Cli/Command/TsConfigSetup.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
module Wasp.Cli.Command.TsConfigSetup (tsConfigSetup) where

import Control.Concurrent (Chan, newChan)
import Control.Concurrent.Async (concurrently)
import Control.Monad.Except (throwError)
import Control.Monad.IO.Class (liftIO)
import StrongPath (Abs, Dir, Path')
import System.Exit (ExitCode (..))
import Wasp.Cli.Command (Command, CommandError (..), require)
import Wasp.Cli.Command.Require (InWaspProject (InWaspProject))
import qualified Wasp.Generator.Job as J
import Wasp.Generator.Job.IO (readJobMessagesAndPrintThemPrefixed)
import Wasp.Generator.Job.Process (runNodeCommandAsJob)
import Wasp.NodePackageFFI (InstallablePackage (WaspConfigPackage), getPackageInstallationPath)

-- | Prepares the project for using Wasp's TypeScript SDK.
tsConfigSetup :: Command ()
tsConfigSetup = do
sodic marked this conversation as resolved.
Show resolved Hide resolved
InWaspProject waspProjectDir <- require
messageChan <- liftIO newChan
-- NOTE: We're also installing the user's package.json dependencies here
-- This is to provide proper IDE support for users working with the TS SDK
-- (it needs the `wasp-config` package).
liftIO (installWaspConfigPackage messageChan waspProjectDir)
>>= onLeftThrowError
where
onLeftThrowError = either (throwError . CommandError "npm install failed") pure

installWaspConfigPackage :: Chan J.JobMessage -> Path' Abs (Dir a) -> IO (Either String ())
installWaspConfigPackage chan projectDir = do
installationPath <- getPackageInstallationPath WaspConfigPackage
(_, exitCode) <-
concurrently
(readJobMessagesAndPrintThemPrefixed chan)
(runNodeCommandAsJob projectDir "npm" ["install", "--save-dev", "file:" ++ installationPath] J.Wasp chan)
return $ case exitCode of
ExitSuccess -> Right ()
ExitFailure _ -> Left "Failed to install wasp-config package"
4 changes: 4 additions & 0 deletions waspc/packages/wasp-config/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules/
dist/
.env
.vscode/
6 changes: 6 additions & 0 deletions waspc/packages/wasp-config/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"trailingComma": "es5",
"tabWidth": 2,
"semi": false,
"singleQuote": true
}
26 changes: 26 additions & 0 deletions waspc/packages/wasp-config/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import globals from "globals";
import pluginJs from "@eslint/js";
import tseslint from "typescript-eslint";

export default [
pluginJs.configs.recommended,
...tseslint.configs.strict,
// Todo: explore typed-linting: https://typescript-eslint.io/getting-started/typed-linting
sodic marked this conversation as resolved.
Show resolved Hide resolved
{
languageOptions: {
globals: globals.node,
},
},
// global ignore
{
ignores: ["node_modules/", "dist/"],
},
{
rules: {
"@typescript-eslint/no-unused-vars": "warn",
"@typescript-eslint/no-empty-function": "warn",
"no-empty": "warn",
"no-constant-condition": "warn",
},
},
];
6 changes: 6 additions & 0 deletions waspc/packages/wasp-config/nodemon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"watch": [
"./src/**/*.ts"
],
"exec": "tsc || exit 1"
}
Loading
Loading