-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfinders.go
60 lines (48 loc) · 1.14 KB
/
finders.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package main
import (
"fmt"
"os"
"path/filepath"
"github.com/hashicorp/go-multierror"
)
type packageInfo struct {
Name string
Version string
InternalVersion string
Path string
HasError bool
}
func findManifests(root string, handlers []packageHandler) ([]packageInfo, error) {
var result error
fileList := []packageInfo{}
err := filepath.Walk(root, func(path string, f os.FileInfo, err error) error {
if err != nil {
fmt.Printf("Error with %s\n", path)
return filepath.SkipDir
}
if isIgnored(f) {
return filepath.SkipDir
}
for _, handler := range handlers {
if handler.isPackage(path) {
pkg, err := handler.getPackageInfo(path)
fileList = append(fileList, pkg)
if err != nil {
result = multierror.Append(result, err)
}
}
}
return nil
})
if err != nil {
result = multierror.Append(result, err)
}
return fileList, result
}
func isIgnored(f os.FileInfo) bool {
var ignoredFolders = []string{"bin", "obj", ".git", "CordovaLib", "platforms", "res", "node_modules"}
if f.IsDir() && stringInSlice(f.Name(), ignoredFolders) {
return true
}
return false
}