Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions cmd/sst/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ var root = &cli.Command{
},
CmdDeploy,
CmdDiff,
CmdTypes,
{
Name: "add",
Description: cli.Description{
Expand Down
73 changes: 73 additions & 0 deletions cmd/sst/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package main

import (
"strings"

"github.com/sst/sst/v3/cmd/sst/cli"
"github.com/sst/sst/v3/cmd/sst/mosaic/ui"
"github.com/sst/sst/v3/pkg/types"
)

var CmdTypes = &cli.Command{
Name: "types",
Description: cli.Description{
Short: "Generate resource types",
Long: strings.Join([]string{
"Generate the types for the linked resources in your app.",
"",
"```bash frame=\"none\"",
"sst types",
"```",
"",
"This writes the `sst-env.d.ts` file that gives you typesafe access to your linked",
"resources in your code. If you are using a language other than JavaScript, it'll",
"also generate the equivalent; like the `sst.pyi` file for Python.",
"",
"These types are generated automatically as a part of `sst dev` and `sst deploy`.",
"So you typically don't need to run this. But it's useful when you want the types",
"without having to run your app.",
"",
"For example, in your CI pipeline or right after you pull down a teammate's changes;",
"where you want to typecheck before deploying.",
"",
"Generate the types for a specific stage by passing in the stage name.",
"",
"```bash frame=\"none\"",
"sst types --stage production",
"```",
"",
":::note",
"The types are based on what's been deployed. So the stage needs to have been",
"deployed at least once.",
":::",
}, "\n"),
},
Examples: []cli.Example{
{
Content: "sst types --stage production",
Description: cli.Description{
Short: "Generate types for production",
},
},
},
Run: func(c *cli.Cli) error {
p, err := c.InitProject()
if err != nil {
return err
}
defer p.Cleanup()

complete, err := p.GetCompleted(c.Context)
if err != nil {
return err
}

err = types.Generate(p.PathConfig(), complete.Links, p.App().Types.Ignore)
if err != nil {
return err
}

ui.Success("Generated types")
return nil
},
}
Loading