diff --git a/bin/hula-mcp.js b/bin/hula-mcp.js index e775350..845992d 100644 --- a/bin/hula-mcp.js +++ b/bin/hula-mcp.js @@ -30,7 +30,7 @@ program process.env.PORT = options.port; // 启动服务 - const serverPath = path.join(__dirname, '..', 'src', 'index.js'); + const serverPath = path.join(__dirname, '..', 'dist', 'index.js'); spawn('node', [serverPath], { stdio: 'inherit' }); }); diff --git a/package.json b/package.json index 33c7fbe..aefbd39 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@hula-spark/hula-mcp", - "version": "1.0.2", + "version": "1.0.3", "description": "HuLa 即时通讯应用的 MCP 服务", "type": "module", "license": "Apache-2.0", @@ -14,16 +14,16 @@ }, "files": [ "dist", + "bin", + "src", "LICENSE", "README.md" ], "scripts": { - "build": "tsc", + "build": "tsc && node scripts/copy-js.js", "start": "node bin/hula-mcp.js start", "dev": "tsx watch src/index.ts", - "test": "jest", - "prepublishOnly": "npm run build", - "prepare": "npm run build" + "test": "jest" }, "keywords": [ "mcp", diff --git a/scripts/copy-js.js b/scripts/copy-js.js new file mode 100644 index 0000000..3706c8b --- /dev/null +++ b/scripts/copy-js.js @@ -0,0 +1,51 @@ +import { promises as fs } from 'fs'; +import path from 'path'; +import { fileURLToPath } from 'url'; + +const __dirname = path.dirname(fileURLToPath(import.meta.url)); +const srcDir = path.join(__dirname, '..', 'src'); +const distDir = path.join(__dirname, '..', 'dist'); + +async function copyJsFiles(dir) { + const entries = await fs.readdir(dir, { withFileTypes: true }); + + for (const entry of entries) { + const srcPath = path.join(dir, entry.name); + const relativePath = path.relative(srcDir, srcPath); + const destPath = path.join(distDir, relativePath); + + if (entry.isDirectory()) { + await fs.mkdir(destPath, { recursive: true }).catch(() => {}); + await copyJsFiles(srcPath); + } else if (entry.name.endsWith('.js')) { + await fs.copyFile(srcPath, destPath).catch(err => { + if (err.code !== 'ENOENT') throw err; + console.error(`无法复制文件: ${srcPath}`); + }); + } + } +} + +// 删除所有 .map 文件的函数 +async function removeMapFiles(dir) { + const entries = await fs.readdir(dir, { withFileTypes: true }); + + for (const entry of entries) { + const fullPath = path.join(dir, entry.name); + + if (entry.isDirectory()) { + await removeMapFiles(fullPath); + } else if (entry.name.endsWith('.map')) { + await fs.unlink(fullPath); + console.log(`已删除: ${fullPath}`); + } + } +} + +// 执行复制和清理操作 +async function main() { + await copyJsFiles(srcDir); + await removeMapFiles(distDir); +} + +main().catch(console.error); \ No newline at end of file diff --git a/src/resources/chat.ts b/src/resources/chat.ts index 4b197e1..a04b4e0 100644 --- a/src/resources/chat.ts +++ b/src/resources/chat.ts @@ -1,5 +1,5 @@ import { McpServer, ResourceTemplate } from '@modelcontextprotocol/sdk/server/mcp.js'; -import { Message, Conversation } from '../types.ts'; +import { Message, Conversation } from '../types.js'; // 模拟数据 const mockMessages: Message[] = [ diff --git a/src/resources/group.ts b/src/resources/group.ts index 94efda3..1e5f3bc 100644 --- a/src/resources/group.ts +++ b/src/resources/group.ts @@ -1,5 +1,5 @@ import { McpServer, ResourceTemplate } from '@modelcontextprotocol/sdk/server/mcp.js'; -import { Group } from '../types.ts'; +import { Group } from '../types.js'; // 模拟数据 - 在实际应用中,这些数据应该从数据库中获取 const mockGroups: Group[] = [ diff --git a/src/resources/user.ts b/src/resources/user.ts index 03b6d22..4d2d0a1 100644 --- a/src/resources/user.ts +++ b/src/resources/user.ts @@ -1,5 +1,5 @@ import { McpServer, ResourceTemplate } from '@modelcontextprotocol/sdk/server/mcp.js'; -import { User } from '../types.ts'; +import { User } from '../types.js'; // 模拟数据 - 在实际应用中,这些数据应该从数据库中获取 const mockUsers: User[] = [ diff --git a/src/tools/index.ts b/src/tools/index.ts index d849d46..011ea10 100644 --- a/src/tools/index.ts +++ b/src/tools/index.ts @@ -1,6 +1,6 @@ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'; import { z } from 'zod'; -import { Message } from '../types.ts'; +import { Message } from '../types.js'; // 生成唯一ID的辅助函数 function generateId(prefix: string): string { diff --git a/tsconfig.json b/tsconfig.json index cf5057d..f9d8928 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,20 +6,19 @@ "esModuleInterop": true, "strict": true, "outDir": "./dist", - "sourceMap": true, + "sourceMap": false, "declaration": true, "resolveJsonModule": true, - "emitDeclarationOnly": true, - "allowImportingTsExtensions": true, "baseUrl": ".", "paths": { "@/*": ["./src/*"] - } + }, + "allowJs": true }, "ts-node": { "esm": true, "experimentalSpecifierResolution": "node" }, - "include": ["src/**/*"], + "include": ["src/**/*.ts", "src/**/*.js"], "exclude": ["node_modules", "dist"] }