Skip to content

Commit

Permalink
remove generated file
Browse files Browse the repository at this point in the history
  • Loading branch information
crhntr committed Aug 19, 2024
1 parent a84185d commit b2c88c3
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions cmd/muxt/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"flag"
"fmt"
"go/ast"
"go/token"
"io"
"log"
Expand Down Expand Up @@ -73,7 +74,6 @@ func generateCommand(args []string, workingDirectory string, getEnv func(string)
if err != nil {
return err
}
_ = os.Remove(filepath.Join(workingDirectory, g.outputFilename))
list, err := packages.Load(&packages.Config{
Mode: packages.NeedFiles | packages.NeedSyntax | packages.NeedEmbedPatterns | packages.NeedEmbedFiles,
Dir: workingDirectory,
Expand Down Expand Up @@ -101,7 +101,14 @@ func generateCommand(args []string, workingDirectory string, getEnv func(string)
return err
}
out := log.New(stdout, "", 0)
s, err := muxt.Generate(templateNames, g.goPackage, g.templatesVariable, g.routesFunction, g.receiverIdent, g.Package.Fset, g.Package.Syntax, g.Package.Syntax, out)
files := slices.Clone(g.Package.Syntax)
if i := slices.IndexFunc(files, func(file *ast.File) bool {
p := g.Package.Fset.Position(file.Pos())
return p.Filename == g.outputFilename
}); i >= 0 {
files = slices.Clip(slices.Delete(files, i, i+1))
}
s, err := muxt.Generate(templateNames, g.goPackage, g.templatesVariable, g.routesFunction, g.receiverIdent, g.Package.Fset, files, files, out)
if err != nil {
return err
}
Expand Down

0 comments on commit b2c88c3

Please sign in to comment.