Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit c41be81
Showing
24 changed files
with
1,256 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
main-packr.go | ||
packrd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
VERSION:= 0.0.1 | ||
|
||
deps: | ||
go get -u github.com/gobuffalo/packr/v2/packr2 | ||
|
||
fmt: | ||
go fmt ./... | ||
|
||
run: | ||
go run main.go | ||
|
||
build: | ||
packr2 | ||
go build -o sprout |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Sprout [POC] | ||
|
||
Status: currently poc | ||
|
||
Sprout intends to be a multi-language service generator. | ||
|
||
Based on specified config it will generate: | ||
* Proto files [Done] | ||
* Proto libraries [Done] | ||
* GraphQL files [In progress] | ||
* GraphQL libraries [In progress] | ||
* Layout [In progress] | ||
* Kubernetes manifests [In progress] | ||
|
||
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. | ||
|
||
## Dependencies | ||
|
||
In order to use this you need ensure you have these installed. | ||
|
||
* prototool | ||
* protoc-gen-go | ||
|
||
## Building locally | ||
|
||
As the templates are embeded into the binary you will need to ensure packer2 is installed. | ||
|
||
You can run `make deps` to install this. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/commitdev/sprout/config" | ||
"github.com/commitdev/sprout/generate/golang" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var configPath string | ||
var outputPath string | ||
|
||
func init() { | ||
|
||
generateCmd.PersistentFlags().StringVarP(&configPath, "config", "c", "sprout.yml", "config path") | ||
generateCmd.PersistentFlags().StringVarP(&outputPath, "output-path", "o", "./", "config path") | ||
|
||
rootCmd.AddCommand(generateCmd) | ||
} | ||
|
||
var generateCmd = &cobra.Command{ | ||
Use: "generate", | ||
Short: "Generate project from config.", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
cfg := config.LoadConfig(configPath) | ||
cfg.Print() | ||
golang.Generate(Templator, cfg, outputPath) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"github.com/commitdev/sprout/templator" | ||
"github.com/spf13/cobra" | ||
"os" | ||
) | ||
|
||
var Templator *templator.Templator | ||
|
||
var rootCmd = &cobra.Command{ | ||
Use: "sprout", | ||
Short: "Sprout a moduler service generator.", | ||
Long: `TODO`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
}, | ||
} | ||
|
||
func Execute(templates *templator.Templator) { | ||
Templator = templates | ||
if err := rootCmd.Execute(); err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
func init() { | ||
rootCmd.AddCommand(versionCmd) | ||
} | ||
|
||
var versionCmd = &cobra.Command{ | ||
Use: "version", | ||
Short: "Print the version number of sprout", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
fmt.Println("v0.0.1") | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package config | ||
|
||
import ( | ||
"github.com/k0kubun/pp" | ||
"gopkg.in/yaml.v2" | ||
"io/ioutil" | ||
"log" | ||
) | ||
|
||
type Maintainers struct { | ||
Name string | ||
Email string | ||
} | ||
|
||
type Network struct { | ||
HTTPPort int `yaml:"http-port,omitempty"` | ||
GrpcPort int `yaml:"grpc-port,omitempty"` | ||
GraphqlPort int `yaml:"graphql-port,omitempty"` | ||
} | ||
|
||
type Service struct { | ||
Name string | ||
Description string | ||
} | ||
|
||
type SproutConfig struct { | ||
Organization string `yaml:"organization"` | ||
Name string `yaml:"name"` | ||
Description string `yaml:"description"` | ||
GitRepo string `yaml:"git-repo"` | ||
DockerRepo string `yaml:"docker-repo"` | ||
Maintainers []Maintainers `yaml:"maintainers"` | ||
Network Network `yaml:"network"` | ||
Services []Service `yaml:"services"` | ||
} | ||
|
||
func LoadConfig(filePath string) *SproutConfig { | ||
config := &SproutConfig{} | ||
data, err := ioutil.ReadFile(filePath) | ||
if err != nil { | ||
log.Panicf("failed to read config: %v", err) | ||
} | ||
err = yaml.Unmarshal(data, &config) | ||
if err != nil { | ||
log.Panicf("failed to unmarshall config: %v", err) | ||
} | ||
|
||
return config | ||
} | ||
|
||
func (c *SproutConfig) Print() { | ||
pp.Print(c) | ||
|
||
} |
Oops, something went wrong.