Skip to content

Commit

Permalink
Fix path to the generated file
Browse files Browse the repository at this point in the history
  • Loading branch information
WinPooh32 authored and AlwxSin committed Nov 5, 2024
1 parent 75e4be2 commit 89eb0df
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions simplegen.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ import (
"go/token"
"go/types"
"os"
"path/filepath"
"strings"
"text/template"

Expand All @@ -116,7 +117,8 @@ const packagesLoadMode = packages.NeedName |
packages.NeedTypes |
packages.NeedSyntax |
packages.NeedTypesInfo |
packages.NeedImports
packages.NeedImports |
packages.NeedModule

type SimpleGenerator struct {
// pkgs collects all used packages for easy use
Expand Down Expand Up @@ -256,10 +258,12 @@ func (sg *SimpleGenerator) write() error {
errors = append(errors, err)
continue
}
parts := strings.SplitN(pkg.PkgPath, "/", 2)

fName := fmt.Sprintf("/%s_gen.go", genName)
err = writeFile(parts[1]+fName, content)
pkgDir := filepath.Join(pkg.Module.Dir, strings.TrimPrefix(pkg.PkgPath, pkg.Module.Path))

fName := fmt.Sprintf("%s_gen.go", genName)

err = writeFile(filepath.Join(pkgDir, fName), content)
if err != nil {
errors = append(errors, err)
}
Expand Down

0 comments on commit 89eb0df

Please sign in to comment.