23 lines
1.1 KiB
TypeScript
23 lines
1.1 KiB
TypeScript
import { mkdirSync } from "node:fs";
|
|
import { resolve } from "node:path";
|
|
|
|
const root = resolve(import.meta.dirname, "..");
|
|
const cache = resolve(root, ".cache");
|
|
const data = resolve(root, "data/mcp");
|
|
mkdirSync(cache, { recursive: true });
|
|
mkdirSync(data, { recursive: true });
|
|
mkdirSync(resolve(root, "data/images"), { recursive: true });
|
|
const binary = resolve(cache, process.platform === "win32" ? "xiaohongshu-mcp.exe" : "xiaohongshu-mcp");
|
|
console.log("构建小红书 MCP(需要 Go;首次启动会准备浏览器)…");
|
|
const build = Bun.spawn(["go", "build", "-o", binary, "."], {
|
|
cwd: resolve(root, "modules/xiaohongshu-mcp"), stdout: "inherit", stderr: "inherit",
|
|
});
|
|
if (await build.exited !== 0) process.exit(1);
|
|
const child = Bun.spawn([binary, "-port", "127.0.0.1:18060"], {
|
|
cwd: root, stdout: "inherit", stderr: "inherit",
|
|
env: { ...process.env, COOKIES_PATH: resolve(data, "cookies.json"), AUTH_TOKEN: process.env.MCP_AUTH_TOKEN ?? "" },
|
|
});
|
|
process.on("SIGINT", () => child.kill());
|
|
process.on("SIGTERM", () => child.kill());
|
|
process.exit(await child.exited);
|