Skip to content

Commit

Permalink
Merge pull request #8 from mukezhz/feature/align-to-wesionary-template
Browse files Browse the repository at this point in the history
Feature/align to wesionary template
  • Loading branch information
Denes-cilwal authored Jan 11, 2024
2 parents edab464 + 6973595 commit d079a2b
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 30 deletions.
8 changes: 4 additions & 4 deletions cmd/new_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
)

var newModuleCmd = &cobra.Command{
Use: "gen features [name]",
Short: "Create a new features",
Use: "gen module [name]",
Short: "Create a new domain",
Args: cobra.MaximumNArgs(2),
Run: createModule,
}
Expand All @@ -35,7 +35,7 @@ func createModule(_ *cobra.Command, args []string) {
fmt.Println("Error finding Git root:", err)
return
}
mainModulePath := filepath.Join(projectPath, "domain", "features", "module.go")
mainModulePath := filepath.Join(projectPath, "domain", "module.go")
var moduleName string
if len(args) == 1 {
questions := []terminal.ProjectQuestion{
Expand All @@ -59,7 +59,7 @@ func createModule(_ *cobra.Command, args []string) {
data := utility.GetModuleDataFromModuleName(moduleName, projectModule.Module, projectModule.GoVersion)

// Define the directory structure
targetRoot := filepath.Join(".", "domain", "features", data.PackageName)
targetRoot := filepath.Join(".", "domain", data.PackageName)
templatePath := filepath.Join(".", "templates", "wesionary", "module")

err = utility.GenerateFiles(templatesFS, templatePath, targetRoot, data)
Expand Down
19 changes: 6 additions & 13 deletions pkg/utility/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

func ImportPackage(node *ast.File, projectModule, packageName string) {
path := filepath.Join(projectModule, "domain", "features", packageName)
path := filepath.Join(projectModule, "domain", packageName)
importSpec := &ast.ImportSpec{
Path: &ast.BasicLit{
Kind: token.STRING,
Expand Down Expand Up @@ -59,17 +59,10 @@ func AddAnotherFxOptionsInModule(path, module, projectModule string) string {
switch x := n.(type) {
case *ast.CallExpr:
if sel, ok := x.Fun.(*ast.SelectorExpr); ok {
if sel.Sel.Name == "Module" {
x.Args = append(x.Args, &ast.CallExpr{
Fun: &ast.SelectorExpr{
X: ast.NewIdent("fx"),
Sel: ast.NewIdent("Options"),
},
Args: []ast.Expr{
ast.NewIdent(module + ".Module"),
},
Rparen: token.Pos(1),
})
if sel.Sel.Name == "Options" {
x.Args = append(x.Args, []ast.Expr{
ast.NewIdent(module + ".Module"),
}...)
}
}
}
Expand All @@ -82,7 +75,7 @@ func AddAnotherFxOptionsInModule(path, module, projectModule string) string {
fmt.Println(err)
}
formattedCode := buf.String()
providerToInsert := fmt.Sprintf("fx.Options(%v.Module),", module)
providerToInsert := fmt.Sprintf("%v.Module,", module)
formattedCode = strings.Replace(formattedCode, providerToInsert, "\n\t"+providerToInsert, 1)
return formattedCode
}
Expand Down
11 changes: 0 additions & 11 deletions templates/wesionary/project/domain/features/module.tmpl

This file was deleted.

4 changes: 2 additions & 2 deletions templates/wesionary/project/domain/module.tmpl
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package domain

import (
"{{.ProjectModuleName}}/domain/features"
"{{.ProjectModuleName}}/domain/hello"
"{{.ProjectModuleName}}/domain/middlewares"

"go.uber.org/fx"
)

var Module = fx.Options(
middlewares.Module,
features.Module,
hello.Module,
)

0 comments on commit d079a2b

Please sign in to comment.