Skip to content

Commit

Permalink
handle v2 config
Browse files Browse the repository at this point in the history
  • Loading branch information
thdxr committed Mar 16, 2024
1 parent 7755fec commit e25a95d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
7 changes: 5 additions & 2 deletions cmd/sst/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ import (
)

func TransformError(err error) error {
mapping := map[error]string{}
mapping[project.ErrInvalidStageName] = "The stage name is invalid. It can only contain alphanumeric characters and hyphens."
mapping := map[error]string{
project.ErrInvalidStageName: "The stage name is invalid. It can only contain alphanumeric characters and hyphens.",
project.ErrV2Config: "You are using sst ion and this looks like an sst v2 config",
}

match, ok := mapping[err]
if !ok {
return err
Expand Down
1 change: 0 additions & 1 deletion cmd/sst/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ func main() {
}
} else {
fmt.Println("Unexpected error occurred. Please check the logs for more details.")
fmt.Println(err.Error())
}
os.Exit(1)
}
Expand Down
10 changes: 9 additions & 1 deletion pkg/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ type ProjectConfig struct {
Config string
}

var ErrInvalidStageName = fmt.Errorf("Invalid stage name")
var ErrInvalidStageName = fmt.Errorf("invalid stage name")
var ErrV2Config = fmt.Errorf("sstv2 config detected")
var StageRegex = regexp.MustCompile(`^[a-zA-Z0-9-]+$`)

func New(input *ProjectConfig) (*Project, error) {
Expand Down Expand Up @@ -123,6 +124,10 @@ func New(input *ProjectConfig) (*Project, error) {
},
Code: fmt.Sprintf(`
import mod from '%s';
if (mod.stacks || mod.config) {
console.log("v2")
process.exit(0)
}
console.log("~j" + JSON.stringify(mod.app({
stage: $input.stage || undefined,
})))`,
Expand All @@ -140,6 +145,9 @@ console.log("~j" + JSON.stringify(mod.app({
break
}

if cmd == js.CommandStdOut && line == "v2" {
return nil, ErrV2Config
}
if cmd != js.CommandJSON {
fmt.Println(line)
continue
Expand Down

0 comments on commit e25a95d

Please sign in to comment.