Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

Moving Plugins into Core #1670

Merged
merged 26 commits into from
Jun 9, 2019
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
3823fd1
*add messaging for installing plugins while we decide what to do
mclark4386 May 18, 2019
e88c136
*copied and modified
mclark4386 May 20, 2019
79e75a7
*noticed this in lint...
mclark4386 May 20, 2019
687c5fa
*fixed a bunch of errors
mclark4386 May 20, 2019
e388c89
*should fix pulling in old plugins
mclark4386 May 20, 2019
b08908d
*more fixmes
mclark4386 May 20, 2019
87a491e
Merge branch 'development' into better_messaging_wo_plugins
markbates May 26, 2019
5bff693
Merge branch 'development' into better_messaging_wo_plugins
mclark4386 May 27, 2019
3715efd
*should fix fix
mclark4386 May 27, 2019
7fe8a5d
Update buffalo/cmd/fix/fix.go via fixmie
mclark4386 May 28, 2019
a479d55
Merge branch 'development' into better_messaging_wo_plugins
markbates Jun 3, 2019
9aec028
Merge branch 'development' into better_messaging_wo_plugins
paganotoni Jun 5, 2019
1463d60
Merge branch 'development' into better_messaging_wo_plugins
mclark4386 Jun 5, 2019
b495c77
Merge branch 'development' into better_messaging_wo_plugins
markbates Jun 9, 2019
17c700a
deps
markbates Jun 9, 2019
d8330db
don't need to run go get for mods when building (#1691)
markbates Jun 9, 2019
d1d2f25
*add messaging for installing plugins while we decide what to do
mclark4386 May 18, 2019
5c5e277
*copied and modified
mclark4386 May 20, 2019
76c8395
*noticed this in lint...
mclark4386 May 20, 2019
8c7b1ce
*fixed a bunch of errors
mclark4386 May 20, 2019
076269a
*should fix pulling in old plugins
mclark4386 May 20, 2019
479bad8
*more fixmes
mclark4386 May 20, 2019
14d6160
*should fix fix
mclark4386 May 27, 2019
592e849
Update buffalo/cmd/fix/fix.go via fixmie
mclark4386 May 28, 2019
9f323bc
deps
markbates Jun 9, 2019
1a3c1b4
Merge branch 'better_messaging_wo_plugins' of https://github.com/gobu…
markbates Jun 9, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions SHOULDERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ Thank you to the following **GIANTS**:

* [github.com/gobuffalo/buffalo-docker](https://godoc.org/github.com/gobuffalo/buffalo-docker)

* [github.com/gobuffalo/buffalo-plugins](https://godoc.org/github.com/gobuffalo/buffalo-plugins)

* [github.com/gobuffalo/buffalo-pop](https://godoc.org/github.com/gobuffalo/buffalo-pop)

* [github.com/gobuffalo/clara](https://godoc.org/github.com/gobuffalo/clara)
Expand Down
1 change: 0 additions & 1 deletion buffalo/cmd/fix/dep.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ var apkg = []string{}
// packages ensure get updated
var upkg = []string{
"github.com/gobuffalo/buffalo",
"github.com/gobuffalo/buffalo-plugins",
"github.com/gobuffalo/plush",
"github.com/gobuffalo/events",
"github.com/gobuffalo/suite",
Expand Down
1 change: 1 addition & 0 deletions buffalo/cmd/fix/fix.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var replace = map[string]string{
"github.com/satori/go.uuid": "github.com/gobuffalo/uuid",
"github.com/markbates/willie": "github.com/gobuffalo/httptest",
"github.com/shurcooL/github_flavored_markdown": "github.com/gobuffalo/github_flavored_markdown",
"github.com/gobuffalo/buffalo-plugins": "github.com/gobuffalo/buffalo/plugins",
}

var ic = ImportConverter{
Expand Down
7 changes: 1 addition & 6 deletions buffalo/cmd/fix/imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,7 @@ func (c ImportConverter) Process(r *Runner) error {

func (c ImportConverter) processFile(p string, info os.FileInfo, err error) error {
er := onlyRelevantFiles(p, info, err, func(p string) error {
err := c.rewriteFile(p)
if err != nil {
err = err
}

return err
return c.rewriteFile(p)
})

return er
Expand Down
7 changes: 6 additions & 1 deletion buffalo/cmd/plugins.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package cmd

import (
"github.com/gobuffalo/buffalo-plugins/plugins"
pluginscmd "github.com/gobuffalo/buffalo/buffalo/cmd/plugins"
"github.com/gobuffalo/buffalo/plugins"
"github.com/markbates/oncer"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

func init() {
RootCmd.AddCommand(pluginscmd.PluginsCmd)
}

var _plugs plugins.List

func plugs() plugins.List {
Expand Down
68 changes: 68 additions & 0 deletions buffalo/cmd/plugins/add.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package plugins

import (
"context"
"os"
"path"
"strings"

"github.com/gobuffalo/buffalo/genny/add"
"github.com/gobuffalo/buffalo/plugins/plugdeps"
"github.com/gobuffalo/genny"
"github.com/gobuffalo/meta"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)

var addOptions = struct {
dryRun bool
buildTags []string
}{}

var addCmd = &cobra.Command{
Use: "add",
Short: "adds plugins to config/buffalo-plugins.toml",
RunE: func(cmd *cobra.Command, args []string) error {
run := genny.WetRunner(context.Background())
if addOptions.dryRun {
run = genny.DryRunner(context.Background())
}

app := meta.New(".")
plugs, err := plugdeps.List(app)
if err != nil && (errors.Cause(err) != plugdeps.ErrMissingConfig) {
return errors.WithStack(err)
}

tags := app.BuildTags("", addOptions.buildTags...)
for _, a := range args {
a = strings.TrimSpace(a)
bin := path.Base(a)
plug := plugdeps.Plugin{
Binary: bin,
GoGet: a,
Tags: tags,
}
if _, err := os.Stat(a); err == nil {
plug.Local = a
plug.GoGet = ""
}
plugs.Add(plug)
}
g, err := add.New(&add.Options{
App: app,
Plugins: plugs.List(),
})
if err != nil {
return errors.WithStack(err)
}
run.With(g)

return run.Run()
},
}

func init() {
addCmd.Flags().BoolVarP(&addOptions.dryRun, "dry-run", "d", false, "dry run")
addCmd.Flags().StringSliceVarP(&addOptions.buildTags, "tags", "t", []string{}, "build tags")
}
28 changes: 28 additions & 0 deletions buffalo/cmd/plugins/available.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package plugins

import (
"github.com/gobuffalo/buffalo/plugins/plugcmds"
"github.com/spf13/cobra"
)

// Available used to manage all of the available commands
// for the plugins
var Available = plugcmds.NewAvailable()

// PluginsCmd is the "root" command for the plugin features.
var PluginsCmd = &cobra.Command{
Use: "plugins",
Short: "tools for working with buffalo plugins",
}

func init() {
PluginsCmd.AddCommand(addCmd)
PluginsCmd.AddCommand(listCmd)
PluginsCmd.AddCommand(generateCmd)
PluginsCmd.AddCommand(removeCmd)
PluginsCmd.AddCommand(installCmd)
PluginsCmd.AddCommand(cacheCmd)

Available.Add("generate", generateCmd)
Available.ListenFor("buffalo:setup:.+", Listen)
}
22 changes: 22 additions & 0 deletions buffalo/cmd/plugins/cache.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package plugins

import (
"github.com/gobuffalo/buffalo/buffalo/cmd/plugins/internal/cache"
"github.com/spf13/cobra"
)

// cacheCmd represents the cache command
var cacheCmd = &cobra.Command{
Use: "cache",
Short: "commands for managing the plugins cache",
RunE: func(cmd *cobra.Command, args []string) error {
return cache.ListCmd.RunE(cmd, args)
},
}

func init() {
cacheCmd.AddCommand(cache.CleanCmd)
cacheCmd.AddCommand(cache.ListCmd)
cacheCmd.AddCommand(cache.BuildCmd)
PluginsCmd.AddCommand(cacheCmd)
}
81 changes: 81 additions & 0 deletions buffalo/cmd/plugins/generate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package plugins

import (
"context"
"fmt"
"path/filepath"
"strings"

"github.com/gobuffalo/buffalo/genny/plugin"
"github.com/gobuffalo/buffalo/genny/plugin/with"
"github.com/gobuffalo/envy"
"github.com/gobuffalo/genny"
"github.com/gobuffalo/gogen"
"github.com/gobuffalo/licenser/genny/licenser"
"github.com/gobuffalo/logger"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

// generateCmd represents the generate command
var generateCmd = &cobra.Command{
Use: "plugin",
Short: "generates a new buffalo plugin",
Long: "buffalo generate plugin github.com/foo/buffalo-bar",
RunE: func(cmd *cobra.Command, args []string) error {
popts := &plugin.Options{
Author: viper.GetString("author"),
ShortName: viper.GetString("short-name"),
License: viper.GetString("license"),
}
if len(args) > 0 {
popts.PluginPkg = args[0]
}

r := genny.WetRunner(context.Background())
if viper.GetBool("dry-run") {
r = genny.DryRunner(context.Background())
}

popts.Root = filepath.Join(envy.GoPath(), "src")

gg, err := plugin.New(popts)
if err != nil {
return errors.WithStack(err)
}
r.Root = popts.Root
r.WithRun(genny.Force(r.Root, viper.GetBool("force")))
r.WithGroup(gg)

if viper.GetBool("with-gen") {
gg, err := with.GenerateCmd(popts)
if err != nil {
return errors.WithStack(err)
}
r.WithGroup(gg)
}

g, err := gogen.Fmt(r.Root)
if err != nil {
return errors.WithStack(err)
}
r.With(g)

if viper.GetBool("verbose") {
r.Logger = logger.New(logger.DebugLevel)
}
return r.Run()
},
}

func init() {
generateCmd.Flags().BoolP("dry-run", "d", false, "run the generator without creating files or running commands")
generateCmd.Flags().BoolP("verbose", "v", false, "turn on verbose logging")
generateCmd.Flags().Bool("with-gen", false, "creates a generator plugin")
generateCmd.Flags().BoolP("force", "f", false, "will delete the target directory if it exists")
generateCmd.Flags().StringP("author", "a", "", "author's name")
generateCmd.Flags().StringP("license", "l", "mit", fmt.Sprintf("choose a license from: [%s]", strings.Join(licenser.Available, ", ")))
generateCmd.Flags().StringP("short-name", "s", "", "a 'short' name for the package")
viper.BindPFlags(generateCmd.Flags())
}
85 changes: 85 additions & 0 deletions buffalo/cmd/plugins/install.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package plugins

import (
"bytes"
"context"
"io"
"os"
"path"
"strings"

"github.com/gobuffalo/buffalo/genny/install"
"github.com/gobuffalo/buffalo/plugins/plugdeps"
"github.com/gobuffalo/genny"
"github.com/gobuffalo/logger"
"github.com/gobuffalo/meta"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)

var installOptions = struct {
dryRun bool
vendor bool
verbose bool
}{}

var installCmd = &cobra.Command{
Use: "install",
Short: "installs plugins listed in config/buffalo-plugins.toml",
RunE: func(cmd *cobra.Command, args []string) error {
run := genny.WetRunner(context.Background())
if installOptions.dryRun {
run = genny.DryRunner(context.Background())
if installOptions.vendor {
run.FileFn = func(f genny.File) (genny.File, error) {
bb := &bytes.Buffer{}
if _, err := io.Copy(bb, f); err != nil {
return f, errors.WithStack(err)
}
return genny.NewFile(f.Name(), bb), nil
}
}
}

app := meta.New(".")
plugs, err := plugdeps.List(app)
if err != nil && (errors.Cause(err) != plugdeps.ErrMissingConfig) {
return errors.WithStack(err)
}

for _, a := range args {
a = strings.TrimSpace(a)
bin := path.Base(a)
plug := plugdeps.Plugin{
Binary: bin,
GoGet: a,
}
if _, err := os.Stat(a); err == nil {
plug.Local = a
plug.GoGet = ""
}
plugs.Add(plug)
}
gg, err := install.New(&install.Options{
App: app,
Plugins: plugs.List(),
Vendor: installOptions.vendor,
})
if err != nil {
return errors.WithStack(err)
}
run.WithGroup(gg)

if installOptions.verbose {
run.Logger = logger.New(logger.DebugLevel)
}

return run.Run()
},
}

func init() {
installCmd.Flags().BoolVarP(&installOptions.dryRun, "dry-run", "d", false, "dry run")
installCmd.Flags().BoolVarP(&installOptions.verbose, "verbose", "v", false, "turn on verbose logging")
installCmd.Flags().BoolVar(&installOptions.vendor, "vendor", false, "will install plugin binaries into ./plugins [WINDOWS not currently supported]")
}
19 changes: 19 additions & 0 deletions buffalo/cmd/plugins/internal/cache/build.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package cache

import (
"os"

"github.com/gobuffalo/buffalo/plugins"
"github.com/spf13/cobra"
)

// BuildCmd rebuilds the plugins cache
var BuildCmd = &cobra.Command{
Use: "build",
Short: "rebuilds the plugins cache",
RunE: func(cmd *cobra.Command, args []string) error {
os.RemoveAll(plugins.CachePath)
_, err := plugins.Available()
return err
},
}
18 changes: 18 additions & 0 deletions buffalo/cmd/plugins/internal/cache/clean.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package cache

import (
"os"

"github.com/gobuffalo/buffalo/plugins"
"github.com/spf13/cobra"
)

// CleanCmd cleans the plugins cache
var CleanCmd = &cobra.Command{
Use: "clean",
Short: "cleans the plugins cache",
RunE: func(cmd *cobra.Command, args []string) error {
os.RemoveAll(plugins.CachePath)
return nil
},
}
Loading