Skip to content

Commit

Permalink
Merge pull request #93 from kcmvp/v014
Browse files Browse the repository at this point in the history
#10: adjust project layout
  • Loading branch information
kcmvp authored Apr 15, 2024
2 parents 6fdcf97 + 5f66cca commit 48bd1e1
Show file tree
Hide file tree
Showing 32 changed files with 62 additions and 51 deletions.
22 changes: 15 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,36 @@ Although the Golang programming ecosystem is becoming more and more mature,
these tools and frameworks exist independently to solve specific problems.
Whenever a new Golang project is started, it requires a series of initialization;
What’s worse is that whenever your switch the development environment, same process have to be repeated!
This project is built to solve this problem by providing a method similar to [Maven](https://maven.apache.org/)
or [Gradle](https://gradle.com/) in the **Java** ecosystem. Please refer [documents](#commands) for details
This project is built to solve this problem by providing a tool named *gbc**, which is similar to [Maven](https://maven.apache.org/)
or [Gradle](https://gradle.com/) in the **Java** ecosystem together with a framework(glue) similar to [SpringBoot](https://spring.io/projects/spring-boot). Please refer [documents](#commands) for details

<span id="nav-3"></span>

## Features

1. **Everything is a plugin, simple yet powerful !**
2. Define a tool chain and workflow without a line code.
3. Better user experience
1. Everything is a plugin, you can use any tool you like as a plugin to customize your build process!
2. Model driver SQL database DAO.
3. IoC Container support.
4. Code generation for most popular frameworks scaffolding.
5. Environment sensitive profile.
6. More ....

## What's a gob based project looks like?
Just like[SpringBoot](https://spring.io/projects/spring-boot), the most important part of a gob project is the **configurations** which define your project.
There are *two** main configurations
1. **gob.yaml** : it acts as the same as **settings.gradle.kts**(Gradle) or **pom.xml**(Maven), you can define any thrid party tool as a plugin in this file.
2. **application.yaml**: it acts as the same **application.yaml** of [SpringBoot](https://spring.io/projects/spring-boot)

## How gob works
`Gob` takes everything defined in the `gob.yaml` as plugin.
```mermaid
flowchart TD
Gob --> gob.yaml
gbc --> gob.yaml
gob.yaml --> plugin1
gob.yaml --> plugin2
gob.yaml --> plugin3
```
You just need to tell `gbc` 3W(where,when and what)

1. **Where** : where to download the tool
2. **When** : when to execute to command
2. **What** : what to do with the tool
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (suite *InternalPluginTestSuit) TestUnmarshalJSON() {
defer func() {
os.RemoveAll(gopath)
}()
data, _ := os.ReadFile(filepath.Join(CurProject().Root(), "gbc", "cmd", "resources", "config.json"))
data, _ := os.ReadFile(filepath.Join(CurProject().Root(), "cmd", "gbc", "command", "resources", "config.json"))
v := gjson.GetBytes(data, "plugins")
var plugins []Plugin
err := json.Unmarshal([]byte(v.Raw), &plugins)
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type ProjectTestSuite struct {
}

func (suite *ProjectTestSuite) BeforeTest(_, testName string) {
s, _ := os.Open(filepath.Join(CurProject().Root(), "gbc", "testdata", "gob.yaml"))
s, _ := os.Open(filepath.Join(CurProject().Root(), "cmd", "gbc", "testdata", "gob.yaml"))
root := filepath.Join(CurProject().Root(), "target", fmt.Sprintf("artifact_ProjectTestSuite_%s", testName))
os.MkdirAll(root, os.ModePerm)
t, _ := os.Create(filepath.Join(root, "gob.yaml"))
Expand Down Expand Up @@ -117,7 +117,7 @@ func (suite *ProjectTestSuite) TestValidate() {
func (suite *ProjectTestSuite) TestMainFiles() {
mainFiles := CurProject().MainFiles()
assert.Equal(suite.T(), 1, len(mainFiles))
assert.True(suite.T(), lo.Contains(mainFiles, filepath.Join(CurProject().Root(), "gbc", "gbc.go")))
assert.True(suite.T(), lo.Contains(mainFiles, filepath.Join(CurProject().Root(), "cmd", "gbc", "gbc.go")))
}

func (suite *ProjectTestSuite) TestVersion() {
Expand Down
4 changes: 2 additions & 2 deletions gbc/cmd/build_action.go → cmd/gbc/command/build_action.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package cmd
package command

import (
"errors"
"fmt"
"github.com/kcmvp/gob/gbc/artifact" //nolint
"github.com/kcmvp/gob/cmd/gbc/artifact" //nolint
"os"
"os/exec"
"path/filepath"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package cmd
package command

import (
"github.com/fatih/color"
"github.com/kcmvp/gob/gbc/artifact"
"github.com/kcmvp/gob/cmd/gbc/artifact"
"github.com/kcmvp/gob/utils"
"github.com/samber/lo"
"github.com/stretchr/testify/assert"
Expand Down
4 changes: 2 additions & 2 deletions gbc/cmd/deps.go → cmd/gbc/command/deps.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cmd
package command

import (
"bufio"
Expand All @@ -8,7 +8,7 @@ import (
"path/filepath"
"strings"

"github.com/kcmvp/gob/gbc/artifact" //nolint
"github.com/kcmvp/gob/cmd/gbc/artifact" //nolint

"github.com/fatih/color"
"github.com/samber/lo"
Expand Down
4 changes: 2 additions & 2 deletions gbc/cmd/deps_test.go → cmd/gbc/command/deps_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package cmd
package command

import (
"fmt"
"github.com/kcmvp/gob/gbc/artifact"
"github.com/kcmvp/gob/cmd/gbc/artifact"
"github.com/samber/lo"
"github.com/stretchr/testify/assert"
"github.com/xlab/treeprint"
Expand Down
4 changes: 2 additions & 2 deletions gbc/cmd/exec.go → cmd/gbc/command/exec.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
*/
package cmd
package command

import (
"bufio"
Expand All @@ -12,7 +12,7 @@ import (
"strings"

"github.com/fatih/color"
"github.com/kcmvp/gob/gbc/artifact"
"github.com/kcmvp/gob/cmd/gbc/artifact"
"github.com/samber/lo"
"github.com/spf13/cobra"
)
Expand Down
16 changes: 9 additions & 7 deletions gbc/cmd/exec_test.go → cmd/gbc/command/exec_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package cmd
package command

import (
"fmt"
"github.com/kcmvp/gob/gbc/artifact"
"github.com/kcmvp/gob/cmd/gbc/artifact"
"github.com/kcmvp/gob/utils"
"github.com/samber/lo"
"github.com/stretchr/testify/assert"
Expand All @@ -19,18 +19,20 @@ type ExecTestSuite struct {
}

func (suite *ExecTestSuite) BeforeTest(_, testName string) {
s, _ := os.Open(filepath.Join(artifact.CurProject().Root(), "gbc", "testdata", "gob.yaml"))
root := filepath.Join(artifact.CurProject().Root(), "target", fmt.Sprintf("cmd_ExecTestSuite_%s", testName))
os.Chdir(artifact.CurProject().Root())
s, _ := os.Open(filepath.Join(artifact.CurProject().Root(), "cmd", "gbc", "testdata", "gob.yaml"))
_, method := utils.TestCaller()
root := filepath.Join(artifact.CurProject().Root(), "target", strings.ReplaceAll(method, "_BeforeTest", fmt.Sprintf("_%s", testName)))
os.MkdirAll(root, os.ModePerm)
t, _ := os.Create(filepath.Join(root, "gob.yaml"))
io.Copy(t, s)
s.Close()
t.Close()
s.Close()
}

func (suite *ExecTestSuite) TearDownSuite() {
_, method := utils.TestCaller()
TearDownSuite(strings.TrimRight(method, "TearDownSuite"))
//_, method := utils.TestCaller()
//TearDownSuite(strings.TrimRight(method, "TearDownSuite"))
}

func TestExecSuite(t *testing.T) {
Expand Down
8 changes: 4 additions & 4 deletions gbc/cmd/initialize.go → cmd/gbc/command/initialize.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
Copyright © 2023 kcmvp <[email protected]>
*/
package cmd
package command

import (
"encoding/json"
Expand All @@ -10,7 +10,7 @@ import (
"path/filepath"

"github.com/fatih/color"
"github.com/kcmvp/gob/gbc/artifact"
"github.com/kcmvp/gob/cmd/gbc/artifact"
"github.com/kcmvp/gob/utils"
"github.com/samber/lo"
"github.com/spf13/cobra"
Expand All @@ -22,9 +22,9 @@ func builtinPlugins() []artifact.Plugin {
var err error
test, _ := utils.TestCaller()
if !test {
data, err = resources.ReadFile("resources/config.json")
data, err = resources.ReadFile(filepath.Join(resourceDir, "config.json"))
} else {
data, err = os.ReadFile(filepath.Join(artifact.CurProject().Root(), "gbc", "testdata", "config.json"))
data, err = os.ReadFile(filepath.Join(artifact.CurProject().Root(), "cmd", "gbc", "testdata", "config.json"))
}
var plugins []artifact.Plugin
if err == nil {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cmd
package command

import (
"github.com/kcmvp/gob/gbc/artifact"
"github.com/kcmvp/gob/cmd/gbc/artifact"
"github.com/kcmvp/gob/utils"
"github.com/samber/lo"
"github.com/stretchr/testify/assert"
Expand Down
4 changes: 2 additions & 2 deletions gbc/cmd/plugin.go → cmd/gbc/command/plugin.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
*/
package cmd
package command

import (
"errors"
Expand All @@ -11,7 +11,7 @@ import (
"github.com/fatih/color"
"github.com/jedib0t/go-pretty/v6/table"
"github.com/jedib0t/go-pretty/v6/text"
"github.com/kcmvp/gob/gbc/artifact"
"github.com/kcmvp/gob/cmd/gbc/artifact"
"github.com/samber/lo"
"github.com/spf13/cobra"
)
Expand Down
4 changes: 2 additions & 2 deletions gbc/cmd/plugin_test.go → cmd/gbc/command/plugin_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cmd
package command

import (
"github.com/kcmvp/gob/gbc/artifact"
"github.com/kcmvp/gob/cmd/gbc/artifact"
"github.com/kcmvp/gob/utils"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
13 changes: 7 additions & 6 deletions gbc/cmd/root.go → cmd/gbc/command/root.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
// Package cmd /*
package cmd
package command

import (
"context"
"embed"
"errors"
"fmt"
"github.com/fatih/color"
"github.com/kcmvp/gob/gbc/artifact"
"github.com/kcmvp/gob/cmd/gbc/artifact"
"github.com/samber/lo"
"github.com/spf13/cobra"
"os" //nolint
"os" //nolint
"path/filepath"
"strings" //nolint
"sync" //nolint
)

const resourceDir = "resources"

//go:embed resources/*
var resources embed.FS

Expand All @@ -25,14 +28,12 @@ var (

func usageTemplate() string {
once.Do(func() {
bytes, _ := resources.ReadFile("resources/usage.tmpl")
bytes, _ := resources.ReadFile(filepath.Join(resourceDir, "usage.tmpl"))
template = color.YellowString(string(bytes))
})
return template
}

const resourceDir = "resources"

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "gbc",
Expand Down
6 changes: 3 additions & 3 deletions gbc/cmd/root_test.go → cmd/gbc/command/root_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package cmd
package command

import (
"fmt"
"github.com/fatih/color"
"github.com/kcmvp/gob/gbc/artifact"
"github.com/kcmvp/gob/cmd/gbc/artifact"
"github.com/kcmvp/gob/utils"
"github.com/samber/lo"
"github.com/stretchr/testify/assert"
Expand All @@ -26,7 +26,7 @@ func TestRootTestSuit(t *testing.T) {

func (suite *RootTestSuit) BeforeTest(_, testName string) {
os.Chdir(artifact.CurProject().Root())
s, _ := os.Open(filepath.Join(artifact.CurProject().Root(), "gbc", "testdata", "gob.yaml"))
s, _ := os.Open(filepath.Join(artifact.CurProject().Root(), "cmd", "gbc", "testdata", "gob.yaml"))
_, method := utils.TestCaller()
root := filepath.Join(artifact.CurProject().Root(), "target", strings.ReplaceAll(method, "_BeforeTest", fmt.Sprintf("_%s", testName)))
os.MkdirAll(root, os.ModePerm)
Expand Down
2 changes: 1 addition & 1 deletion gbc/cmd/setup.go → cmd/gbc/command/setup.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
Copyright © 2024 NAME HERE <EMAIL ADDRESS>
*/
package cmd
package command

import (
"github.com/samber/lo"
Expand Down
2 changes: 1 addition & 1 deletion gbc/cmd/setup_test.go → cmd/gbc/command/setup_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cmd
package command

import (
"github.com/stretchr/testify/assert"
Expand Down
2 changes: 1 addition & 1 deletion gbc/cmd/validator.go → cmd/gbc/command/validator.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cmd
package command

import (
"errors"
Expand Down
4 changes: 2 additions & 2 deletions gbc/gbc.go → cmd/gbc/gbc.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ Copyright © 2023 [email protected]
package main

import (
"github.com/kcmvp/gob/gbc/cmd"
"github.com/kcmvp/gob/cmd/gbc/command"
"os" //nolint
)

func main() {
if err := cmd.Execute(); err != nil {
if err := command.Execute(); err != nil {
os.Exit(1)
}
os.Exit(0)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 48bd1e1

Please sign in to comment.