one headlight

This commit is contained in:
Mark Bates 2019-08-01 17:56:37 -04:00
parent da705a9bbc
commit fa7d8c2b96
2 changed files with 43 additions and 7 deletions

View File

@ -2,11 +2,11 @@ module github.com/markbates/pkger/internal/examples/app
go 1.12 go 1.12
replace github.com/markbates/pkger => ../../../
require ( require (
cloud.google.com/go v0.36.0 // indirect cloud.google.com/go v0.36.0 // indirect
github.com/cockroachdb/cockroach-go v0.0.0-20181001143604-e0a95dfd547c // indirect github.com/cockroachdb/cockroach-go v0.0.0-20181001143604-e0a95dfd547c // indirect
github.com/gobuffalo/buffalo v0.14.7 // indirect github.com/gobuffalo/buffalo v0.14.7 // indirect
github.com/markbates/pkger v0.0.0-00010101000000-000000000000 github.com/markbates/pkger v0.0.0
) )
replace github.com/markbates/pkger => ../../../

View File

@ -14,13 +14,15 @@ var DefaultIgnoredFolders = []string{".", "_", "vendor", "node_modules", "_fixtu
func Parse(name string) (Results, error) { func Parse(name string) (Results, error) {
var r Results var r Results
if name == "" || name == "." {
c, err := pkgs.Current() c, err := pkgs.Current()
if err != nil { if err != nil {
return r, err return r, err
} }
if name == "" || name == "." {
name = c.ImportPath name = c.ImportPath
} }
pt, err := paths.Parse(name) pt, err := paths.Parse(name)
if err != nil { if err != nil {
return r, err return r, err
@ -34,18 +36,37 @@ func Parse(name string) (Results, error) {
} }
m := map[paths.Path]bool{} m := map[paths.Path]bool{}
root := r.Path.Name root := r.Path.Name
if !strings.HasPrefix(root, string(filepath.Separator)) { if !strings.HasPrefix(root, string(filepath.Separator)) {
root = string(filepath.Separator) + root root = string(filepath.Separator) + root
} }
if !strings.HasPrefix(root, her.Dir) { if !strings.HasPrefix(root, her.Dir) {
root = filepath.Join(her.Dir, root) root = filepath.Join(her.Dir, root)
} }
if name != her.Dir {
_, err = os.Stat(filepath.Join(root, "go.mod"))
if err == nil {
return Results{}, nil
}
}
err = filepath.Walk(root, func(path string, info os.FileInfo, err error) error { err = filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
if err != nil { if err != nil {
return err return err
} }
if info.IsDir() {
if path != c.Dir {
_, err = os.Stat(filepath.Join(path, "go.mod"))
if err == nil {
return filepath.SkipDir
}
}
}
base := filepath.Base(path) base := filepath.Base(path)
for _, ig := range DefaultIgnoredFolders { for _, ig := range DefaultIgnoredFolders {
@ -128,11 +149,26 @@ func sourceFiles(pt paths.Path) ([]paths.Path, error) {
if !fi.IsDir() { if !fi.IsDir() {
return res, nil return res, nil
} }
c, err := pkgs.Current()
if err != nil {
return res, err
}
err = filepath.Walk(fp, func(p string, info os.FileInfo, err error) error { err = filepath.Walk(fp, func(p string, info os.FileInfo, err error) error {
if err != nil { if err != nil {
return err return err
} }
if info.IsDir() {
if p != c.Dir {
_, err = os.Stat(filepath.Join(p, "go.mod"))
if err == nil {
return filepath.SkipDir
}
}
}
base := filepath.Base(p) base := filepath.Base(p)
if base == "." { if base == "." {