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.
This commit is contained in:
1 parent
3be20a6bb0
commit
aa1acbbff6
4 files changed
+83
-4
No files matched your search
+3
-2
@@ -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",
|
||||
|
||||
@@ -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);
|
||||
@@ -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}`);
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in new issue
Block a user