From 42d486601fed37dfa24d6404c63feb72b616a3df Mon Sep 17 00:00:00 2001 From: Brett Goulder Date: Fri, 25 Feb 2022 12:42:17 -0800 Subject: [PATCH] feat: initialize repository on `apps init` --- cmd/meroxa/root/apps/init.go | 21 +++++++++++++++++++- cmd/meroxa/root/apps/init_test.go | 32 +++++++++++++++++++++++++++++++ go.mod | 1 + go.sum | 5 +++-- vendor/modules.txt | 2 ++ 5 files changed, 58 insertions(+), 3 deletions(-) diff --git a/cmd/meroxa/root/apps/init.go b/cmd/meroxa/root/apps/init.go index 951765d9a..d72e7912a 100644 --- a/cmd/meroxa/root/apps/init.go +++ b/cmd/meroxa/root/apps/init.go @@ -63,6 +63,20 @@ func (i *Init) ParseArgs(args []string) error { return nil } +func (i *Init) GitInit(ctx context.Context, path string) error { + if path == "" { + return errors.New("path is required") + } + + cmd := exec.Command("git", "init", path) + _, err := cmd.CombinedOutput() + if err != nil { + return err + } + + return nil +} + func (i *Init) Execute(ctx context.Context) error { name := i.args.appName lang := i.flags.Lang @@ -79,7 +93,7 @@ func (i *Init) Execute(ctx context.Context) error { i.logger.Infof(ctx, "Application successfully initialized!\n"+ "You can start interacting with Meroxa in your app located at \"%s/%s\"", i.path, name) case "js", JavaScript, NodeJs: - cmd := exec.Command("npx", "turbine_cli", "generate", name) + cmd := exec.Command("npx", "turbine", "generate", name) stdout, err := cmd.CombinedOutput() if err != nil { return err @@ -89,5 +103,10 @@ func (i *Init) Execute(ctx context.Context) error { return fmt.Errorf("language %q not supported. Currently, we support \"javascript\" and \"go\"", lang) } + err := i.GitInit(ctx, i.path+"/"+name) + if err != nil { + return err + } + return nil } diff --git a/cmd/meroxa/root/apps/init_test.go b/cmd/meroxa/root/apps/init_test.go index 3476a6d40..daf80c9e9 100644 --- a/cmd/meroxa/root/apps/init_test.go +++ b/cmd/meroxa/root/apps/init_test.go @@ -1,9 +1,12 @@ package apps import ( + "context" "errors" + "os" "testing" + "github.com/google/uuid" "github.com/meroxa/cli/cmd/meroxa/builder" "github.com/meroxa/cli/utils" ) @@ -68,3 +71,32 @@ func TestInitAppFlags(t *testing.T) { } } } + +func TestGitInit(t *testing.T) { + testDir := os.TempDir() + "/tests" + uuid.New().String() + + tests := []struct { + path string + err error + }{ + {path: "", err: errors.New("path is required")}, + {path: testDir, err: nil}, + } + + for _, tt := range tests { + cc := &Init{} + err := cc.GitInit(context.Background(), tt.path) + + if err != nil && tt.err.Error() != err.Error() { + t.Fatalf("expected \"%s\" got \"%s\"", tt.err, err) + } + + if tt.err == nil { + if _, err := os.Stat(testDir + "/.git"); os.IsNotExist(err) { + t.Fatalf("expected directory \"%s\" to be created", testDir) + } + } + } + + os.RemoveAll(testDir) +} diff --git a/go.mod b/go.mod index f31e9f844..5d4db2cb2 100644 --- a/go.mod +++ b/go.mod @@ -78,6 +78,7 @@ require ( google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c // indirect google.golang.org/grpc v1.42.0 // indirect google.golang.org/protobuf v1.27.1 // indirect + gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect gopkg.in/ini.v1 v1.62.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect ) diff --git a/go.sum b/go.sum index 0dae3502f..0700d2501 100644 --- a/go.sum +++ b/go.sum @@ -525,6 +525,7 @@ github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= +github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/pty v1.1.5/go.mod h1:9r2w37qlBe7rQ6e1fg1S/9xpWHSnaqNdHD3WcMdbPDA= @@ -609,7 +610,6 @@ github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8m github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw= github.com/ncw/swift v1.0.47/go.mod h1:23YIA4yWVnGwv2dQlN4bB7egfYX6YLn0Yo/S6zZO/ZM= -github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/nirasan/go-oauth-pkce-code-verifier v0.0.0-20170819232839-0fbfe93532da h1:qiPWuGGr+1GQE6s9NPSK8iggR/6x/V+0snIoOPYsBgc= github.com/nirasan/go-oauth-pkce-code-verifier v0.0.0-20170819232839-0fbfe93532da/go.mod h1:DvuJJ/w1Y59rG8UTDxsMk5U+UJXJwuvUgbiJSm9yhX8= @@ -1274,8 +1274,9 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/check.v1 v1.0.0-20141024133853-64131543e789/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU= gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= diff --git a/vendor/modules.txt b/vendor/modules.txt index 77422a3e1..4eb8d7e4e 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -334,6 +334,8 @@ google.golang.org/protobuf/types/descriptorpb google.golang.org/protobuf/types/known/anypb google.golang.org/protobuf/types/known/durationpb google.golang.org/protobuf/types/known/timestamppb +# gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c +## explicit; go 1.11 # gopkg.in/ini.v1 v1.62.0 ## explicit gopkg.in/ini.v1