插件
5 分钟阅读
Plugins 插件
Since 0.9.1 自 0.9.1 起
Plugins allow for 3rd party code to extend the buffalo
command as well as its sub-commands.
插件允许第三方代码扩展 buffalo
命令及其子命令。
Installing the buffalo-plugins Plugin 安装 buffalo-plugins 插件
|
|
Finding Available Plugins 查找可用插件
A full list of Plugins can be found at https://toolkit.gobuffalo.io/tools?topic=plugin.
可以在 https://toolkit.gobuffalo.io/tools?topic=plugin 找到插件的完整列表。
To get your project listed on the Buffalo Toolkit you must tag your project on GitHub with gobuffalo
.
要将您的项目列在 Buffalo Toolkit 上,您必须在 GitHub 上使用 gobuffalo
标记您的项目。
There are a few more tags that you can use that will help the Buffalo Toolkit better categorize your project. You can add as many of this tags to your project as is suitable. Please try to refrain from using more than just a few tags.
还有几个其他标签可供您使用,它们将帮助 Buffalo Toolkit 更好地对您的项目进行分类。您可以根据需要向您的项目添加任意数量的这些标签。请尽量不要使用超过几个标签。
plugin
- Pluginsplugin
- 插件generator
- Generatorsgenerator
- 生成器middleware
- Middlewaremiddleware
- 中间件pop
- Pop/Sodapop
- 流行/苏打水templating
- Templatingtemplating
- 模板化grifts
- Grift Tasksgrifts
- 欺诈任务deployment
- Deploymentdeployment
- 部署testing
- Testingtesting
- 测试example
- Example Appsexample
- 示例应用程序worker
- Workers/Adaptersworker
- 工作人员/适配器webpack
- Webpack/Front-Endwebpack
- Webpack/前端
Any other tags will still be indexed and searchable, but the tool may not show in the “known” categories section.
任何其他标签仍将被索引并可搜索,但该工具可能不会显示在“已知”类别部分。
How Does Buffalo Find Plugins? Buffalo 如何查找插件?
Buffalo plugins have a set of rules that must be followed for them to be consider, by Buffalo, as a plugin.
Buffalo 插件有一组规则,必须遵循这些规则才能被 Buffalo 视为插件。
Plugins must be named in the format of
buffalo-<plugin-name>
. For example,buffalo-myplugin
. 插件必须以buffalo-<plugin-name>
的格式命名。例如,buffalo-myplugin
。Plugins must be executable and must be available in one of the following places:
插件必须可执行,并且必须位于以下位置之一:
- in the
$BUFFALO_PLUGIN_PATH
在$BUFFALO_PLUGIN_PATH
- if not set,
$GOPATH/bin
, is tried 如果未设置,则尝试$GOPATH/bin
- in the
./plugins
folder of your Buffalo application 在 Buffalo 应用程序的./plugins
文件夹中
- in the
Plugins must implement an
available
command that prints a JSON response listing the available commands. 插件必须实现一个available
命令,该命令打印一个 JSON 响应,列出可用的命令。
The buffalo plugins list
command will print a table of plugins that Buffalo sees as “available” to you.
buffalo plugins list
命令将打印一个 Buffalo 视为“可供您使用”的插件表。
With Configuration 带配置
Since 1.1.0 自 1.1.0 起
When a config/buffalo-plugins.toml
file is present, Buffalo will scope the list of plugins that are “available” to those listed in the configuration file.
当存在 config/buffalo-plugins.toml
文件时,Buffalo 将把“可用”插件列表限定为配置文件中列出的那些插件。
|
|
Without Configuration 无配置
Without a configuration file, Buffalo will try to aforementioned paths to find any, and all Buffalo plugins installed on the users system.
如果没有配置文件,Buffalo 将尝试上述路径以查找用户系统上安装的所有 Buffalo 插件。
|
|
Installing Plugins 安装插件
Since 1.1.0 自 1.1.0 起
To add support for the plugin manager, one can either manually edit ./config/buffalo-plugins.toml
or let buffalo plugins install
create it for you.
要添加对插件管理器的支持,可以手动编辑 ./config/buffalo-plugins.toml
或让 buffalo plugins install
为您创建它。
Install command 安装命令
Config file 配置文件
Resulting plugin list 生成的插件列表
|
|
The buffalo-pop
plugin was automatically added because the application in this example is a Buffalo application that uses Pop.
buffalo-pop
插件已自动添加,因为此示例中的应用程序是使用 Pop 的 Buffalo 应用程序。
New plugins can be install in bulk with the install
command
可以使用 install
命令批量安装新插件
Bulk Install command 批量安装命令
Config file 配置文件
Resulting plugin list 生成的插件列表
|
|
Removing Plugins 删除插件 # 自 1.1.0 起
Since 1.1.0 可以使用 命令删除插件。这只会将它们从配置文件中删除,而不会从用户系统中删除。 删除命令
Plugins can be removed with the remove
command. This only removes them from the config file, not from the users system.
Remove command
Config file 配置文件
Resulting plugin list 生成的插件列表
|
|
Writing a Plugin 编写插件
First, you must understand how Buffalo finds plugins, before you can successfully write one.
首先,您必须了解 Buffalo 如何查找插件,然后才能成功编写一个插件。
The buffalo-plugins
plugin adds a new generator to buffalo generate
to help you build a new plugin quickly
buffalo-plugins
插件为 buffalo generate
添加了一个新的生成器,以帮助您快速构建一个新插件
|
|
LICENSE 许可证
Makefile
main.go
bar/version.go
cmd/available.go
cmd/bar.go
cmd/root.go
cmd/version.go
|
|
Writing Non-Go Plugins 编写非 Go 插件
Plugins do not need to be written in Go. They can be written in any language you would like, as long as they comply with the rules above.
插件无需用 Go 编写。只要符合上述规则,您就可以使用任何您喜欢的语言编写插件。
For example, we can write the following plugin using Ruby:
例如,我们可以使用 Ruby 编写以下插件:
|
|
To activate the plugin we need to add the file as buffalo-hello.rb
to somewhere in the $PATH
or in a directory called plugins/
inside of a Buffalo application.
要激活插件,我们需要将文件作为 buffalo-hello.rb
添加到 $PATH
中的某个位置,或添加到 Buffalo 应用程序内的名为 plugins/
的目录中。
Finally the file needs to be made executable. On a Mac/Linux it can be done with chmod +x buffalo-hello.rb
.
最后,该文件需要可执行。在 Mac/Linux 上,可以使用 chmod +x buffalo-hello.rb
来执行此操作。
|
|