Skip to content

Commit

Permalink
Improve UX
Browse files Browse the repository at this point in the history
  • Loading branch information
rusinikita committed Nov 1, 2024
1 parent 6fb8c0c commit 67797b9
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 19 deletions.
12 changes: 3 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,8 @@ Go repository architecture visualization

# Usage

1. Clone repository
2. Download dependencies
1. Run program with project folder
```shell
go mod tidy
go run github.com/rusinikita/goviz /Users/nikitarusin/Repositories/go-clean-architecture
```
3. Replace value of `projectDir` and `pathPrefixToRemove` with your local repository values
4. Run app
```shell
go run main.go
```
5. Open `result.html` file in browser
2. Open `result.html` file in browser
12 changes: 11 additions & 1 deletion internal/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type CompileResult struct {
constructors []*Constructor
}

func Compile(projectDir, pathPrefixToRemove string) *CompileResult {
func Compile(projectDir string) *CompileResult {
cfg := &packages.Config{
Mode: packages.NeedName |
packages.NeedTypes |
Expand All @@ -32,6 +32,12 @@ func Compile(projectDir, pathPrefixToRemove string) *CompileResult {
var structs []*Struct
var constructors []*Constructor

if len(pkgs) == 0 {
return nil
}

pathPrefixToRemove := pkgs[0].Module.Path + "/"

for _, pkg := range pkgs {
for _, name := range pkg.Types.Scope().Names() {
object := pkg.Types.Scope().Lookup(name)
Expand Down Expand Up @@ -71,6 +77,10 @@ func Compile(projectDir, pathPrefixToRemove string) *CompileResult {

log.Println("collected")

interfaces = lo.Filter(interfaces, func(item *Interface, _ int) bool {
return item.NumMethods() > 1
})

structs = lo.Filter(structs, func(item *Struct, _ int) bool {
return item.component
})
Expand Down
8 changes: 5 additions & 3 deletions internal/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ func NewStruct(s *types.Struct, n *types.Named, pref string) *Struct {
var includes []string
var componentDeps int

name := strings.TrimPrefix(n.String(), pref)

for i := 0; i < s.NumFields(); i++ {
t := s.Field(i).Type()

path := t.String()
path := strings.TrimPrefix(t.String(), "*")
if !strings.HasPrefix(path, pref) {
continue
}
Expand All @@ -54,11 +56,11 @@ func NewStruct(s *types.Struct, n *types.Named, pref string) *Struct {
}

return &Struct{
name: strings.TrimPrefix(n.String(), pref),
name: name,
_type: n,
s: s,
includes: includes,
component: true, //componentDeps > 0 && n.NumMethods() > 0,
component: n.NumMethods() > 0,
}
}

Expand Down
16 changes: 10 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package main

import (
"github.com/rusinikita/goviz/internal"
)
"fmt"
"os"

const (
projectDir = "/Users/nikitarusin/Repositories/replace_me"
pathPrefixToRemove = "github.com/rusinikita/replace_me/"
"github.com/rusinikita/goviz/internal"
)

func main() {
code := internal.Compile(projectDir, pathPrefixToRemove)
args := os.Args
if len(args) < 2 {
fmt.Println("Usage: goviz <project dir>")
os.Exit(1)
}

code := internal.Compile(args[1])

internal.RenderFiles(code)
}

0 comments on commit 67797b9

Please sign in to comment.