Skip to content

Commit ba409d9

Browse files
authored
Merge pull request #51 from commitdev/restructure-project
Move some dirs from root into internal, shuffle some stuff around in cmd
2 parents 4fc10c3 + ff8e79f commit ba409d9

File tree

14 files changed

+59
-62
lines changed

14 files changed

+59
-62
lines changed

cmd/commit0.go

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,20 @@ package cmd
22

33
import (
44
"fmt"
5-
"github.com/commitdev/commit0/templator"
6-
"github.com/gobuffalo/packr/v2"
7-
"github.com/spf13/cobra"
85
"os"
9-
)
106

11-
var Templator *templator.Templator
7+
"github.com/spf13/cobra"
8+
)
129

1310
var rootCmd = &cobra.Command{
1411
Use: "commit0",
15-
Short: "Commit0 is a moduler service generator.",
12+
Short: "Commit0 is a modular service generator.",
1613
Long: `TODO`,
1714
Run: func(cmd *cobra.Command, args []string) {
1815
},
1916
}
2017

21-
func Init() {
22-
templates := packr.New("templates", "../templates")
23-
Templator = templator.NewTemplator(templates)
24-
}
25-
2618
func Execute() {
27-
Init()
2819
if err := rootCmd.Execute(); err != nil {
2920
fmt.Println(err)
3021
os.Exit(1)

cmd/create.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@ import (
55
"os"
66
"path"
77

8+
"github.com/commitdev/commit0/internal/templator"
9+
"github.com/gobuffalo/packr/v2"
810
"github.com/spf13/cobra"
911
)
1012

1113
func init() {
12-
1314
rootCmd.AddCommand(createCmd)
1415
}
1516

16-
func Create(projectName string, outDir string) string {
17+
func Create(projectName string, outDir string, t *templator.Templator) string {
1718
rootDir := path.Join(outDir, projectName)
1819
log.Printf("Creating project %s.", projectName)
1920
err := os.MkdirAll(rootDir, os.ModePerm)
@@ -31,14 +32,14 @@ func Create(projectName string, outDir string) string {
3132
if err != nil {
3233
log.Printf("Error creating commit0 config: %v", err)
3334
}
34-
Templator.Commit0.Execute(f, projectName)
35+
t.Commit0.Execute(f, projectName)
3536

3637
gitIgnorePath := path.Join(rootDir, ".gitignore")
3738
f, err = os.Create(gitIgnorePath)
3839
if err != nil {
3940
log.Printf("Error creating commit0 config: %v", err)
4041
}
41-
Templator.GitIgnore.Execute(f, projectName)
42+
t.GitIgnore.Execute(f, projectName)
4243

4344
return rootDir
4445
}
@@ -51,8 +52,11 @@ var createCmd = &cobra.Command{
5152
log.Fatalf("Project name cannot be empty!")
5253
}
5354

55+
templates := packr.New("templates", "../templates")
56+
t := templator.NewTemplator(templates)
57+
5458
projectName := args[0]
5559

56-
Create(projectName, "./")
60+
Create(projectName, "./", t)
5761
},
5862
}

cmd/create_test.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
package cmd_test
22

33
import (
4-
"github.com/commitdev/commit0/cmd"
54
"io/ioutil"
65
"os"
76
"path"
87
"testing"
9-
)
108

11-
func TestInitWorks(t *testing.T) {
12-
cmd.Init()
13-
}
9+
"github.com/commitdev/commit0/cmd"
10+
"github.com/commitdev/commit0/internal/templator"
11+
"github.com/gobuffalo/packr/v2"
12+
)
1413

1514
func TestCreateWorks(t *testing.T) {
1615
tmpdir, err := ioutil.TempDir("", "commit0-")
@@ -20,7 +19,10 @@ func TestCreateWorks(t *testing.T) {
2019

2120
projectName := "test-project"
2221

23-
root := cmd.Create(projectName, tmpdir)
22+
templates := packr.New("templates", "../templates")
23+
templator := templator.NewTemplator(templates)
24+
25+
root := cmd.Create(projectName, tmpdir, templator)
2426
defer os.RemoveAll(tmpdir)
2527

2628
st, err := os.Stat(path.Join(root, "commit0.yml"))

cmd/generate.go

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
package cmd
22

33
import (
4-
"github.com/commitdev/commit0/config"
5-
"github.com/commitdev/commit0/generate/docker"
6-
"github.com/commitdev/commit0/generate/golang"
7-
"github.com/commitdev/commit0/generate/http"
8-
"github.com/commitdev/commit0/generate/proto"
9-
"github.com/commitdev/commit0/generate/react"
10-
114
"log"
125

6+
"github.com/commitdev/commit0/internal/config"
7+
"github.com/commitdev/commit0/internal/generate/docker"
8+
"github.com/commitdev/commit0/internal/generate/golang"
9+
"github.com/commitdev/commit0/internal/generate/http"
10+
"github.com/commitdev/commit0/internal/generate/proto"
11+
"github.com/commitdev/commit0/internal/generate/react"
12+
"github.com/commitdev/commit0/internal/templator"
13+
"github.com/gobuffalo/packr/v2"
1314
"github.com/spf13/cobra"
1415
)
1516

@@ -39,23 +40,26 @@ var generateCmd = &cobra.Command{
3940
log.Fatalf("'%s' is not a supported language.", language)
4041
}
4142

43+
templates := packr.New("templates", "../templates")
44+
t := templator.NewTemplator(templates)
45+
4246
cfg := config.LoadConfig(configPath)
4347
cfg.Language = language
4448
cfg.Print()
4549

4650
switch language {
4751
case Go:
48-
proto.Generate(Templator, cfg)
49-
golang.Generate(Templator, cfg)
50-
docker.GenerateGoAppDockerFile(Templator, cfg)
51-
docker.GenerateGoDockerCompose(Templator, cfg)
52+
proto.Generate(t, cfg)
53+
golang.Generate(t, cfg)
54+
docker.GenerateGoAppDockerFile(t, cfg)
55+
docker.GenerateGoDockerCompose(t, cfg)
5256
case React:
53-
react.Generate(Templator, cfg)
57+
react.Generate(t, cfg)
5458
}
5559

5660
if cfg.Network.Http.Enabled {
57-
http.GenerateHttpGW(Templator, cfg)
58-
docker.GenerateGoHttpGWDockerFile(Templator, cfg)
61+
http.GenerateHttpGW(t, cfg)
62+
docker.GenerateGoHttpGWDockerFile(t, cfg)
5963
}
6064
},
6165
}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package docker
22

33
import (
4-
"github.com/commitdev/commit0/util"
5-
6-
"github.com/commitdev/commit0/config"
7-
"github.com/commitdev/commit0/templator"
4+
"github.com/commitdev/commit0/internal/config"
5+
"github.com/commitdev/commit0/internal/templator"
6+
"github.com/commitdev/commit0/internal/util"
87
)
98

109
func GenerateGoAppDockerFile(templator *templator.Templator, config *config.Commit0Config) {
@@ -17,4 +16,4 @@ func GenerateGoHttpGWDockerFile(templator *templator.Templator, config *config.C
1716

1817
func GenerateGoDockerCompose(templator *templator.Templator, config *config.Commit0Config) {
1918
util.TemplateFileIfDoesNotExist("", "docker-compose.yml", templator.Docker.DockerCompose, config)
20-
}
19+
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ package golang
22

33
import (
44
"fmt"
5-
"github.com/commitdev/commit0/util"
6-
7-
"github.com/commitdev/commit0/config"
8-
"github.com/commitdev/commit0/templator"
95
"log"
106
"os"
7+
8+
"github.com/commitdev/commit0/internal/config"
9+
"github.com/commitdev/commit0/internal/templator"
10+
"github.com/commitdev/commit0/internal/util"
1111
)
1212

1313
func Generate(templator *templator.Templator, config *config.Commit0Config) {
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package http
22

33
import (
4-
"github.com/commitdev/commit0/util"
5-
6-
"github.com/commitdev/commit0/config"
7-
"github.com/commitdev/commit0/templator"
4+
"github.com/commitdev/commit0/internal/config"
5+
"github.com/commitdev/commit0/internal/templator"
6+
"github.com/commitdev/commit0/internal/util"
87
)
98

109
func GenerateHttpGW(templator *templator.Templator, config *config.Commit0Config) {
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ package proto
33
import (
44
"bytes"
55
"fmt"
6-
7-
"github.com/commitdev/commit0/config"
8-
"github.com/commitdev/commit0/templator"
9-
"github.com/commitdev/commit0/util"
106
"log"
117
"os"
128
"os/exec"
9+
10+
"github.com/commitdev/commit0/internal/config"
11+
"github.com/commitdev/commit0/internal/templator"
12+
"github.com/commitdev/commit0/internal/util"
1313
)
1414

1515
func Generate(templator *templator.Templator, config *config.Commit0Config) {

0 commit comments

Comments
 (0)