From 00020e0a4cd9b45c717a75a1c6528ce156227b7f Mon Sep 17 00:00:00 2001 From: pritesh-patel Date: Thu, 22 Aug 2019 11:22:31 -0700 Subject: [PATCH] split into seperate repos --- README.md | 18 ++++++++++++++++++ example/README.MD | 7 +++++++ .../sprout-example-go}/health/health.pb.go | 0 .../helloworld/helloworld.pb.go | 0 .../proto/health/health.proto | 0 .../proto/helloworld/helloworld.proto | 0 .../sprout-example-idl}/proto/prototool.yaml | 4 ++-- .../sprout-example}/server/health/health.go | 2 +- .../server/helloworld/helloworld.go | 2 +- example/sprout.yml | 4 ++-- generate/golang/generate.go | 9 ++++----- generate/proto/generate.go | 8 ++++---- templates/golang/health_server.tmpl | 2 +- templates/golang/server.tmpl | 2 +- templates/proto/prototool.tmpl | 2 +- 15 files changed, 42 insertions(+), 18 deletions(-) create mode 100644 example/README.MD rename example/{example/gen/go => sprout-example/sprout-example-go}/health/health.pb.go (100%) rename example/{example/gen/go => sprout-example/sprout-example-go}/helloworld/helloworld.pb.go (100%) rename example/{example/idl => sprout-example/sprout-example-idl}/proto/health/health.proto (100%) rename example/{example/idl => sprout-example/sprout-example-idl}/proto/helloworld/helloworld.proto (100%) rename example/{example/idl => sprout-example/sprout-example-idl}/proto/prototool.yaml (85%) rename example/{example => sprout-example/sprout-example}/server/health/health.go (87%) rename example/{example => sprout-example/sprout-example}/server/helloworld/helloworld.go (54%) diff --git a/README.md b/README.md index 47fda6d6b..c869c5da8 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,24 @@ Based on specified config it will generate: It will also live with your project, when you add a new service to the config it will generate everything needed for that new service. +The generation will create a folder with 3 repos within it. + +* A rep for the IDL's +* A repo that has the generated artifacts from the IDL +* A repo that implements the interfaces of the generated artifacts + +NOTE: It only creates the folders for these repos, you will still need to create the git repos on your respected platform. Aswell as initialise each folder as a git repo and push when there have been changes. (if there is a strong desire we can look at how to make this process easier.) + +The dev process: + +1) Setup sprout config & run generation +2) Start adding your desired methods to the protobuf files generated +3) Rerun generation +4) Push the idl and the language generated repo +5) Implement these methods on the main application repo +6) When you feel the need to add more services add them to the sprout config +7) Repeat steps 1 - 5 + ## Dependencies In order to use this you need ensure you have these installed. diff --git a/example/README.MD b/example/README.MD new file mode 100644 index 000000000..2f4249ebf --- /dev/null +++ b/example/README.MD @@ -0,0 +1,7 @@ +# Example + +You can find the generated repos from this example here: + +* sprout-example +* sprout-example-idl +* sprout-example-go \ No newline at end of file diff --git a/example/example/gen/go/health/health.pb.go b/example/sprout-example/sprout-example-go/health/health.pb.go similarity index 100% rename from example/example/gen/go/health/health.pb.go rename to example/sprout-example/sprout-example-go/health/health.pb.go diff --git a/example/example/gen/go/helloworld/helloworld.pb.go b/example/sprout-example/sprout-example-go/helloworld/helloworld.pb.go similarity index 100% rename from example/example/gen/go/helloworld/helloworld.pb.go rename to example/sprout-example/sprout-example-go/helloworld/helloworld.pb.go diff --git a/example/example/idl/proto/health/health.proto b/example/sprout-example/sprout-example-idl/proto/health/health.proto similarity index 100% rename from example/example/idl/proto/health/health.proto rename to example/sprout-example/sprout-example-idl/proto/health/health.proto diff --git a/example/example/idl/proto/helloworld/helloworld.proto b/example/sprout-example/sprout-example-idl/proto/helloworld/helloworld.proto similarity index 100% rename from example/example/idl/proto/helloworld/helloworld.proto rename to example/sprout-example/sprout-example-idl/proto/helloworld/helloworld.proto diff --git a/example/example/idl/proto/prototool.yaml b/example/sprout-example/sprout-example-idl/proto/prototool.yaml similarity index 85% rename from example/example/idl/proto/prototool.yaml rename to example/sprout-example/sprout-example-idl/proto/prototool.yaml index 1f7940ef0..516c1325a 100644 --- a/example/example/idl/proto/prototool.yaml +++ b/example/sprout-example/sprout-example-idl/proto/prototool.yaml @@ -11,7 +11,7 @@ create: generate: go_options: - import_path: github.com/commitdev/example/example + import_path: github.com/commitdev extra_modifiers: google/api/annotations.proto: google.golang.org/genproto/googleapis/api/annotations google/api/http.proto: google.golang.org/genproto/googleapis/api/annotations @@ -19,4 +19,4 @@ generate: - name: go type: go flags: plugins=grpc - output: ../../gen/go + output: ../../sprout-example-go diff --git a/example/example/server/health/health.go b/example/sprout-example/sprout-example/server/health/health.go similarity index 87% rename from example/example/server/health/health.go rename to example/sprout-example/sprout-example/server/health/health.go index 5baa0b053..b57b08187 100644 --- a/example/example/server/health/health.go +++ b/example/sprout-example/sprout-example/server/health/health.go @@ -2,7 +2,7 @@ package health import ( "context" - api "github.com/commitdev/example/example/gen/go/health" + api "github.com/commitdev/sprout-example-go/health" ) type HealthServer struct { diff --git a/example/example/server/helloworld/helloworld.go b/example/sprout-example/sprout-example/server/helloworld/helloworld.go similarity index 54% rename from example/example/server/helloworld/helloworld.go rename to example/sprout-example/sprout-example/server/helloworld/helloworld.go index 2d77b67c5..f6a71744f 100644 --- a/example/example/server/helloworld/helloworld.go +++ b/example/sprout-example/sprout-example/server/helloworld/helloworld.go @@ -2,7 +2,7 @@ package helloworld import ( "context" - api "github.com/commitdev/example/example/gen/go/helloworld" + api "github.com/commitdev/sprout-example-go/helloworld" ) type HelloworldServer struct { diff --git a/example/sprout.yml b/example/sprout.yml index ca22a0843..996ee4d53 100644 --- a/example/sprout.yml +++ b/example/sprout.yml @@ -1,7 +1,7 @@ organization: mycompany -name: example +name: sprout-example description: This is a test project -git-repo: github.com/commitdev/example/example +git-repo: github.com/commitdev docker-repo: test.com maintainers: - name: bob diff --git a/generate/golang/generate.go b/generate/golang/generate.go index 085a307d6..bfb85e03c 100644 --- a/generate/golang/generate.go +++ b/generate/golang/generate.go @@ -17,7 +17,7 @@ func Generate(templator *templator.Templator, config *config.SproutConfig, outPa } func GenerateServers(templator *templator.Templator, config *config.SproutConfig, outPath string) { - serverDirPath := fmt.Sprintf("%s/%s/server", outPath, config.Name) + serverDirPath := fmt.Sprintf("%s/%s/%s/server", outPath, config.Name, config.Name) err := util.CreateDirIfDoesNotExist(serverDirPath) if err != nil { log.Printf("Error creating server path: %v", err) @@ -43,6 +43,7 @@ func GenerateServers(templator *templator.Templator, config *config.SproutConfig } data := map[string]string { + "ProjectName": config.Name, "ServiceName": s.Name, "GitRepo": config.GitRepo, } @@ -53,7 +54,7 @@ func GenerateServers(templator *templator.Templator, config *config.SproutConfig } func GenerateHealthServer(templator *templator.Templator, config *config.SproutConfig, outPath string) { - serverDirPath := fmt.Sprintf("%s/%s/server", outPath, config.Name) + serverDirPath := fmt.Sprintf("%s/%s/%s/server", outPath, config.Name, config.Name) err := util.CreateDirIfDoesNotExist(serverDirPath) if err != nil { log.Printf("Error creating server path: %v", err) @@ -72,7 +73,5 @@ func GenerateHealthServer(templator *templator.Templator, config *config.SproutC log.Printf("Error: %v", err) } - importPath := fmt.Sprintf("%s/gen/go/health", config.GitRepo) - - templator.Go.GoHealthServer.Execute(f, importPath) + templator.Go.GoHealthServer.Execute(f, config) } diff --git a/generate/proto/generate.go b/generate/proto/generate.go index 1292ecab8..782a046e1 100644 --- a/generate/proto/generate.go +++ b/generate/proto/generate.go @@ -19,7 +19,7 @@ func Generate(templator *templator.Templator, config *config.SproutConfig, outPa } func GenerateProtoToolConfig(templator *templator.Templator, config *config.SproutConfig, outPath string) { - protoPath := fmt.Sprintf("%s/%s/idl/proto", outPath, config.Name) + protoPath := fmt.Sprintf("%s/%s/%s-idl/proto", outPath, config.Name, config.Name) protoToolOutput := fmt.Sprintf("%s/prototool.yaml", protoPath) err := util.CreateDirIfDoesNotExist(protoPath) @@ -35,7 +35,7 @@ func GenerateProtoToolConfig(templator *templator.Templator, config *config.Spro } func GenerateProtoHealth(templator *templator.Templator, config *config.SproutConfig, outPath string) { - protoHealthPath := fmt.Sprintf("%s/%s/idl/proto/health", outPath, config.Name) + protoHealthPath := fmt.Sprintf("%s/%s/%s-idl/proto/health", outPath, config.Name, config.Name) protoHealthOutput := fmt.Sprintf("%s/health.proto", protoHealthPath) err := util.CreateDirIfDoesNotExist(protoHealthPath) @@ -52,7 +52,7 @@ func GenerateProtoHealth(templator *templator.Templator, config *config.SproutCo } func GenerateProtoServices(templator *templator.Templator, config *config.SproutConfig, outPath string) { - protoToolConfigPath := fmt.Sprintf("%s/%s/idl/proto", outPath, config.Name) + protoToolConfigPath := fmt.Sprintf("%s/%s/%s-idl/proto", outPath, config.Name, config.Name) for _, s := range config.Services { idlPath := fmt.Sprintf("%s/%s", protoToolConfigPath, s.Name) err := util.CreateDirIfDoesNotExist(idlPath) @@ -70,7 +70,7 @@ func GenerateProtoServices(templator *templator.Templator, config *config.Sprout } func GenerateProtoServiceLibs(config *config.SproutConfig, outPath string) { - protoToolConfigPath := fmt.Sprintf("%s/%s/idl/proto", outPath, config.Name) + protoToolConfigPath := fmt.Sprintf("%s/%s/%s-idl/proto", outPath, config.Name, config.Name) cmd := exec.Command("prototool", "generate") cmd.Dir = protoToolConfigPath err := cmd.Run() diff --git a/templates/golang/health_server.tmpl b/templates/golang/health_server.tmpl index caaf80800..ca006c832 100644 --- a/templates/golang/health_server.tmpl +++ b/templates/golang/health_server.tmpl @@ -2,7 +2,7 @@ package health import ( "context" - api "{{ . }}" + api "{{ .GitRepo }}/{{ .Name }}-go/health" ) type HealthServer struct { diff --git a/templates/golang/server.tmpl b/templates/golang/server.tmpl index 88b641bf2..752cd0e0b 100644 --- a/templates/golang/server.tmpl +++ b/templates/golang/server.tmpl @@ -2,7 +2,7 @@ package {{ .ServiceName }} import ( "context" - api "{{.GitRepo}}/gen/go/{{ .ServiceName }}" + api "{{.GitRepo}}/{{ .ProjectName }}-go/{{ .ServiceName }}" ) type {{ .ServiceName | Title }}Server struct { diff --git a/templates/proto/prototool.tmpl b/templates/proto/prototool.tmpl index 9f5b4a346..e8c5fdb8e 100644 --- a/templates/proto/prototool.tmpl +++ b/templates/proto/prototool.tmpl @@ -22,4 +22,4 @@ generate: - name: go type: go flags: plugins=grpc - output: ../../gen/go + output: ../../{{ .Name }}-go