From 952d520306f06114899e4506c3c892db60778cf9 Mon Sep 17 00:00:00 2001 From: joel Date: Sat, 6 Apr 2024 15:14:21 +0800 Subject: [PATCH] feat:initial commit --- internal/bootstrap/bootstrap.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/internal/bootstrap/bootstrap.go b/internal/bootstrap/bootstrap.go index 68832b076..0c11e80f3 100644 --- a/internal/bootstrap/bootstrap.go +++ b/internal/bootstrap/bootstrap.go @@ -34,6 +34,17 @@ import ( "golang.org/x/term" ) +type Sample struct { + Name string `json:"name"` + Description string `json:"description"` + URL string `json:"url"` + Start string `json:"start"` +} + +type SamplesFile struct { + Samples []Sample `json:"samples"` +} + func Run(ctx context.Context, templateUrl string, fsys afero.Fs, options ...func(*pgx.ConnConfig)) error { workdir := viper.GetString("WORKDIR") if !filepath.IsAbs(workdir) { @@ -137,6 +148,21 @@ func suggestAppStart(cwd string) string { if len(workdir) > 0 && workdir != "." { cmd = append(cmd, "cd "+workdir) } + fileBytes, err := ioutil.ReadFile("samples.json") + if err != nil { + log.Fatalf("failed to read file: %v", err) + } + + var samples SamplesFile + err = json.Unmarshal(fileBytes, &samples) + if err != nil { + log.Fatalf("failed to unmarshal JSON: %v", err) + } + + for _, sample := range samples.Samples { + fmt.Printf("To start your app run:", sample.Start) + } + // TODO: refactor this part properly cmd = append(cmd, "npm ci", "npm run dev") suggestion := "To start your app:" for _, c := range cmd {