-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
Implement the TS SDK as a preview feature.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ data Call | |
| StartDb | ||
| Clean | ||
| Uninstall | ||
| TsSetup | ||
| Compile | ||
| Db Arguments -- db args | ||
| Build | ||
|
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 | ||
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" |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
node_modules/ | ||
dist/ | ||
.env | ||
.vscode/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"trailingComma": "es5", | ||
"tabWidth": 2, | ||
"semi": false, | ||
"singleQuote": true | ||
} |
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 | ||
{ | ||
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", | ||
}, | ||
}, | ||
]; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"watch": [ | ||
"./src/**/*.ts" | ||
], | ||
"exec": "tsc || exit 1" | ||
} |