This repository has been archived by the owner on Feb 24, 2024. It is now read-only.
/
plugins.go
75 lines (61 loc) · 1.79 KB
/
plugins.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package fix
import (
"context"
"fmt"
"os"
"path"
"strings"
cmdPlugins "github.com/gobuffalo/buffalo/buffalo/cmd/plugins"
"github.com/gobuffalo/buffalo/genny/plugins/install"
"github.com/gobuffalo/buffalo/internal/takeon/github.com/markbates/errx"
"github.com/gobuffalo/buffalo/plugins"
"github.com/gobuffalo/buffalo/plugins/plugdeps"
"github.com/gobuffalo/genny/v2"
"github.com/gobuffalo/meta"
)
//Plugins fixes the plugin configuration of the project by
//manipulating the plugins .toml file.
type Plugins struct{}
//CleanCache cleans the plugins cache folder by removing it
func (pf Plugins) CleanCache(r *Runner) error {
fmt.Println("~~~ Cleaning plugins cache ~~~")
os.RemoveAll(plugins.CachePath)
return nil
}
//Reinstall installs latest versions of the plugins
func (pf Plugins) Reinstall(r *Runner) error {
plugs, err := plugdeps.List(r.App)
if err != nil && (errx.Unwrap(err) != plugdeps.ErrMissingConfig) {
return err
}
run := genny.WetRunner(context.Background())
gg, err := install.New(&install.Options{
App: r.App,
Plugins: plugs.List(),
})
if err != nil {
return err
}
run.WithGroup(gg)
fmt.Println("~~~ Reinstalling plugins ~~~")
return run.Run()
}
//RemoveOld removes old and deprecated plugins
func (pf Plugins) RemoveOld(r *Runner) error {
fmt.Println("~~~ Removing old plugins ~~~")
run := genny.WetRunner(context.Background())
app := meta.New(".")
plugs, err := plugdeps.List(app)
if err != nil && (errx.Unwrap(err) != plugdeps.ErrMissingConfig) {
return err
}
a := strings.TrimSpace("github.com/gobuffalo/buffalo-pop")
bin := path.Base(a)
plugs.Remove(plugdeps.Plugin{
Binary: bin,
GoGet: a,
})
fmt.Println("~~~ Removing github.com/gobuffalo/buffalo-pop plugin ~~~")
run.WithRun(cmdPlugins.NewEncodePluginsRunner(app, plugs))
return run.Run()
}