美文网首页ios developers
自定义 fastlane 插件 yhpgyer

自定义 fastlane 插件 yhpgyer

作者: who_young | 来源:发表于2023-04-05 00:18 被阅读0次

yhpgyer 是在 fastlane-plugin-pgyer 插件的基础上,实现 ipa 文件上传到蒲公英后,返回安装包二维码下载链接的功能。本文以此来介绍如何创建自定义插件。创建方法参见官方文档:Create your own fastlane plugin

创建插件

打开终端,依次执行如下命令:

# 定位到 home 目录下。(可按自己喜好选择目录)。
cd ~
# 创建 yhpgyer 文件夹。
mkdir yhPgyer
# 定位到 yhpgyer 文件夹下。
cd yhpgyer
# 创建 yhpgyer 插件
fastlane new_plugin yhpgyer

然后根据终端提示输入:y,以及插件的总结和描述。

[14:07:58]: Would 'yhpgyer' be okay to use for your plugin name? (y/n)
y
[14:07:58]: Please enter a short summary of this fastlane plugin:
distribute app to pgyer beta testing service
[14:09:15]: Please enter a detailed description of this fastlane plugin:
distribute app to pgyer beta testing service

执行完上面的操作后,用文本编译器打开 ~/yhpgyer/fastlane-plugin-yhpgyer/lib/fastlane/plugin/yhpgyer/actions/yhpgyer_action.rb 文件,实现文件内的方法即可。

yhpgyer_action
yhpgyer 插件,复制了 pgyer 插件的实现代码后,修改了 self.checkPublishStatus 方法,增加了上传 ipa 文件成功后,返回安装包二维码下载链接的功能。
image.png

使用本地 fastlane 插件

打开终端,依次执行如下命令:

# 定位到要使用本地 fastlane 插件的项目目录下。
cd /path/projectName
# 添加插件
fastlane add_plugin

然后根据终端提示,依次输入:yhpgyer、2、本地插件的路径~/yhpgyer/fastlane-plugin-yhpgyer

[15:11:54]: Enter the name of the plugin to install: yhpgyer
[15:12:00]: Seems like the plugin is not available on RubyGems, what do you want to do?
1. Git URL
2. Local Path
3. RubyGems.org ('fastlane-plugin-yhpgyer' seems to not be available there)
4. Other Gem Server
?  2
[15:12:02]: Please enter the relative path to the plugin you want to use. It
has to point to the directory containing the .gemspec file
~/yhpgyer/fastlane-plugin-yhpgyer
[15:12:19]: Plugin 'fastlane-plugin-yhpgyer' was added to './fastlane/Pluginfile'

执行完上面的命令,我们可以看到项目目录下的./fastlane/Pluginfile文件被添加了gem "fastlane-plugin-yhpgyer", path: "~/yhpgyer/fastlane-plugin-yhpgyer",这个就是指定本地插件的路径。

发布自定义 fastlane 插件

1.在RubyGems官网上注册账号
2.将你的插件发布到 github 上(整个fastlane-plugin-[plugin name]文件夹)
3.将.gemspec文件中的spec.homepage参数改为你的github地址
4.执行以下指令,进行发布操作

bundle install
rake install
rake release

上述命令都执行成功后,即可通过 fastlane add_plugin yhpgyer 安装插件了。

通过 github 链接使用自定义插件

如果不想通过 RubyGems 发布插件,我们可以通过 github 上的插件仓库地址来使用自定义插件。
只需要将项目目录下的 ./fastlane/Pluginfile 文件添加 gem "fastlane-plugin-yhpgyer", git: "https://github.com/whoyoung/yhpgyer" 即可。

相关文章

网友评论

    本文标题:自定义 fastlane 插件 yhpgyer

    本文链接:https://www.haomeiwen.com/subject/hinsddtx.html