title: 小程序持续集成

:::info 目前仅支持微信字节支付宝百度小程序。 :::

Taro 小程序端构建后支持 CI(持续集成)的插件 @tarojs/plugin-mini-ci

功能包括:

  • 构建完毕后自动打开小程序开发者工具
  • 上传体验版
  • 生成预览二维码

使用

安装

  1. npm i @tarojs/plugin-mini-ci -D

使用插件

配置 Taro 编译选项:

```js title=”config/index.js” // 如果你使用 VSCode 作为开发工具, 你还可以使用注释的语法引入插件包含的声明文件,可获得类似于 Typescript 的友好提示 /**

  • @typedef { import(“@tarojs/plugin-mini-ci”).CIOptions } CIOptions
  • @type {CIOptions} */ const CIPluginOpt = { // 微信小程序 weapp: { appid: “微信小程序appid”, privateKeyPath: “密钥文件相对项目根目录的相对路径,例如 key/private.appid.key” }, // 字节跳动小程序 tt: { email: “字节小程序邮箱”, password: “字节小程序密码” }, // 支付宝小程序 alipay: { appId: “支付宝小程序appId”, toolId: “工具id”, privateKeyPath: “密钥文件相对项目根目录的相对路径,例如 key/pkcs8-private-pem” }, // 百度小程序 swan: { token: “鉴权需要的token令牌” }, // 版本号 version: “1.0.0”, // 版本发布描述 desc: “版本描述” }

const config = { plugins: [ [“@tarojs/plugin-mini-ci”, CIPluginOpt] ] }

  1. ### 配置 NPM Script
  2. 修改 `package.json`
  3. ```json title="package.json"
  4. {
  5. "scripts": {
  6. // 构建完后自动 “打开开发者工具”
  7. "build:weapp": "taro build --type weapp --open",
  8. // 构建完后自动“上传代码作为体验版”
  9. "build:weapp:upload": "taro build --type weapp --upload",
  10. // 构建完后自动 “上传代码作为开发版并生成预览二维码”
  11. "build:weapp:preview": "taro build --type weapp --preview"
  12. },
  13. "taroConfig": {
  14. "version": "1.0.0",
  15. "desc": "上传描述"
  16. }
  17. }

由上面的示例可知,插件为 Taro CLI 命令扩展了 3 个选项:

  • --open 打开开发者工具,类似于网页开发中自动打开谷歌浏览器
  • --upload 上传代码作为体验版
  • --preview 上传代码作为开发版并生成预览二维码

:::note 上述 3 个选项在一条命令里不能同时使用 :::

API

插件配置

参数 类型 说明
weapp Object 微信小程序 CI 配置
tt Object 头条小程序配置
alipay Object 支付宝小程序配置
swan Object 百度小程序配置
version string 上传的版本号。不传时默认读取 package.json 里 taroConfig 下的 version 字段
desc string 上传时的描述信息。不传时默认读取 package.json 里 taroConfig 下的 desc 字段

微信小程序 CI 配置

官方 CI 文档

参数 类型 说明
appid string 小程序/小游戏项目的 appid
privateKeyPath string 私钥文件在项目中的相对路径,在获取项目属性和上传时用于鉴权使用
devToolsInstallPath string 微信开发者工具安装路径,如果你安装微信开发者工具时选的默认路径,则不需要传入此参数
projectPath string 上传的小程序的路径(默认取的 outputPath )
ignores string[] 上传需要排除的目录(选填)

头条小程序 CI 配置

官方 CI 文档

参数 类型 说明
email string 字节小程序邮箱
password string 字节小程序密码

支付宝小程序 CI 配置

官方CI文档

参数 类型 说明
appId string 小程序appId
toolId string 工具 id,生成方式请查看这里
privateKeyPath string 密钥文件相对项目根目录的相对路径,支付宝生产的私钥文件名一般是 pkcs8-private-pem
clientType string 上传的终端,终端类型见下表(默认值 alipay

clientType 终端类型值及其含义:

终端类型 含义
alipay 支付宝
ampe AMPE
amap 高德
genie 天猫精灵
alios ALIOS
uc UC
quark 夸克
taobao 淘宝
koubei 口碑
alipayiot IoT
cainiao 菜鸟
alihealth 阿里健康

百度小程序CI配置

官方CI文档

参数 类型 说明
token string 有该小程序发布权限的登录密钥
minSwanVersion string 最低基础库版本, 不传默认为 3.350.6

Ts 接口描述

  1. export interface IOptions {
  2. version?: string
  3. desc?: string
  4. weapp?: WeappConfig
  5. tt?: TTConfig
  6. alipay?: AlipayConfig
  7. swan?: SwanConfig
  8. }
  9. /** 微信小程序配置 */
  10. export interface WeappConfig {
  11. /** 小程序/小游戏项目的 appid */
  12. appid: string
  13. /** 私钥,在获取项目属性和上传时用于鉴权使用(必填) */
  14. privateKeyPath: string
  15. /** 微信开发者工具安装路径 */
  16. devToolsInstallPath?: string
  17. /** 上传的小程序的路径(默认 outputPath) */
  18. projectPath?: string
  19. /** 类型,默认miniProgram 小程序 */
  20. type?: ProjectType
  21. /** 上传需要排除的目录 */
  22. ignores?: Array<string>
  23. }
  24. /** 头条小程序配置 */
  25. export interface TTConfig {
  26. email: string
  27. password: string
  28. }
  29. /** 终端类型 */
  30. export type ClientType =
  31. /** 支付宝 */'alipay' |
  32. /** AMPE */'ampe' |
  33. /** 高德 */'amap' |
  34. /** 天猫精灵 */'genie'|
  35. /** ALIOS */ 'alios'|
  36. /** UC */'uc'|
  37. /** 夸克 */ 'quark'|
  38. /** 淘宝 */ 'taobao'|
  39. /** 口碑 */'koubei' |
  40. /** loT */'alipayiot'|
  41. /** 菜鸟 */'cainiao' |
  42. /** 阿里健康 */ 'alihealth'
  43. /** 支付宝系列小程序配置 */
  44. export interface AlipayConfig {
  45. /** 小程序 appId */
  46. appId: string
  47. /** 工具 id */
  48. toolId: string
  49. /** 工具私钥 */
  50. privateKey: string
  51. /** 服务代理地址(可选) */
  52. proxy?: string
  53. /** 上传的终端, 默认 alipay */
  54. clientType?: ClientType
  55. }
  56. /** 百度小程序配置 */
  57. export interface SwanConfig {
  58. /** 有该小程序发布权限的登录密钥 */
  59. token: string
  60. /** 最低基础库版本, 不传默认为 3.350.6 */
  61. minSwanVersion?: string
  62. }