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;
const archNameMap = {
'x86_64': 'x64',
'aarch64': 'aarch64' };
const mappedArch = archNameMap[arch] || arch;
let binaryName = `${platform}-${mappedArch}.zip`;
return binaryName;
}
function getDownloadUrl(version, platformInfo) {
const binaryName = getBinaryName(platformInfo);
const repo = 'Protagonistss/ziro';
return `https://github.com/${repo}/releases/download/v${version}/${binaryName}`;
}
module.exports = {
detectPlatform,
getBinaryName,
getDownloadUrl,
};