From aa1acbbff6285ef95f68a66c6daba83214df5fb8 Mon Sep 17 00:00:00 2001 From: Kang Date: Thu, 27 Aug 2026 23:36:13 +0800 Subject: [PATCH] chore(build): update build process and add MCP sidecar script - Modified the build command to include a new script for building the MCP sidecar. - Introduced a new script `build-mcp-sidecar.mjs` to handle the compilation of the MCP sidecar using Cargo. - Updated the `sync-version.mjs` script to synchronize versioning for the MCP sidecar package. - Adjusted the Tauri configuration to ensure the MCP sidecar is built before development starts. --- package.json | 5 ++-- scripts/build-mcp-sidecar.mjs | 47 +++++++++++++++++++++++++++++++++++ scripts/sync-version.mjs | 30 +++++++++++++++++++++- src-tauri/tauri.conf.json | 5 +++- 4 files changed, 83 insertions(+), 4 deletions(-) create mode 100644 scripts/build-mcp-sidecar.mjs diff --git a/package.json b/package.json index 28f2393b..298da2bd 100644 --- a/package.json +++ b/package.json @@ -18,8 +18,9 @@ "lint:console": "node scripts/check-no-console.mjs", "version-sync": "node scripts/sync-version.mjs", "dev": "vite", - "build": "tsc && vite build", - "release": "node scripts/sync-version.mjs --commit && tsc && vite build && tauri build", + "build": "pnpm build:mcp-sidecar && tsc && vite build", + "build:mcp-sidecar": "node scripts/build-mcp-sidecar.mjs", + "release": "node scripts/sync-version.mjs --commit && tauri build", "build:unlock-rescue": "powershell -ExecutionPolicy Bypass -File scripts/build-unlock-rescue.ps1", "preview": "vite preview", "test": "vitest", diff --git a/scripts/build-mcp-sidecar.mjs b/scripts/build-mcp-sidecar.mjs new file mode 100644 index 00000000..b04642bd --- /dev/null +++ b/scripts/build-mcp-sidecar.mjs @@ -0,0 +1,47 @@ +import { execFileSync } from "node:child_process"; +import { copyFileSync, mkdirSync } from "node:fs"; +import { dirname, join, resolve } from "node:path"; +import process from "node:process"; +import { fileURLToPath } from "node:url"; + +const root = resolve(dirname(fileURLToPath(import.meta.url)), ".."); +const manifest = join(root, "src-tauri", "crates", "nyaterm-mcp", "Cargo.toml"); +const targetDir = join(root, "src-tauri", "crates", "nyaterm-mcp", "target"); +const rustcInfo = execFileSync("rustc", ["-vV"], { encoding: "utf8" }); +const host = rustcInfo.match(/^host:\s*(.+)$/m)?.[1]?.trim(); +const target = + process.env.NYATERM_MCP_TARGET || + process.env.TAURI_ENV_TARGET_TRIPLE || + process.env.CARGO_BUILD_TARGET || + host; +if (!target) + throw new Error("Unable to determine the Rust target triple for nyaterm-mcp"); + +const args = [ + "build", + "--release", + "--manifest-path", + manifest, + "--target-dir", + targetDir, +]; +if (target !== host) args.push("--target", target); +execFileSync("cargo", args, { cwd: root, stdio: "inherit" }); + +const windowsTarget = target.includes("windows"); +const executable = windowsTarget ? "nyaterm-mcp.exe" : "nyaterm-mcp"; +const source = join( + targetDir, + target !== host ? target : "", + "release", + executable, +); +const suffix = windowsTarget ? ".exe" : ""; +const destination = join( + root, + "src-tauri", + "binaries", + `nyaterm-mcp-${target}${suffix}`, +); +mkdirSync(dirname(destination), { recursive: true }); +copyFileSync(source, destination); diff --git a/scripts/sync-version.mjs b/scripts/sync-version.mjs index 70df7a58..ca74998e 100644 --- a/scripts/sync-version.mjs +++ b/scripts/sync-version.mjs @@ -17,6 +17,15 @@ cargo = cargo.replace( ); writeFileSync('src-tauri/Cargo.toml', cargo); +// Keep the separately-built MCP sidecar package aligned with the app release. +const sidecarManifestPath = 'src-tauri/crates/nyaterm-mcp/Cargo.toml'; +let sidecarCargo = readFileSync(sidecarManifestPath, 'utf-8'); +sidecarCargo = sidecarCargo.replace( + /(\[package\]\s*\nname\s*=\s*"nyaterm-mcp"\s*\n)version\s*=\s*"[^"]*"/, + `$1version = "${version}"` +); +writeFileSync(sidecarManifestPath, sidecarCargo); + // Change the version in Cargo.lock function updateNyaTermVersion(version) { const filePath = 'src-tauri/Cargo.lock'; @@ -37,11 +46,30 @@ function updateNyaTermVersion(version) { } updateNyaTermVersion(version); +function updateSidecarLockVersion(version) { + const filePath = 'src-tauri/crates/nyaterm-mcp/Cargo.lock'; + const content = readFileSync(filePath, 'utf-8'); + const pattern = + /(\[\[package\]\]\r?\nname = "nyaterm-mcp"\r?\nversion = ")([^"]*)(")/; + if (!pattern.test(content)) { + throw new Error('Could not find nyaterm-mcp in the sidecar Cargo.lock'); + } + writeFileSync(filePath, content.replace(pattern, `$1${version}$3`), 'utf-8'); +} +updateSidecarLockVersion(version); + console.log(`✅ Version synced to ${version}`); // If the --commit parameter is passed, automatically commit the version change if (process.argv.includes('--commit')) { - const files = ['package.json', 'src-tauri/tauri.conf.json', 'src-tauri/Cargo.toml', 'src-tauri/Cargo.lock']; + const files = [ + 'package.json', + 'src-tauri/tauri.conf.json', + 'src-tauri/Cargo.toml', + 'src-tauri/Cargo.lock', + sidecarManifestPath, + 'src-tauri/crates/nyaterm-mcp/Cargo.lock' + ]; execSync(`git add ${files.join(' ')}`, { stdio: 'inherit' }); execSync(`git commit -m "chore: bump version to v${version}"`, { stdio: 'inherit' }); console.log(`✅ Committed: chore: bump version to v${version}`); diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 188a5472..941b851d 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -4,7 +4,7 @@ "version": "1.2.5", "identifier": "com.kang.nyaterm", "build": { - "beforeDevCommand": "pnpm dev", + "beforeDevCommand": "pnpm build:mcp-sidecar && pnpm dev", "devUrl": "http://localhost:1420", "beforeBuildCommand": "pnpm build", "frontendDist": "../dist" @@ -34,6 +34,9 @@ "active": true, "targets": "all", "createUpdaterArtifacts": true, + "externalBin": [ + "binaries/nyaterm-mcp" + ], "icon": [ "icons/32x32.png", "icons/128x128.png",