This repository has been archived by the owner on Feb 24, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 579
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d8330db
commit 64eb933
Showing
72 changed files
with
2,815 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}, | ||
} |
Oops, something went wrong.