Skip to content

Commit

Permalink
feat(taro-plugin-mini-ci): 支持传入函数作为插件参数
Browse files Browse the repository at this point in the history
  • Loading branch information
bigmeow committed Aug 22, 2022
1 parent 8cc018b commit 041b33b
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 34 deletions.
38 changes: 38 additions & 0 deletions packages/taro-plugin-mini-ci/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` 字段使用命令参数
Expand Down
73 changes: 39 additions & 34 deletions packages/taro-plugin-mini-ci/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down

0 comments on commit 041b33b

Please sign in to comment.