feat: midway注解方式编写插件

This commit is contained in:
xiaojunnuo
2023-01-07 23:22:02 +08:00
parent e4ec4e1404
commit 52522f27e9
16 changed files with 156 additions and 238 deletions
+26 -22
View File
@@ -1,26 +1,30 @@
import { AbstractPlugin, IsTask, TaskInput, TaskOutput, TaskPlugin } from "../src";
import { IsTaskPlugin, TaskInput, ITaskPlugin, LOGGER, Autowire, TaskOutput } from "../src";
@IsTask(() => {
return {
name: "EchoPlugin",
title: "测试插件【echo】",
input: {
cert: {
title: "cert",
component: {
name: "pi-output-selector",
},
helper: "输出选择",
},
},
output: {},
};
@IsTaskPlugin({
name: "EchoPlugin",
title: "测试插件【echo】",
})
export class EchoPlugin extends AbstractPlugin implements TaskPlugin {
async execute(input: TaskInput): Promise<TaskOutput> {
for (const key in input) {
this.logger.info("input :", key, input[key]);
}
return input;
export class EchoPlugin implements ITaskPlugin {
@TaskInput({
title: "cert",
component: {
name: "pi-output-selector",
},
helper: "输出选择",
})
cert!: any;
@Autowire()
logger!: LOGGER;
@TaskOutput({
title: "cert info",
})
certInfo!: any;
// eslint-disable-next-line @typescript-eslint/no-empty-function
async onInit(): Promise<void> {}
async execute(): Promise<void> {
console.log("input :cert", this.cert);
}
}
+7 -3
View File
@@ -3,10 +3,14 @@ import "mocha";
import { EchoPlugin } from "./echo-plugin";
describe("task_plugin", function () {
it("#taskplugin", function () {
console.log("before new plugin");
const echoPlugin = new EchoPlugin();
console.log("before set property", echoPlugin);
echoPlugin.cert = { test: 1 };
console.log("before execute");
// @ts-ignore
const define = echoPlugin.getDefine();
echoPlugin.execute({ context: {}, input: { test: 111 } });
expect(define.name).eq("EchoPlugin");
echoPlugin.execute();
console.log("after execute");
expect(echoPlugin.cert).eq("EchoPlugin");
});
});
@@ -1,7 +1,7 @@
import { AbstractAccess, IAccessService } from "../../src";
import { IAccess, IAccessService } from "../../src";
import { aliyunSecret } from "../user.secret";
export class AccessServiceTest implements IAccessService {
async getById(id: any): Promise<AbstractAccess> {
async getById(id: any): Promise<IAccess> {
return {
...aliyunSecret,
} as any;