Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
重构所有代码和文档中的项目名称,将OpenFang统一更新为ZCLAW。包括: - 配置文件中的项目名称 - 代码注释和文档引用 - 环境变量和路径 - 类型定义和接口名称 - 测试用例和模拟数据 同时优化部分代码结构,移除未使用的模块,并更新相关依赖项。
151 lines
4.5 KiB
JavaScript
151 lines
4.5 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* ZCLAW Binary Downloader
|
|
* Automatically downloads the correct ZCLAW binary for the current platform
|
|
* Run during Tauri build process
|
|
*/
|
|
|
|
import { execSync } from 'child_process';
|
|
import { existsSync, mkdirSync, writeFileSync, renameSync } from 'fs';
|
|
import { join, dirname } from 'path';
|
|
import { fileURLToPath } from 'url';
|
|
import { platform, arch } from 'os';
|
|
|
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
const RESOURCES_DIR = join(__dirname, '../src-tauri/resources/zclaw-runtime');
|
|
|
|
// ZCLAW release info
|
|
const ZCLAW_REPO = 'RightNow-AI/zclaw';
|
|
const ZCLAW_VERSION = process.env.ZCLAW_VERSION || 'latest';
|
|
|
|
interface PlatformConfig {
|
|
binaryName: string;
|
|
downloadName: string;
|
|
}
|
|
|
|
function getPlatformConfig(): PlatformConfig {
|
|
const currentPlatform = platform();
|
|
const currentArch = arch();
|
|
|
|
switch (currentPlatform) {
|
|
case 'win32':
|
|
return {
|
|
binaryName: 'zclaw.exe',
|
|
downloadName: currentArch === 'x64'
|
|
? 'zclaw-x86_64-pc-windows-msvc.exe'
|
|
: 'zclaw-aarch64-pc-windows-msvc.exe',
|
|
};
|
|
case 'darwin':
|
|
return {
|
|
binaryName: currentArch === 'arm64'
|
|
? 'zclaw-aarch64-apple-darwin'
|
|
: 'zclaw-x86_64-apple-darwin',
|
|
downloadName: currentArch === 'arm64'
|
|
? 'zclaw-aarch64-apple-darwin'
|
|
: 'zclaw-x86_64-apple-darwin',
|
|
};
|
|
case 'linux':
|
|
return {
|
|
binaryName: currentArch === 'arm64'
|
|
? 'zclaw-aarch64-unknown-linux-gnu'
|
|
: 'zclaw-x86_64-unknown-linux-gnu',
|
|
downloadName: currentArch === 'arm64'
|
|
? 'zclaw-aarch64-unknown-linux-gnu'
|
|
: 'zclaw-x86_64-unknown-linux-gnu',
|
|
};
|
|
default:
|
|
throw new Error(`Unsupported platform: ${currentPlatform}`);
|
|
}
|
|
}
|
|
|
|
function downloadBinary(): void {
|
|
const config = getPlatformConfig();
|
|
const baseUrl = `https://github.com/${ZCLAW_REPO}/releases`;
|
|
const downloadUrl = ZCLAW_VERSION === 'latest'
|
|
? `${baseUrl}/latest/download/${config.downloadName}`
|
|
: `${baseUrl}/download/${ZCLAW_VERSION}/${config.downloadName}`;
|
|
|
|
const outputPath = join(RESOURCES_DIR, config.binaryName);
|
|
|
|
console.log('='.repeat(60));
|
|
console.log('ZCLAW Binary Downloader');
|
|
console.log('='.repeat(60));
|
|
console.log(`Platform: ${platform()} (${arch()})`);
|
|
console.log(`Binary: ${config.binaryName}`);
|
|
console.log(`Version: ${ZCLAW_VERSION}`);
|
|
console.log(`URL: ${downloadUrl}`);
|
|
console.log('='.repeat(60));
|
|
|
|
// Ensure directory exists
|
|
if (!existsSync(RESOURCES_DIR)) {
|
|
mkdirSync(RESOURCES_DIR, { recursive: true });
|
|
}
|
|
|
|
// Check if already downloaded
|
|
if (existsSync(outputPath)) {
|
|
console.log('Binary already exists, skipping download.');
|
|
return;
|
|
}
|
|
|
|
// Download using curl (cross-platform via Node.js)
|
|
console.log('Downloading...');
|
|
|
|
try {
|
|
// Use curl for download (available on all platforms with Git/WSL)
|
|
const tempPath = `${outputPath}.tmp`;
|
|
|
|
if (platform() === 'win32') {
|
|
// Windows: use PowerShell
|
|
execSync(
|
|
`powershell -Command "Invoke-WebRequest -Uri '${downloadUrl}' -OutFile '${tempPath}'"`,
|
|
{ stdio: 'inherit' }
|
|
);
|
|
} else {
|
|
// Unix: use curl
|
|
execSync(`curl -fsSL -o "${tempPath}" "${downloadUrl}"`, { stdio: 'inherit' });
|
|
}
|
|
|
|
// Rename temp file to final name
|
|
renameSync(tempPath, outputPath);
|
|
|
|
// Make executable on Unix
|
|
if (platform() !== 'win32') {
|
|
execSync(`chmod +x "${outputPath}"`);
|
|
}
|
|
|
|
console.log('Download complete!');
|
|
} catch (error) {
|
|
console.error('Download failed:', error);
|
|
console.log('\nPlease download manually from:');
|
|
console.log(` ${baseUrl}/${ZCLAW_VERSION === 'latest' ? 'latest' : 'tag/' + ZCLAW_VERSION}`);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
function updateManifest(): void {
|
|
const manifestPath = join(RESOURCES_DIR, 'runtime-manifest.json');
|
|
|
|
const manifest = {
|
|
source: {
|
|
binPath: platform() === 'win32' ? 'zclaw.exe' : `zclaw-${arch()}-${platform()}`,
|
|
},
|
|
stagedAt: new Date().toISOString(),
|
|
version: ZCLAW_VERSION === 'latest' ? new Date().toISOString().split('T')[0].replace(/-/g, '.') : ZCLAW_VERSION,
|
|
runtimeType: 'zclaw',
|
|
description: 'ZCLAW Agent OS - Single binary runtime (~32MB)',
|
|
endpoints: {
|
|
websocket: 'ws://127.0.0.1:4200/ws',
|
|
rest: 'http://127.0.0.1:4200/api',
|
|
},
|
|
};
|
|
|
|
writeFileSync(manifestPath, JSON.stringify(manifest, null, 2));
|
|
console.log('Manifest updated');
|
|
}
|
|
|
|
// Run
|
|
downloadBinary();
|
|
updateManifest();
|
|
|
|
console.log('\nZCLAW runtime ready for build!');
|