github.com/singlemusic/buffalo@v0.16.30/buffalo/cmd/fix/plugins.go (about)

     1  package fix
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  	"os"
     7  	"path"
     8  	"strings"
     9  
    10  	cmdPlugins "github.com/gobuffalo/buffalo/buffalo/cmd/plugins"
    11  	"github.com/gobuffalo/buffalo/genny/plugins/install"
    12  	"github.com/gobuffalo/buffalo/internal/takeon/github.com/markbates/errx"
    13  	"github.com/gobuffalo/buffalo/plugins"
    14  	"github.com/gobuffalo/buffalo/plugins/plugdeps"
    15  	"github.com/gobuffalo/genny/v2"
    16  	"github.com/gobuffalo/meta"
    17  )
    18  
    19  //Plugins fixes the plugin configuration of the project by
    20  //manipulating the plugins .toml file.
    21  type Plugins struct{}
    22  
    23  //CleanCache cleans the plugins cache folder by removing it
    24  func (pf Plugins) CleanCache(r *Runner) error {
    25  	fmt.Println("~~~ Cleaning plugins cache ~~~")
    26  	os.RemoveAll(plugins.CachePath)
    27  	return nil
    28  }
    29  
    30  //Reinstall installs latest versions of the plugins
    31  func (pf Plugins) Reinstall(r *Runner) error {
    32  	plugs, err := plugdeps.List(r.App)
    33  	if err != nil && (errx.Unwrap(err) != plugdeps.ErrMissingConfig) {
    34  		return err
    35  	}
    36  
    37  	run := genny.WetRunner(context.Background())
    38  	gg, err := install.New(&install.Options{
    39  		App:     r.App,
    40  		Plugins: plugs.List(),
    41  	})
    42  
    43  	run.WithGroup(gg)
    44  
    45  	fmt.Println("~~~ Reinstalling plugins ~~~")
    46  	return run.Run()
    47  }
    48  
    49  //RemoveOld removes old and deprecated plugins
    50  func (pf Plugins) RemoveOld(r *Runner) error {
    51  	fmt.Println("~~~ Removing old plugins ~~~")
    52  
    53  	run := genny.WetRunner(context.Background())
    54  	app := meta.New(".")
    55  	plugs, err := plugdeps.List(app)
    56  	if err != nil && (errx.Unwrap(err) != plugdeps.ErrMissingConfig) {
    57  		return err
    58  	}
    59  
    60  	a := strings.TrimSpace("github.com/gobuffalo/buffalo-pop")
    61  	bin := path.Base(a)
    62  	plugs.Remove(plugdeps.Plugin{
    63  		Binary: bin,
    64  		GoGet:  a,
    65  	})
    66  
    67  	fmt.Println("~~~ Removing github.com/gobuffalo/buffalo-pop plugin ~~~")
    68  
    69  	run.WithRun(cmdPlugins.NewEncodePluginsRunner(app, plugs))
    70  
    71  	return run.Run()
    72  }