ziro 0.0.3

跨平台端口管理工具 - 快速查找和终止占用端口的进程
/**
 * 检测当前操作系统和架构
 */

function detectPlatform() {
  const platform = process.platform;
  const arch = process.arch;
  
  // 平台映射
  const platformMap = {
    'win32': 'windows',
    'darwin': 'macos',
    'linux': 'linux',
  };
  
  // 架构映射
  const archMap = {
    'x64': 'x86_64',
    'arm64': 'aarch64',
  };
  
  const mappedPlatform = platformMap[platform];
  const mappedArch = archMap[arch];
  
  if (!mappedPlatform) {
    throw new Error(`: ${platform}`);
  }
  
  if (!mappedArch) {
    throw new Error(`: ${arch}`);
  }
  
  return {
    platform: mappedPlatform,
    arch: mappedArch,
    raw: {
      platform,
      arch,
    },
  };
}

function getBinaryName(platformInfo) {
  const { platform, arch } = platformInfo;
  
  // 生成二进制文件名
  // 例如: ziro-windows-x86_64.exe, ziro-linux-x86_64, ziro-macos-aarch64
  let binaryName = `ziro-${platform}-${arch}`;
  
  if (platform === 'windows') {
    binaryName += '.exe';
  }
  
  return binaryName;
}

function getDownloadUrl(version, platformInfo) {
  const binaryName = getBinaryName(platformInfo);
  const repo = 'Protagonistss/ziro';
  
  // GitHub Release 下载 URL
  return `https://github.com/${repo}/releases/download/v${version}/${binaryName}`;
}

module.exports = {
  detectPlatform,
  getBinaryName,
  getDownloadUrl,
};