refactor(plugin): 重构插件定义和安装流程

- 更新插件配置格式,增加依赖库和插件类型字段
- 修改插件安装流程,支持安装依赖插件和第三方库
- 优化插件列表过滤逻辑,按类型筛选插件
- 调整 Dockerfile,使用 Node.js22 镜像并更新 pnpm 安装方式
This commit is contained in:
xiaojunnuo
2025-04-11 23:39:40 +08:00
parent 420b0394a7
commit 3d9620abb0
8 changed files with 176 additions and 85 deletions

View File

@@ -1,28 +1,36 @@
import yaml from "js-yaml";
const CertOutputs = [
"CertApply",
"CertApplyLego",
"CertApplyUpload"
];
import { CertApplyPluginNames } from "@certd/plugin-cert";
export function getDefaultAccessPlugin() {
const metadata = {
username: {
title: "用户名",
required: true,
encrypt: false
},
password: {
title: "密码",
required: true,
encrypt: true
}
};
const metadata = `
input:
username: # 授权参数名
title: 用户名 # 授权参数标题
required: true # 是否必填项
encrypt: false # 是否加密
component: # 输入组件配置
name: a-input #输入组件名称
allowClear: true # 组件的参数,参考 https://www.antdv.com/components/input#api
password:
title: 密码
required: true
encrypt: true
component:
name: a-input
allowClear: true
const script = `const { BaseAccess } = await import("@certd/pipeline")
`
const script = `
# 必须使用 await import 来引入模块
const { BaseAccess } = await import("@certd/pipeline")
# 需要返回一个继承BaseAccess的类
return class DemoAccess extends BaseAccess {
username;
password;
# 授权的字段跟左边input一一对应
username;
password;
}
`;
return {
@@ -32,82 +40,93 @@ password;
}
export function getDefaultDeployPlugin() {
const metadata = {
cert: {
title: "前置任务证书",
component: {
name: "output-selector",
from: [...CertOutputs]
},
required: true
},
certDomains: {
title: "当前证书域名",
component: {
name: "cert-domains-getter"
},
mergeScript: `
return {
component:{
inputKey: ctx.compute(({form})=>{
return form.cert
}),
}
let certApplyNames = ''
for (const name of CertApplyPluginNames) {
certApplyNames += `
- ${name}`
}
const metadata =`
input: # 插件的输入参数
cert:
title: 前置任务证书
helper: 请选择前置任务产生的证书 # 帮助说明
component:
name: output-selector # 输入组件名称
vModel: modelValue # 组件参数
from:${certApplyNames}
required: true
certDomains:
title: 当前证书域名
component:
name: cert-domains-getter
mergeScript: |
return {
component:{
inputKey: ctx.compute(({form})=>{
return form.cert
}),
}
`,
required: true
},
accessId: {
title: "Access授权",
helper: "xxxx的授权",
component: {
name: "access-selector",
type: "aliyun"
},
required: true
},
key1: {
title: "输入示例1",
required: false
},
key2: {
title: "可选项",
component: {
name: "a-select",
vMode: "value",
options: [
{ value: "1", label: "选项1" },
{ value: "2", label: "选项2" }
]
},
required: false
}
};
}
required: true
accessId:
title: Access授权
helper: xxxx的授权
component:
name: access-selector # 授权选择组件名称
type: aliyun # 授权类型
required: true
key1:
title: 输入示例1
required: false
key2:
title: 可选项
component:
name: a-select
vMode: value
options:
- value: "1"
label: 选项1
- value: "2"
label: 选项2
required: false
#output: # 输出参数,一般插件都不需要配置此项
# outputName:
#
`
const script = `
// 要用await来import模块
const { AbstractTaskPlugin } = await import("@certd/pipeline")
// 要返回一个继承AbstractTaskPlugin的class
return class DemoTask extends AbstractTaskPlugin {
// 这里是插件的输入参数对应左边的input配置
cert;
certDomains;
accessId;
key1;
key2;
// 编写执行方法
async execute(){
# 根据accessId获取授权配置
const access = await this.accessService.getById(this.accessId)
this.logger.info("cert:",this.cert);
//必须使用this.logger打印日志
// this.logger.info("cert:",this.cert);
this.logger.info("certDomains:",this.certDomains);
this.logger.info("access:",access);
this.logger.info("key1:",this.key1);
this.logger.info("key2:",this.key2);
//开始你的部署任务
const res = await this.ctx.http.request({url:"xxxxxx"})
// 开始你的部署任务
// this.ctx里面有一些常用的方法类比如utils、http、logger等
const res = await this.ctx.http.request({url:"https://www.baidu.com"})
if(res.error){
//抛出异常,终止任务,否则将被判定为执行成功
throw new Error("部署失败:"+res.message)
}
//必须使用this.logger打印日志
this.logger.info("执行成功")
// this.outputName = xxxx //设置输出参数,可以被其他插件选择使用
}
}
`
@@ -118,7 +137,14 @@ return class DemoTask extends AbstractTaskPlugin {
}
export function getDefaultDnsPlugin() {
const metadata = `accessType: aliyun #授权类型名称`
const metadata = `
accessType: aliyun # 授权类型名称
#dependPlugins: # 依赖第三方库安装插件时会安装依赖库尽量使用certd已安装的库比如http、lodash-es、utils
# @alicloud/openapi-client: ^0.4.12
#dependLibs: # 依赖的插件,应用商店安装时会先安装依赖插件
# aliyun: *
`
const script = `
const { AbstractDnsProvider } = await import("@certd/pipeline")