Skip to content

Commit 41a5fae

Browse files
committed
file structure changes
1 parent ebdd304 commit 41a5fae

File tree

22 files changed

+129
-60
lines changed

22 files changed

+129
-60
lines changed

Makefile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,14 @@ build:
1414
packr2 clean
1515

1616
build-example:
17-
./sprout generate -c example/sprout.yml -l go -o example
17+
mkdir -p example
18+
cd example && ../sprout create -p "hello-world"
19+
cd example/hello-world && ../../sprout generate -l go
1820

1921
clean-example:
20-
rm -rf example/example
22+
rm -rf example
23+
24+
install-linux: build
25+
mkdir -p ${HOME}/bin
26+
cp sprout ${HOME}/bin/sprout
27+
chmod +x ${HOME}/bin/sprout

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,23 @@ It will also live with your project, when you add a new service to the config it
1818

1919
## What does it generate?
2020

21-
The generation will create a folder with 3 repos within it.
21+
The generation will create 2 folders.
2222

23-
* A rep for the IDL's
24-
* A repo that has the generated artifacts from the IDL
23+
* A rep for the IDL's, this folder will also contain generated artifacts from the IDL under 'gen'
2524
* A repo that implements the interfaces of the generated artifacts
2625

2726
`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.)`
2827

2928
## The development cycle
3029

31-
1) Setup sprout config & run generation
32-
2) Start adding your desired methods to the protobuf files generated
33-
3) Rerun generation
34-
4) Push the idl and the language generated repo
35-
5) Implement these methods on the main application repo
36-
6) When you feel the need to add more services add them to the sprout config
37-
7) Repeat steps 1 - 5
30+
1) Make folder and within that folder execute `sprout create [PROJECT_NAME]`
31+
2) A folder will be created and within that update the `sprout.yml` and then run `sprout generate -l=[LANGUAGE OF CHOICE]`
32+
3) Move back to the root folder and you will see that there is now an idl folder created.
33+
4) Modify the the protobuf services generated with your desired methods
34+
5) Either run `prototool generate` or return to the application folder and re run `sprout generate`
35+
6) Push up the IDL repo
36+
6) Implement these methods on the main application repo
37+
7) When you feel the need to add more services add them to the sprout config and repeate the generation process
3838

3939
## Dependencies
4040

cmd/create.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package cmd
2+
3+
import (
4+
"log"
5+
"os"
6+
"fmt"
7+
8+
9+
"github.com/spf13/cobra"
10+
)
11+
12+
var projectName string
13+
14+
func init() {
15+
16+
createCmd.PersistentFlags().StringVarP(&projectName, "project-name", "p", "", "project name")
17+
18+
rootCmd.AddCommand(createCmd)
19+
}
20+
21+
var createCmd = &cobra.Command{
22+
Use: "create",
23+
Short: "Create new project.",
24+
Run: func(cmd *cobra.Command, args []string) {
25+
26+
err := os.Mkdir(projectName, os.ModePerm)
27+
if os.IsExist(err){
28+
log.Fatalf("Directory %v already exists!", projectName)
29+
}
30+
31+
sproutConfigPath := fmt.Sprintf("%v/sprout.yml", projectName)
32+
33+
f, err := os.Create(sproutConfigPath)
34+
if err != nil {
35+
log.Printf("Error creating sprout config: %v", err)
36+
}
37+
38+
Templator.Sprout.Execute(f, projectName)
39+
},
40+
}

cmd/generate.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
)
1111

1212
var configPath string
13-
var outputPath string
1413
var language string
1514

1615
const (
@@ -22,15 +21,14 @@ var supportedLanguages = [...]string{Go}
2221
func init() {
2322

2423
generateCmd.PersistentFlags().StringVarP(&configPath, "config", "c", "sprout.yml", "config path")
25-
generateCmd.PersistentFlags().StringVarP(&outputPath, "output-path", "o", "./", "config path")
2624
generateCmd.PersistentFlags().StringVarP(&language, "language", "l", "", "language to generate project in")
2725

2826
rootCmd.AddCommand(generateCmd)
2927
}
3028

3129
var generateCmd = &cobra.Command{
3230
Use: "generate",
33-
Short: "Generate project from config.",
31+
Short: "Generate idl & application folders",
3432
Run: func(cmd *cobra.Command, args []string) {
3533
if !ValidLanguage() {
3634
log.Fatalf("'%s' is not a supported language.", language)
@@ -39,11 +37,11 @@ var generateCmd = &cobra.Command{
3937
cfg := config.LoadConfig(configPath)
4038
cfg.Print()
4139

42-
proto.Generate(Templator, cfg, outputPath)
40+
proto.Generate(Templator, cfg)
4341

4442
switch language {
4543
case Go:
46-
golang.Generate(Templator, cfg, outputPath)
44+
golang.Generate(Templator, cfg)
4745

4846
}
4947
},

example/README.MD

Lines changed: 0 additions & 7 deletions
This file was deleted.

example/sprout-example/sprout-example-go/health/health.pb.go renamed to example/hello-world-idl/gen/go/health/health.pb.go

File renamed without changes.

example/sprout-example/sprout-example-go/helloworld/helloworld.pb.go renamed to example/hello-world-idl/gen/go/helloworld/helloworld.pb.go

File renamed without changes.

example/sprout-example/sprout-example-idl/proto/health/health.proto renamed to example/hello-world-idl/proto/health/health.proto

File renamed without changes.

example/sprout-example/sprout-example-idl/proto/helloworld/helloworld.proto renamed to example/hello-world-idl/proto/helloworld/helloworld.proto

File renamed without changes.

example/sprout-example/sprout-example-idl/proto/prototool.yaml renamed to example/hello-world-idl/proto/prototool.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ create:
1111

1212
generate:
1313
go_options:
14-
import_path: github.com/commitdev
14+
import_path: github.com/yourrepo
1515
extra_modifiers:
1616
google/api/annotations.proto: google.golang.org/genproto/googleapis/api/annotations
1717
google/api/http.proto: google.golang.org/genproto/googleapis/api/annotations
1818
plugins:
1919
- name: go
2020
type: go
2121
flags: plugins=grpc
22-
output: ../../sprout-example-go
22+
output: ../gen/go

0 commit comments

Comments
 (0)