From 3a1494e18cba059d1d9fb8b2fcdfa88b05a8e749 Mon Sep 17 00:00:00 2001 From: Dominik Jain Date: Sat, 27 Sep 2025 18:27:22 +0200 Subject: [PATCH] Move REPL server HTML content to a separate file --- mcp-server/package.json | 3 +- mcp-server/src/ReplServer.ts | 232 +------------------------------- mcp-server/src/static/repl.html | 217 +++++++++++++++++++++++++++++ 3 files changed, 225 insertions(+), 227 deletions(-) create mode 100644 mcp-server/src/static/repl.html diff --git a/mcp-server/package.json b/mcp-server/package.json index 2d3d9e9..984e0e5 100644 --- a/mcp-server/package.json +++ b/mcp-server/package.json @@ -5,7 +5,8 @@ "type": "module", "main": "dist/index.js", "scripts": { - "build": "esbuild src/index.ts --bundle --platform=node --target=node18 --format=esm --outfile=dist/index.js --external:@modelcontextprotocol/* --external:ws --external:express --external:class-transformer --external:class-validator --external:reflect-metadata --external:pino --external:pino-pretty --external:js-yaml", + "build": "esbuild src/index.ts --bundle --platform=node --target=node18 --format=esm --outfile=dist/index.js --external:@modelcontextprotocol/* --external:ws --external:express --external:class-transformer --external:class-validator --external:reflect-metadata --external:pino --external:pino-pretty --external:js-yaml && npm run copy-static", + "copy-static": "node -e \"require('fs').cpSync('src/static', 'dist/static', { recursive: true })\"", "build:types": "tsc --emitDeclarationOnly --outDir dist", "build:full": "npm run build && npm run build:types", "start": "node dist/index.js", diff --git a/mcp-server/src/ReplServer.ts b/mcp-server/src/ReplServer.ts index 26e23ed..892364c 100644 --- a/mcp-server/src/ReplServer.ts +++ b/mcp-server/src/ReplServer.ts @@ -1,4 +1,6 @@ import express from "express"; +import path from "path"; +import { fileURLToPath } from "url"; import { PluginBridge } from "./PluginBridge"; import { ExecuteCodePluginTask } from "./tasks/ExecuteCodePluginTask"; import { createLogger } from "./logger"; @@ -31,7 +33,6 @@ export class ReplServer { */ private setupMiddleware(): void { this.app.use(express.json()); - this.app.use(express.static("public")); // for serving static files if needed } /** @@ -40,7 +41,10 @@ export class ReplServer { private setupRoutes(): void { // serve the main REPL interface this.app.get("/", (req, res) => { - res.send(this.getReplHtml()); + const __filename = fileURLToPath(import.meta.url); + const __dirname = path.dirname(__filename); + const htmlPath = path.join(__dirname, 'static', 'repl.html'); + res.sendFile(htmlPath); }); // API endpoint for executing code @@ -74,231 +78,7 @@ export class ReplServer { }); } - /** - * Generates the HTML content for the REPL interface. - * - * Creates a simple web page with a resizable textarea for code input, - * an execute button, and a results display area using jQuery. - */ - private getReplHtml(): string { - return ` - - - - - Penpot MCP REPL - - - - -

Penpot MCP REPL

- -
- - -
- -
- - Shortcut: Ctrl+Enter -
- -
- -
Click "Execute Code" to run your JavaScript...
-
- - -`; - } /** * Starts the REPL web server. diff --git a/mcp-server/src/static/repl.html b/mcp-server/src/static/repl.html new file mode 100644 index 0000000..46d8401 --- /dev/null +++ b/mcp-server/src/static/repl.html @@ -0,0 +1,217 @@ + + + + + + Penpot MCP REPL + + + + +

Penpot MCP REPL

+ +
+ + +
+ +
+ + Shortcut: Ctrl+Enter +
+ +
+ +
Click "Execute Code" to run your JavaScript...
+
+ + + +