mirror of
https://github.com/certd/certd.git
synced 2026-05-17 22:07:34 +08:00
feat: midway注解方式编写插件
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user