Refactoring: Move every concrete plugin task to a separate source file

This commit is contained in:
Dominik Jain 2025-09-12 13:41:31 +02:00
parent 0468381d2b
commit 283f01b0ac
3 changed files with 35 additions and 34 deletions

View File

@ -51,34 +51,3 @@ export abstract class PluginTask<TParams = any, TResult = any> {
};
}
}
/**
* Parameters for the printText task.
*/
export class PluginTaskPrintTextParams {
/**
* The text to be displayed in Penpot.
*/
public readonly text: string;
constructor(text: string) {
this.text = text;
}
}
/**
* Task for printing/creating text in Penpot.
*
* This task instructs the plugin to create a text element
* at the viewport center and select it.
*/
export class PluginTaskPrintText extends PluginTask<PluginTaskPrintTextParams> {
/**
* Creates a new print text task.
*
* @param params - The parameters containing the text to print
*/
constructor(params: PluginTaskPrintTextParams) {
super("printText", params);
}
}

View File

@ -0,0 +1,32 @@
import { PluginTask } from "../PluginTask";
/**
* Parameters for the printText task.
*/
export class PrintTextPluginTaskParams {
/**
* The text to be displayed in Penpot.
*/
public readonly text: string;
constructor(text: string) {
this.text = text;
}
}
/**
* Task for printing/creating text in Penpot.
*
* This task instructs the plugin to create a text element
* at the viewport center and select it.
*/
export class PrintTextPluginTask extends PluginTask<PrintTextPluginTaskParams> {
/**
* Creates a new print text task.
*
* @param params - The parameters containing the text to print
*/
constructor(params: PrintTextPluginTaskParams) {
super("printText", params);
}
}

View File

@ -1,10 +1,10 @@
import { IsNotEmpty, IsString } from "class-validator";
import { Tool } from "../Tool";
import { PluginTaskPrintText, PluginTaskPrintTextParams } from "../PluginTask";
import type { ToolResponse } from "../ToolResponse";
import { TextResponse } from "../ToolResponse";
import "reflect-metadata";
import { PenpotMcpServer } from "../PenpotMcpServer";
import { PrintTextPluginTask, PrintTextPluginTaskParams } from "../tasks/PrintTextPluginTask";
/**
* Arguments class for the PrintText tool with validation decorators.
@ -43,8 +43,8 @@ export class PrintTextTool extends Tool<PrintTextArgs> {
}
protected async executeCore(args: PrintTextArgs): Promise<ToolResponse> {
const taskParams = new PluginTaskPrintTextParams(args.text);
const task = new PluginTaskPrintText(taskParams);
const taskParams = new PrintTextPluginTaskParams(args.text);
const task = new PrintTextPluginTask(taskParams);
this.mcpServer.executePluginTask(task);
return new TextResponse(
`Successfully sent text creation task. Text "${args.text}" should now appear in Penpot.`