fix: 修复无法启动问题

This commit is contained in:
Dawn
2025-04-01 05:26:24 +08:00
parent 9231bb8542
commit ef1822e883
8 changed files with 65 additions and 15 deletions

View File

@@ -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' });
});

View File

@@ -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",

51
scripts/copy-js.js Normal file
View File

@@ -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);

View File

@@ -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[] = [

View File

@@ -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[] = [

View File

@@ -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[] = [

View File

@@ -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 {

View File

@@ -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"]
}