-
-
Notifications
You must be signed in to change notification settings - Fork 182
/
pluginmod.go
37 lines (34 loc) · 875 Bytes
/
pluginmod.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
package pluginmod
import (
"errors"
"io/fs"
"path"
"strings"
"github.com/livebud/bud/package/gomod"
)
func Glob(module *gomod.Module, dir string) (plugins []*gomod.Module, err error) {
// Get all the bud plugins that start with bud-*
modules, err := module.FindBy(func(req *gomod.Require) bool {
// Plugins must be directly imported, they cannot come indirectly through
// another dependency
if req.Indirect {
return false
}
return strings.HasPrefix(path.Base(req.Mod.Path), "bud-")
})
if err != nil {
return nil, err
}
// Add the app module to the top of the list
modules = append([]*gomod.Module{module}, modules...)
for _, module := range modules {
if _, err := fs.Stat(module, dir); err != nil {
if errors.Is(err, fs.ErrNotExist) {
continue
}
return nil, err
}
plugins = append(plugins, module)
}
return plugins, nil
}