@tarojs/plugin-mini-ci 3.5.10 → 3.6.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,15 +1,17 @@
1
1
  # @tarojs/plugin-mini-ci
2
2
 
3
- > Taro 小程序端构建后支持CI(持续集成)的插件, 支持构建完毕后自动打开小程序开发这个工具、上传作为体验版、生成预览二维码. 目前暂时仅支持微信、字节、支付宝、百度小程序
3
+ > Taro 小程序端构建后支持CI(持续集成)的插件, 支持构建完毕后自动打开小程序开发这个工具、上传作为体验版、生成预览二维码. 目前支持(企业)微信、字节、支付宝、钉钉、百度小程序
4
4
 
5
5
  ## 使用
6
6
 
7
7
  ### 安装
8
- ```
8
+
9
+ ```sh
9
10
  npm i @tarojs/plugin-mini-ci -D
10
11
  ```
11
12
 
12
13
  ### 使用插件
14
+
13
15
  `/config/index.js`
14
16
 
15
17
  ```js
@@ -28,10 +30,14 @@ const CIPluginOpt = {
28
30
  password: "字节小程序密码"
29
31
  },
30
32
  alipay: {
31
- appId: "支付宝小程序appId",
33
+ appid: "支付宝小程序appid",
32
34
  toolId: "工具id",
33
35
  privateKeyPath: "密钥文件相对项目根目录的相对路径,例如 key/pkcs8-private-pem"
34
36
  },
37
+ dd: {
38
+ appid: "钉钉小程序appid,即钉钉开放平台后台应用管理的 MiniAppId 选项",
39
+ token: "令牌,从钉钉后台获取"
40
+ },
35
41
  swan: {
36
42
  token: "鉴权需要的token令牌"
37
43
  },
@@ -47,7 +53,51 @@ const config = {
47
53
  }
48
54
  ```
49
55
 
50
- ### 配置命令
56
+ 除了给插件传入对象, 你也可以传入一个异步函数,在编译时动态返回相关配置。
57
+
58
+ ```js
59
+ const CIPluginFn = async () => {
60
+ // 可以在这里做一些异步事情, 比如请求接口获取配置
61
+ /**
62
+ * @typedef { import("@tarojs/plugin-mini-ci").CIOptions } CIOptions
63
+ * @type {CIOptions}
64
+ */
65
+ return {
66
+ weapp: {
67
+ appid: "微信小程序appid",
68
+ privateKeyPath: "密钥文件相对项目根目录的相对路径,例如 key/private.appid.key"
69
+ },
70
+ tt: {
71
+ email: "字节小程序邮箱",
72
+ password: "字节小程序密码"
73
+ },
74
+ alipay: {
75
+ appid: "支付宝小程序appid",
76
+ toolId: "工具id",
77
+ privateKeyPath: "密钥文件相对项目根目录的相对路径,例如 key/pkcs8-private-pem"
78
+ },
79
+ dd: {
80
+ appid: "钉钉小程序appid,即钉钉开放平台后台应用管理的 MiniAppId 选项"
81
+ token: "令牌,从钉钉后台获取"
82
+ },
83
+ swan: {
84
+ token: "鉴权需要的token令牌"
85
+ },
86
+ // 版本号
87
+ version: "1.0.0",
88
+ // 版本发布描述
89
+ desc: "版本描述"
90
+ }
91
+ }
92
+
93
+ const config = {
94
+ plugins: [
95
+ [ "@tarojs/plugin-mini-ci", CIPluginFn ]
96
+ ]
97
+ }
98
+ ```
99
+
100
+ ### 作为选项配合 build 命令使用
51
101
 
52
102
  `package.json` 的 `scripts` 字段使用命令参数
53
103
 
@@ -56,10 +106,12 @@ const config = {
56
106
  "scripts": {
57
107
  // 构建完后自动 “打开开发者工具”
58
108
  "build:weapp": "taro build --type weapp --open",
109
+ // 构建完后自动 “上传代码作为开发版并生成预览二维码”
110
+ "build:weapp:preview": "taro build --type weapp --preview",
59
111
  // 构建完后自动“上传代码作为体验版”
60
112
  "build:weapp:upload": "taro build --type weapp --upload",
61
- // 构建完后自动 “上传代码作为开发版并生成预览二维码”
62
- "build:weapp:preview": "taro build --type weapp --preview"
113
+ // 构建完后自动“上传 dist/xxx 目录的代码作为体验版”, `--projectPath` 参数 适用于 taro 和 原生混合的场景
114
+ "build:weapp:upload": "taro build --type weapp --upload --projectPath dist/xxx"
63
115
  },
64
116
  "taroConfig": {
65
117
  "version": "1.0.0",
@@ -67,39 +119,174 @@ const config = {
67
119
  }
68
120
  }
69
121
  ```
70
- 由上面的示例可知,插件为taro cli命令扩展了3个选项:
122
+
123
+ 由上面的示例可知,插件为taro cli命令扩展了4个选项:
71
124
 
72
125
  - --open
73
126
  打开开发者工具,类似于网页开发中自动打开谷歌浏览器
74
- - --upload
75
- 上传代码作为体验版
76
127
  - --preview
77
128
  上传代码作为开发版并生成预览二维码
129
+ - --upload
130
+ 上传代码作为体验版
78
131
 
79
- 此3个选项在一条命令里不能同时使用
132
+ 此3个选项在一条命令里不能同时使用(互斥)
80
133
 
81
- ## API
134
+ - --projectPath
135
+ 指定要操作(打开、预览、上传)的目录路径, 默认情况下是操作构建后目录路径,即 [outputRoot选项](https://taro-docs.jd.com/taro/docs/next/config-detail#outputroot);
136
+
137
+ 此选项必须搭配上述三个选项之一一起使用;
138
+
139
+ 此选项优先级为: 终端传入的`--projectPath` > CI配置的`projectPath` 选项 > [outputRoot选项](https://taro-docs.jd.com/taro/docs/next/config-detail#outputroot)。
140
+
141
+ ### 作为命令单独使用
142
+
143
+ ```json
144
+ {
145
+ "scripts": {
146
+ // 直接 “打开开发者工具并载入项目”
147
+ "build:weapp": "taro open --type weapp --projectPath dist/xxx",
148
+ // 直接 “上传代码作为开发版并生成预览二维码”
149
+ "build:weapp:preview": "taro preview --type weapp",
150
+ // 直接“上传代码作为体验版”
151
+ "build:weapp:upload": "taro upload --type weapp",
152
+ // 上传指定目录代码作为体验版
153
+ "build:weapp:upload2": "taro upload --type weapp --projectPath dist/xxx",
154
+ },
155
+ "taroConfig": {
156
+ "version": "1.0.0",
157
+ "desc": "上传描述"
158
+ }
159
+ }
160
+ ```
161
+
162
+ 由上面的示例可知,插件额外新增了3个独立命令,让你可以直接操作指定目录。适用于把 `taro` 作为项目一部分的使用场景。
163
+
164
+ 当直接作为命令使用时,有两个选项:
165
+
166
+ - --type
167
+ 传入平台名称
168
+ - --projectPath
169
+ 传入路径。 此选项优先级为: 终端传入的`--projectPath` > CI配置的`projectPath` 选项 > [outputRoot选项](https://taro-docs.jd.com/taro/docs/next/config-detail#outputroot)
170
+
171
+ ### Hooks 使用
82
172
 
173
+ 在插件执行完 `预览`、`上传` 操作后, 插件会触发2个钩子事件:
174
+
175
+ | 事件名 | 传递参数对象 | 说明 |
176
+ | :--- | :--- | :--- |
177
+ | onPreviewComplete | 详细见下文 | CI 执行预览后触发 |
178
+ | onUploadComplete | 详细见下文| CI 执行上传后触发 |
179
+
180
+ 两个钩子被触发时传入的数据对象描述如下
181
+
182
+ ```ts
183
+ interface HooksData {
184
+ /** 是否预览、构建成功 */
185
+ success: boolean;
186
+ data: {
187
+ /** 当前构建的小程序平台 */
188
+ platform: string;
189
+ /** 预览码本地路径 */
190
+ qrCodeLocalPath: string;
191
+ /** 预览码内容 */
192
+ qrCodeContent: string;
193
+ /** 插件传递的预览版本号 */
194
+ version: string;
195
+ /** 插件传递的描述文本 */
196
+ desc: string;
197
+ /** 预览或上传的目录路径 */
198
+ projectPath: string;
199
+ },
200
+ /** 错误对象 */
201
+ error?: Error;
202
+ }
203
+ ```
204
+
205
+ 你可以写一个自定义插件,来接收上述2个事件传递的值:
206
+
207
+ ```js
208
+ // config/test.js
209
+ module.exports = function(ctx) {
210
+ ctx.register({
211
+ name: 'onPreviewComplete',
212
+ fn: ({success, data, error}) => {
213
+ console.log('接收预览后数据', success, data, error)
214
+ // 你可以在这里发送钉钉或者飞书消息
215
+ }
216
+ })
217
+ ctx.register({
218
+ name: 'onUploadComplete',
219
+ fn: ({success, data, error}) => {
220
+ console.log('接收上传后数据', success, data, error)
221
+ // 你可以在这里发送钉钉或者飞书消息
222
+ }
223
+ })
224
+ }
225
+ ```
226
+
227
+ 然后把自己写的插件配置应用起来:
228
+
229
+ ```js
230
+ // config/index.js
231
+ const config = {
232
+
233
+ plugins: [
234
+ ["@tarojs/plugin-mini-ci", CI插件参数],
235
+ // 应用自己写的插件
236
+ require('path').join(__dirname, './test' )
237
+ ],
238
+ ... 其他配置省略
239
+
240
+ }
241
+
242
+ module.exports = function (merge) {
243
+ if (process.env.NODE_ENV === 'development') {
244
+ return merge({}, config, require('./dev'))
245
+ }
246
+ return merge({}, config, require('./prod'))
247
+ }
248
+ ```
249
+
250
+ ### 各平台 支持的功能情况对比
251
+
252
+ | 平台/功能 | 自动打开IDE | 输出预览二维码 | 输出体验二维码 |
253
+ | :--- | :--- | :--- | :--- |
254
+ | weapp | ✅ | ✅ |✅ |
255
+ | qywx | ✅ | ✅ |✅ |
256
+ | tt | ✅ | ✅ |✅ |
257
+ | alipay | ✅ | ✅ |✅ |
258
+ | dd | ✅ | ✅ |❌ |
259
+ | swan | ✅ | ✅ |✅ |
260
+
261
+ > ps: 各平台上传都是支持的,只是不一定会输出二维码
262
+
263
+ > 企业微信和微信的各项参数是一样的,共用一个配置
264
+
265
+ ## API
83
266
 
84
267
  ### 插件配置
85
268
 
86
269
  | 参数 | 类型 | 说明 |
87
270
  | :--- | :--- | :--- |
88
- | weapp | Object | 微信小程序CI配置 |
271
+ | weapp | Object | (企业)微信小程序CI配置 |
89
272
  | tt | Object | 头条小程序配置 |
90
273
  | alipay | Object | 支付宝小程序配置 |
274
+ | dd | Object | 钉钉小程序配置(3.6.0 版本开始支持) |
91
275
  | swan | Object | 百度小程序配置 |
92
276
  | version | string | 上传版本号,不传时默认读取package.json下的taroConfig下的version字段 |
93
277
  | desc | string | 上传时的描述信息,不传时默认读取package.json下的taroConfig下的desc字段 |
278
+ | projectPath | string | 目标项目目录,对所有小程序生效(不传默认取 outputRoot 字段 )(3.6.0 版本开始支持) |
279
+
280
+ ### (企业)微信小程序CI配置
94
281
 
95
- ### 微信小程序CI配置
96
282
  | 参数 | 类型 | 说明 |
97
283
  | :--- | :--- | :--- |
98
284
  | appid | string | 小程序/小游戏项目的 appid |
99
285
  | privateKeyPath | string | 私钥文件在项目中的相对路径,在获取项目属性和上传时用于鉴权使用|
100
- | devToolsInstallPath | string | 微信开发者工具安装路径,如果你安装微信开发者工具时选的默认路径,则不需要传入此参数 |
101
- | projectPath | string | 上传的小程序的路径(默认取的 outputPath |
286
+ | devToolsInstallPath | string | 微信开发者工具安装路径,如果你安装微信开发者工具时选的默认路径,则不需要传入此参数(选填) |
287
+ | projectPath | string | 上传的小程序的路径(默认取的 outputRoot )(3.6.0 版本已废弃) |
102
288
  | ignores | string[] | 上传需要排除的目录(选填) |
289
+ | robot | number | 指定使用哪一个 ci 机器人,可选值:1 ~ 30(选填, 3.6.0 版本开始支持) |
103
290
 
104
291
  官方CI文档[点这里](https://developers.weixin.qq.com/miniprogram/dev/devtools/ci.html)
105
292
 
@@ -116,10 +303,12 @@ const config = {
116
303
 
117
304
  | 参数 | 类型 | 说明 |
118
305
  | :--- | :--- | :--- |
119
- | appId | string | 小程序appId |
120
- | toolId | string | 工具id,生成方式[查看这里](https://opendocs.alipay.com/mini/miniu/api#%E5%88%9D%E5%A7%8B%E5%8C%96%E9%85%8D%E7%BD%AE%EF%BC%88%E4%B9%8B%E5%89%8D%E7%9A%84%E6%96%B9%E5%BC%8F%EF%BC%8C%E6%8E%A8%E8%8D%90%E4%BD%BF%E7%94%A8%20miniu%20login%EF%BC%89) |
121
- | privateKeyPath | string | 密钥文件相对项目根目录的相对路径, 支付宝生产的私钥文件名一般是 pkcs8-private-pem |
122
- | clientType | string | 上传的终端,终端类型见下表(默认值alipay) |
306
+ | appid | string | 小程序appid(`3.6.0` 之前参数名是 `appId` , `3.6.0` 开始统一成`appid`) |
307
+ | toolId | string | 工具id[查看这里复制](https://open.alipay.com/dev/workspace/key-manage/tool) |
308
+ | privateKeyPath | string | 密钥文件相对项目根目录的相对路径, 私钥可通过[支付宝开放平台开发助手](https://opendocs.alipay.com/common/02kipl)生成 |
309
+ | privateKey | string | 私钥文本内容, 生成方式同上(privateKeyPath和privateKey之间必须要填写其中一个; 3.6.0 版本开始支持) |
310
+ | devToolsInstallPath | string | 小程序开发者工具安装路径(选填, 3.6.0 版本开始支持) |
311
+ | clientType | string | 上传的终端,终端类型见下表(选填,默认值alipay) |
123
312
 
124
313
  ```
125
314
  终端类型值及其含义:
@@ -138,8 +327,6 @@ uc:UC
138
327
 
139
328
  quark:夸克
140
329
 
141
- taobao:淘宝
142
-
143
330
  koubei:口碑
144
331
 
145
332
  alipayiot:IoT
@@ -147,9 +334,21 @@ alipayiot:IoT
147
334
  cainiao:菜鸟
148
335
 
149
336
  alihealth:阿里健康
337
+
338
+ health: 阿里医院
150
339
  ```
151
340
 
152
- 官方CI文档[点这里](https://opendocs.alipay.com/mini/miniu/api)
341
+ 官方CI文档[点这里](https://opendocs.alipay.com/mini/02q29z)
342
+
343
+ ### 钉钉小程序CI配置(3.6.0 版本开始支持)
344
+
345
+ | 参数 | 类型 | 说明 |
346
+ | :--- | :--- | :--- |
347
+ | appid | string | 钉钉小程序appid,即钉钉开放平台后台应用管理的 MiniAppId 选项(必填) |
348
+ | token | string | 令牌,从钉钉后台获取 (必填) |
349
+ | devToolsInstallPath | string | 小程序开发者工具安装路径(选填) |
350
+
351
+ `taro` 集成的钉钉CI使用了[钉钉官方仓库](https://github.com/open-dingtalk/dingtalk-design-cli)中的 `dingtalk-miniapp-opensdk` 包,查阅源码封装而成
153
352
 
154
353
  ### 百度小程序CI配置
155
354
 
@@ -160,41 +359,56 @@ alihealth:阿里健康
160
359
 
161
360
  官方CI文档[点这里](https://smartprogram.baidu.com/docs/develop/devtools/commandtool/)
162
361
 
163
- ### ts 接口描述
362
+ ### 完整 ts 接口描述
363
+
164
364
  ```ts
165
- export interface IOptions {
166
- version?: string;
167
- desc?: string;
168
- weapp?: WeappConfig;
169
- tt?: TTConfig;
170
- alipay?: AlipayConfig;
171
- swan?: SwanConfig;
365
+ export interface CIOptions {
366
+ /** 发布版本号,默认取 package.json 文件的 taroConfig.version 字段 */
367
+ version?: string
368
+ /** 版本发布描述, 默认取 package.json 文件的 taroConfig.desc 字段 */
369
+ desc?: string
370
+ /** 目标项目目录,对所有小程序生效(不传默认取 outputRoot 字段 ) */
371
+ projectPath?: string
372
+ /** 微信小程序CI配置, 官方文档地址:https://developers.weixin.qq.com/miniprogram/dev/devtools/ci.html */
373
+ weapp?: WeappConfig
374
+ /** 头条小程序配置, 官方文档地址:https://microapp.bytedance.com/docs/zh-CN/mini-app/develop/developer-instrument/development-assistance/ide-order-instrument */
375
+ tt?: TTConfig
376
+ /** 支付宝系列小程序配置,官方文档地址: https://opendocs.alipay.com/mini/miniu/api */
377
+ alipay?: AlipayConfig
378
+ /** 钉钉小程序配置 */
379
+ dd?: DingtalkConfig
380
+ /** 百度小程序配置, 官方文档地址:https://smartprogram.baidu.com/docs/develop/devtools/commandtool/ */
381
+ swan?: SwanConfig
172
382
  }
173
383
 
384
+ export type ProjectType = 'miniProgram' | 'miniGame' | 'miniProgramPlugin' | 'miniGamePlugin';
385
+
174
386
  /** 微信小程序配置 */
175
387
  export interface WeappConfig {
176
388
  /** 小程序/小游戏项目的 appid */
177
- appid: string;
178
- /** 私钥,在获取项目属性和上传时用于鉴权使用(必填) */
179
- privateKeyPath: string;
389
+ appid: string
390
+ /** 私钥文件路径,在获取项目属性和上传时用于鉴权使用 */
391
+ privateKeyPath: string
180
392
  /** 微信开发者工具安装路径 */
181
- devToolsInstallPath?: string;
182
- /** 上传的小程序的路径(默认 outputPath ) */
183
- projectPath?: string;
393
+ devToolsInstallPath?: string
184
394
  /** 类型,默认miniProgram 小程序 */
185
- type?: ProjectType;
395
+ type?: ProjectType
186
396
  /** 上传需要排除的目录 */
187
- ignores?: Array<string>;
397
+ ignores?: Array<string>
398
+ /** 指定使用哪一个 ci 机器人,可选值:1 ~ 30 */
399
+ robot?: number
188
400
  }
189
401
 
190
402
  /** 头条小程序配置 */
191
403
  export interface TTConfig {
192
- email: string;
193
- password: string;
404
+ /** 绑定的邮箱账号 */
405
+ email: string
406
+ /** 密码 */
407
+ password: string
194
408
  }
195
409
 
196
410
  /** 终端类型 */
197
- export type ClientType =
411
+ export type AlipayClientType =
198
412
  /** 支付宝 */'alipay' |
199
413
  /** AMPE */'ampe' |
200
414
  /** 高德 */'amap' |
@@ -202,31 +416,56 @@ export type ClientType =
202
416
  /** ALIOS */ 'alios'|
203
417
  /** UC */'uc'|
204
418
  /** 夸克 */ 'quark'|
205
- /** 淘宝 */ 'taobao'|
206
419
  /** 口碑 */'koubei' |
207
420
  /** loT */'alipayiot'|
208
421
  /** 菜鸟 */'cainiao' |
209
- /** 阿里健康 */ 'alihealth'
422
+ /** 阿里健康(医蝶谷) */ 'alihealth'|
423
+ /** 阿里医院 */ 'health'
210
424
 
211
425
  /** 支付宝系列小程序配置 */
212
426
  export interface AlipayConfig {
213
- /** 小程序appId */
214
- appId: string;
427
+ /** 小程序appid */
428
+ appid: string
215
429
  /** 工具id */
216
- toolId: string;
217
- /** 工具私钥 */
218
- privateKey: string;
219
- /** 服务代理地址(可选) */
220
- proxy?: string;
430
+ toolId: string
431
+ /** 私钥文件路径,在获取项目属性和上传时用于鉴权使用(privateKeyPath和privateKey之间必须要填写其中一个) */
432
+ privateKeyPath: string
433
+ /** 私钥文本内容,在获取项目属性和上传时用于鉴权使用(privateKeyPath和privateKey之间必须要填写其中一个) */
434
+ privateKey: string
435
+ /** 小程序开发者工具安装路径 */
436
+ devToolsInstallPath?: string
221
437
  /** 上传的终端, 默认alipay */
222
- clientType?: ClientType;
438
+ clientType?: AlipayClientType
439
+ }
440
+
441
+ export type DingtalkProjectType =
442
+ /** 第三方个人应用 */
443
+ 'dingtalk-personal'|
444
+ /** 第三方企业应用 */
445
+ 'dingtalk-biz-isv'|
446
+ /** 企业内部应用 */
447
+ 'dingtalk-biz'|
448
+ /** 企业定制应用 */
449
+ 'dingtalk-biz-custom'|
450
+ /** 工作台组件 */
451
+ 'dingtalk-biz-worktab-plugin'
452
+ export interface DingtalkConfig {
453
+ /** 钉钉小程序appid,即钉钉开放平台后台应用管理的 MiniAppId 选项(必填) */
454
+ appid: string
455
+ /** 令牌,从钉钉后台获取 */
456
+ token: string
457
+ /** 小程序开发者工具安装路径 */
458
+ devToolsInstallPath?: string
459
+ /** 钉钉应用类型, 默认为:'dingtalk-biz' (企业内部应用) */
460
+ projectType?: DingtalkProjectType
223
461
  }
224
462
 
225
463
  /** 百度小程序配置 */
226
464
  export interface SwanConfig {
227
465
  /** 有该小程序发布权限的登录密钥 */
228
- token: string;
466
+ token: string
229
467
  /** 最低基础库版本, 不传默认为 3.350.6 */
230
- minSwanVersion?: string;
468
+ minSwanVersion?: string
231
469
  }
470
+
232
471
  ```