Files
youle_cocos/cocoscreator_projects/YouleNexus/extensions/cocos-mcp-server/scripts/preinstall.js
T
joywayerandClaude Opus 5 42bc0722b8 chore(mcp): 换用 cocos-mcp-server 扩展, .mcp.json 改 HTTP 直连
旧扩展 @iflow-mcp/harady-cocos-creator-mcp(164 个细粒度工具 + stdio-bridge
转发)整个删除, 换成 cocos-mcp-server v1.7.9(16 个聚合工具, 靠 action 分派)。

新扩展自身起 streamable-http 服务, 不再需要 stdio 桥, 故 .mcp.json 从
node + stdio-bridge.js 改为 { type: "http", url: "http://127.0.0.1:3000/mcp" }。
原配置指向的 client/stdio-bridge.js 已随旧扩展删除, MCP 因此加载失败。

服务器名保留 cocos-creator-mcp(而非 INSTALL.md 建议的 cocos-creator), 以免
打断 CLAUDE.md、cocos-mcp 技能与 settings.local.json 里的
mcp__cocos-creator-mcp__* 允许规则。

gitignore: 新扩展是商业付费产品(vberai), 非 npm 可重装, dist/sidecar/static
共约 16M 发行产物+加密载荷+平台二进制不入库; 顺带忽略 Claude Code 个人本地
配置与编辑器运行时端口文件。

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-19 08:01:07 +08:00

111 lines
4.2 KiB
JavaScript

const fs = require("fs");
const path = require("path");
const { spawnSync } = require("child_process");
const PATH = {
packageJSON: path.join(__dirname, "../package.json")
};
function checkCreatorTypesVersion(version) {
try {
// 根据平台选择合适的npm命令
const npmCmd = process.platform === "win32" ? "npm.cmd" : "npm";
// 检查npm命令是否可用
const npmCheck = spawnSync(npmCmd, ["--version"], {
stdio: 'pipe',
shell: process.platform === "win32"
});
if (npmCheck.error || npmCheck.status !== 0) {
console.warn("Warning: npm command not available, skipping version check");
return true; // 如果npm不可用,跳过检查
}
// 获取版本列表
const result = spawnSync(npmCmd, ["view", "@cocos/creator-types", "versions"], {
stdio: 'pipe',
shell: process.platform === "win32"
});
if (result.error || result.status !== 0) {
console.warn("Warning: Failed to fetch @cocos/creator-types versions, skipping check");
return true; // 如果获取失败,跳过检查
}
let output = result.stdout.toString().trim();
// 尝试解析JSON
try {
const versions = JSON.parse(output);
if (Array.isArray(versions)) {
return versions.includes(version);
} else if (typeof versions === 'string') {
return versions.includes(version);
}
} catch (parseError) {
// 如果JSON解析失败,尝试作为字符串处理
return output.includes(version);
}
return false;
} catch (error) {
console.warn("Warning: Version check failed:", error.message);
return true; // 出错时跳过检查
}
}
function getCreatorTypesVersion() {
try {
// 检查package.json文件是否存在
if (!fs.existsSync(PATH.packageJSON)) {
console.warn("Warning: package.json not found");
return null;
}
const packageContent = fs.readFileSync(PATH.packageJSON, "utf8");
const packageJson = JSON.parse(packageContent);
// 检查devDependencies是否存在
if (!packageJson.devDependencies || !packageJson.devDependencies["@cocos/creator-types"]) {
console.warn("Warning: @cocos/creator-types not found in devDependencies");
return null;
}
const versionString = packageJson.devDependencies["@cocos/creator-types"];
return versionString.replace(/^[^\d]+/, "");
} catch (error) {
console.warn("Warning: Failed to read package.json:", error.message);
return null;
}
}
function main() {
try {
const creatorTypesVersion = getCreatorTypesVersion();
if (!creatorTypesVersion) {
console.log("Skipping @cocos/creator-types version check");
return;
}
if (!checkCreatorTypesVersion(creatorTypesVersion)) {
console.log("\x1b[33mWarning:\x1b[0m");
console.log(" @en");
console.log(" Version check of @cocos/creator-types failed.");
console.log(` The definition of ${creatorTypesVersion} has not been released yet. Please export the definition to the ./node_modules directory by selecting "Developer -> Export Interface Definition" in the menu of the Creator editor.`);
console.log(" The definition of the corresponding version will be released on npm after the editor is officially released.");
console.log(" @zh");
console.log(" @cocos/creator-types 版本检查失败。");
console.log(` ${creatorTypesVersion} 定义还未发布,请先通过 Creator 编辑器菜单 "开发者 -> 导出接口定义",导出定义到 ./node_modules 目录。`);
console.log(" 对应版本的定义会在编辑器正式发布后同步发布到 npm 上。");
}
} catch (error) {
console.error("Preinstall script error:", error.message);
// 不要抛出错误,让安装继续进行
process.exit(0);
}
}
// 执行主函数
main();