From 041b33be053d4cf7d410ef720ab89e0ca1eff610 Mon Sep 17 00:00:00 2001 From: bigMeow Date: Tue, 23 Aug 2022 00:48:10 +0800 Subject: [PATCH] =?UTF-8?q?feat(taro-plugin-mini-ci):=20=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E4=BC=A0=E5=85=A5=E5=87=BD=E6=95=B0=E4=BD=9C=E4=B8=BA=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-plugin-mini-ci/README.md | 38 ++++++++++++ packages/taro-plugin-mini-ci/src/index.ts | 73 ++++++++++++----------- 2 files changed, 77 insertions(+), 34 deletions(-) diff --git a/packages/taro-plugin-mini-ci/README.md b/packages/taro-plugin-mini-ci/README.md index 5b686cc8aa30..57a2abaac8d8 100644 --- a/packages/taro-plugin-mini-ci/README.md +++ b/packages/taro-plugin-mini-ci/README.md @@ -47,6 +47,44 @@ const config = { } ``` +除了给插件传入对象, 你也可以传入一个函数,在编译时动态返回相关配置 +```js +const CIPluginFn = () => { + /** + * @typedef { import("@tarojs/plugin-mini-ci").CIOptions } CIOptions + * @type {CIOptions} + */ + return { + 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", CIPluginFn ] + ] +} +``` + ### 配置命令 `package.json` 的 `scripts` 字段使用命令参数 diff --git a/packages/taro-plugin-mini-ci/src/index.ts b/packages/taro-plugin-mini-ci/src/index.ts index 3c00f56f98fe..83908da81708 100644 --- a/packages/taro-plugin-mini-ci/src/index.ts +++ b/packages/taro-plugin-mini-ci/src/index.ts @@ -8,44 +8,49 @@ import TTCI from './TTCI' import WeappCI from './WeappCI' export { CIOptions } from './BaseCi' -export default (ctx: IPluginContext, pluginOpts: CIOptions) => { +export default (ctx: IPluginContext, _pluginOpts: CIOptions | (() => CIOptions)) => { const onBuildDone = ctx.onBuildComplete || ctx.onBuildFinish + const pluginOpts = typeof _pluginOpts === 'function' ? _pluginOpts() : _pluginOpts + ctx.addPluginOptsSchema((joi) => { - return joi - .object() - .keys({ + return joi.alternatives().try( + joi.function().required(), + joi + .object() + .keys({ /** 微信小程序上传配置 */ - weapp: joi.object({ - appid: joi.string().required(), - projectPath: joi.string(), - privateKeyPath: joi.string().required(), - type: joi.string().valid('miniProgram', 'miniProgramPlugin', 'miniGame', 'miniGamePlugin'), - ignores: joi.array().items(joi.string().required()) - }), - /** 字节跳动小程序上传配置 */ - tt: joi.object({ - email: joi.string().required(), - password: joi.string().required() - }), - /** 阿里小程序上传配置 */ - alipay: joi.object({ - appId: joi.string().required(), - toolId: joi.string().required(), - privateKeyPath: joi.string().required(), - proxy: joi.string(), - project: joi.string(), - clientType: joi.string().valid('alipay', 'ampe', 'amap', 'genie', 'alios', 'uc', 'quark', 'taobao', 'koubei', 'alipayiot', 'cainiao', 'alihealth') - }), - /** 百度小程序上传配置 */ - swan: joi.object({ - token: joi.string().required(), - minSwanVersion: joi.string() - }), - version: joi.string(), - desc: joi.string() - }) - .required() + weapp: joi.object({ + appid: joi.string().required(), + projectPath: joi.string(), + privateKeyPath: joi.string().required(), + type: joi.string().valid('miniProgram', 'miniProgramPlugin', 'miniGame', 'miniGamePlugin'), + ignores: joi.array().items(joi.string().required()) + }), + /** 字节跳动小程序上传配置 */ + tt: joi.object({ + email: joi.string().required(), + password: joi.string().required() + }), + /** 阿里小程序上传配置 */ + alipay: joi.object({ + appId: joi.string().required(), + toolId: joi.string().required(), + privateKeyPath: joi.string().required(), + proxy: joi.string(), + project: joi.string(), + clientType: joi.string().valid('alipay', 'ampe', 'amap', 'genie', 'alios', 'uc', 'quark', 'taobao', 'koubei', 'alipayiot', 'cainiao', 'alihealth') + }), + /** 百度小程序上传配置 */ + swan: joi.object({ + token: joi.string().required(), + minSwanVersion: joi.string() + }), + version: joi.string(), + desc: joi.string() + }) + .required() + ) }) onBuildDone(async () => {