Skip to content

Commit

Permalink
initial poc
Browse files Browse the repository at this point in the history
  • Loading branch information
Pritesh-Patel committed Aug 21, 2019
0 parents commit c41be81
Show file tree
Hide file tree
Showing 24 changed files with 1,256 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
main-packr.go
packrd
14 changes: 14 additions & 0 deletions Makefile
@@ -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
29 changes: 29 additions & 0 deletions README.md
@@ -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.

28 changes: 28 additions & 0 deletions cmd/generate.go
@@ -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)
},
}
26 changes: 26 additions & 0 deletions cmd/sprout.go
@@ -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)
}
}
19 changes: 19 additions & 0 deletions cmd/version.go
@@ -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")
},
}
54 changes: 54 additions & 0 deletions config/config.go
@@ -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)

}

0 comments on commit c41be81

Please sign in to comment.